我使用以下内容将panda数据帧写入预先格式化的excel模板,然后用不同的名称保存:
def writer(self):
'''
Calls the excel writer function to create an object for writing out the
report to excel. It loads an excel template, populates it and then
saves the file. '''
book = load_workbook(os.path.join(self.env.REPORT_TEMPLATE_PATH
, self.env.REPORT_TEMPLATE))
writer = pd.ExcelWriter(self.filename()
, engine='openpyxl')
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
return writer
命名范围用于避免断开链接。
我遇到的问题是,运行时的代码输出如下:
ContinuumAnaconda3libsitepackagesopenpyxlworkbooknamesnamed_range.py:124: UserWarning: Discarded range with reserved name
warnings.warn("Discarded range with reserved name")
就结果而言,一切似乎都很好,但打印区域已重置
有没有办法在新文件中保留模板中的打印区域?
有没有办法看到被丢弃的东西?
这将在openpyxl 2.4中实现。在发布之前,您必须手动重新创建打印设置。