Hi,
I am using xlsxwriter to convert csv to Excel files. For some reason, the line that convert to float and format to 6 decimal places caused the error when opening the xlsx file. If I would to comment out the line or just write it out to excel as string, the error goes away. Any help is appreciated.
Here’s the snippet of the code. The code splits up one csv into multiple excel due to excel limitation of number of rows.
for row in reader:
for col in range(len(row)):
if header[col] == ‘In-Service Date’:
worksheet.write(row_count, col, row[col], datefmt)
elif header[col] == ‘Length’ or header[col] == ‘Length Installed’:
try:
worksheet.write(row_count, col, float(row[col]), numfmt1)
except ValueError, e:
worksheet.write(row_count, col, row[col])
#print “error”, e, row_count
# For some reason the elif below corrupted the excel file. Possibly the defect in the xlsxwriter.
#elif header[col] in [‘First Point Latitude’, ‘First Point Longitude’,‘Last Point Latitude’, ‘Last Point Longitude’]:
# worksheet.write(row_count, col, float(row[col]), numfmt3)
elif header[col] == ‘ERP ID’:
worksheet.write(row_count, col, row[col].lstrip(“0”))
else:
worksheet.write(row_count, col, row[col])
row_count += 1