【问题标题】:Losing macros when adding data to excel spread sheet in python在 python 中将数据添加到 Excel 电子表格时丢失宏
【发布时间】:2015-06-18 00:40:01
【问题描述】:

我正在尝试为 Web 项目生成报告。报告要求我用数据填充 Excel 电子表格,然后运行宏来生成详细信息。

使用以下代码

   from xlrd import open_workbook
   from xlutils.copy import copy
   import StringIO

   contents=open_workbook("filename.xls")
   cloneContents = copy(contents)

   #code for adding data to cloneContents here
   stream = StringIO()
   cloneContents.save(stream)

   #this is from a web app so this is stream sent to the user to download
   return stream

这一切都很好,除了克隆的文件似乎丢失了所有的宏。我环顾四周寻找其他解决方案,但我能看到的唯一一个涉及实际在 excel 中加载文件,这是我无法做到的,因为这是一个 linux 服务器。有谁知道可以做什么? 谢谢

【问题讨论】:

    标签: python excel


    【解决方案1】:

    xlrd 和 xlutils 无法做到这一点。

    但是可以使用这个分支来完成 https://bitbucket.org/amorris/openpyxl/overview openpyxl 的。

    关键行是contents = load_workbook('filename.xlsm', keep_vba = True);

    【讨论】:

    • 这个分支不再活跃
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多