I'm trying to use the openpyxl library (see https://openpyxl.readthedocs.io/) to create some basic Excel-type files for use in Excel and Planmaker (from Softmaker FreeOffice 2018). The code I'm using is basically the same as shown on the openpyxl library web site, viz:-
from openpyxl import Workbook
import csv
Excel_file = "Test.xlsx"
csv_file = "test.csv"
# ----
wb = Workbook()
ws = wb.active
with open(csv_file, 'r') as fp:
for row in csv.reader(fp):
ws.append(row) # This creates cells that aren't numbers OR formattable?
# endfile
wb.save(Excel_file)
exit(0)
...and the .csv file is:-
Fruit,Quantity
Apples,222.09
Oranges,1032.12
Bananas,14.12
The file this code creates is Ok... but the numeric cells are formatted as 'Default' (they appear left-justified, not right-justified, as is normal with numeric fields) and can't seem to be formatted any specific way. The contents are 'Default' justified, etc. If I set the cells to 'Centred', the display of the cell is changed to centre the numeric text; however, if I then try to assign a 'Number' format (say, with 2 decimal places and to use commas for thousands), the display is not updated with the decimal places nor the thousands separator and the displayed text becomes left-justified, as it was before I changed it to 'Centred'.
I'm not sure if the problem is with Python, the library, or the Planmaker application (I don't have access to Excel at present), so I'm not sure where to go to see about resolving the problem. I'm not using 'pandas' or other such tools as I'm only dealing with small amounts of data and I want to keep the Python code small and 'lightweight' as I can.
I'm using Python 3.7.0 (collected from python.org some months ago, installed for everyone -- that is, not a 'user' installation), Windows 8.1 32-bit, openpyxl 3.0.2 and FreeOffice Planmaker 2018 Rev 973.1103 32-bit.
An example of the 'test.xlsx' file created by Python/openpyxl is located at: http://www.filedropper.com/test_20160 .
I'd appreciate any thoughts on what might be going awry.
Thanks.