• Coding

    Automate Simple Tasks with Python: Excel Table to HTML Table using the python Dominate Module

    Book Sometimes a database is really not necessary. Why not try a simple excel sheet Coded this in an hour; sips on coffee though 9:06:34 PM I generated the excel workbook using a website called Mockaroo. Today’s task is to convert a basic excel sheet table into an HTML table. I broke the task into sub tasks which were then later translated into functions.   Do you need a website ? I can build it for you! PseudoCode Convert Excel Table into one dimensional List containing dictionaries Convert List into HTML document Save HTML string into a file with “.html” extension Done The Excel Sheet looked like this: MOCK_DATA The code generated…

  • Coding

    Python Learning: Automate Boring Stuff with Python | Chapter 12: Spreadsheet to Text Files

    Chapter 12 done!!! Finally Now I can sleep.. for 10 minutes though.. 3:42:14 AM Suggestions are welcomed. [sourcecode language=”python”] #USAGE python sheet2text.py <EXCELFILE> import logging, sys, os, openpyxl logging.basicConfig(level=logging.DEBUG, format="%(asctime)s – %(levelname)s – %(message)s") if len(sys.argv) == 2: #TODO: EXTRACTS EXCEL FILE excelfile = sys.argv[1] excelfile = os.path.abspath(excelfile) excelfile_name = os.path.basename(excelfile).split(".")[0] if not os.path.exists(excelfile): logging.error("Excel File "+ excelfile + " does not exists") raise #TODO: OPENS FILE wb = openpyxl.load_workbook(excelfile) #TODO: GET ACTIVE SHEET ws = wb.active if not ws: logging.error("Excel File should have at least a sheet with data") raise if ws.max_row <= 0 or ws.max_column <=0: logging.error("Excel File should contain data") raise #TODO: LOOP OVER COLUMNS #Each column =…

Enjoy this blog? Please spread the word :)

error: Content is protected !!