【问题标题】:Saving excel work book not working in python保存excel工作簿在python中不起作用
【发布时间】:2015-03-29 18:47:13
【问题描述】:
for sheet_name in book.sheet_names():   
    for index in range(len(tabs)):
        tab = tabs[index]
        if sheet_name == tab:       
            dump_file_name = dump_files[index]
            dump_file_name = file_prefix+dump_file_name
            sheet = book.sheet_by_name(sheet_name)

            new_book = Workbook()
            sheet1 = new_book.add_sheet("Sheet 1")          

            for row in range(sheet.nrows):
                values = []
                for col in range(sheet.ncols):

                    sheet1.write(row,col,sheet.cell(row,col).value)


            xlsx_file_name = dirname+"/"+dump_file_name+".xlsx"
            sheet1.title = xlsx_file_name           
            new_book.save(xlsx_file_name)

文件正在创建并且数据在那里,但是如果我在 openoffice.org 中打开它并单击保存按钮,它会要求输入新名称。 PHP 也无法读取该文件。如果我再次打开并用新名称保存它,那么它可以完美运行。我认为我们必须在代码中添加一些内容,以便 PHP 可以使用它。

【问题讨论】:

    标签: python export-to-excel


    【解决方案1】:

    我做了谷歌并在这里找到了解决方案 http://xlsxwriter.readthedocs.org/getting_started.html 这正是我想要的。 创建文件并将其保存为 xlsx 格式。 现在它工作得很好。

    原始来源 How to save Xlsxwriter file in certain path?
    重要链接: https://pypi.python.org/pypi/PyExcelerate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多