Search code examples
pythonexcelformattingxlwtxlutils

How to enter values to an .xlsx file and keep formatting of cells


I have a results analysing spreadsheet where i need to enter my raw data into a 8x6 cell 'plate' which has formatted cells to produce the output based on a graph created. This .xlsx file is heavily formatted with formulas for the analysis, and it is a commercial spreadsheet so I cannot replicate these formulas.

I am using python 2.7 to obtain the raw results into a list and I have tried using xlwt and xlutils to copy the spreadsheet to enter the results. When I do this it loses all formatting when I save the file. I am wondering whether there is a different way in which I can make a copy of the spreadsheet to enter my results.

Also when I have used xlutils.copy I can only save the file as a .xls file, not an xlsx, is this the reason why it loses formatting?


Solution

  • First:

    Apparently xlwt, does not support xlsx. does xlwt support xlsx Format

    Other library to use with format:

    https://pypi.python.org/pypi/XlsxWriter

    or

    http://pythonexcels.com/python-excel-mini-cookbook/