简体   繁体   中英

Python, file corruoption when converting .csv to .xlsx, without xlsxwriter.workbook module

I'm trying to convert a .csv file to a .xlsx file without using the xlsxwriter.workbook module. The following code changes the format however when I try to open the file, I get prompted with "file format or file extension is not valid. Verify that the file has not been corrupted". Thanks

import os
import tkSimpleDialog
from tkFileDialog import askopenfilename

my_file = askopenfilename()

newname = my_file.replace('.csv', '.xlsx')
output = os.rename(my_file, newname)

I don't think you can convert csv file into xlsx file without using another module. I think your script only try to change the filename and do nothing to the content of the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM