在将多个文件重新组合为 .xls 之前将 .xls 转换为 .csv

Converting .xls to .csv before recombining multiple files into a .xls

我正在开发一个网络爬虫工具,它可以从网站下载 excel 文件。当然,那些 .xls 文件实际上只是重命名为 .csv 文件,这使我无法将 .xls 文件组合在一起。相反,我需要将它们全部转换为 .csv,它们使用 pyexcelpyexcel.merge_csv_to_a_book(filelist, outfilename='merged.xls') 函数从这些 .csv 文件创建一本书 excel。

这是我尝试过的:

        def concatenate_excel_files():
        indexer = 0
        excel_file_list = []
        for file in glob.glob(os.getcwd()+'\Reports\*.'):
            pyexcel.save_as(file_name=file, dest_file_name=str(indexer)+'.csv')
            excel_file_list[indexer] = file
            indexer += 1
        pyexcel.merge_csv_to_a_book(excel_file_list, outfilename='merged.xls')

这甚至无法将文件转换为 .csv(IndexError: list index out of range 错误。)

如能帮助重写本文,我们将不胜感激。

chfw 的回答:

for pyexcel to work properly, it needs to know file extension but in your case, the file extension is missing. And it will more helpful if the full stack trace is shown.