openpyxl python - writing csv to excel gives 'number formatted as text'

前端 未结 2 744
旧时难觅i
旧时难觅i 2020-12-09 13:31

I have written a code to import a .csv file (containing numbers) into an excel file through openpyxl. It works, however, all the cells have written the numbers to the excel

2条回答
  •  既然无缘
    2020-12-09 13:47

    You need to convert the value from the CSV file to what you need. All values in CSV files are strings. ws.cell('%s%s'%(column_letter, (row_index + 1))).value = int(cell) ought to do it.

    BTW. you might want to look at the ws.append() method.

提交回复
热议问题