我使用以下内容将pandas数据帧写入预先格式化的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
命名范围用于避免链接断开。
我遇到的问题是运行时的代码输出:
\Continuum\Anaconda3\lib\sitepackages\openpyxl\workbook\names\named_range.py:124: UserWarning: Discarded range with reserved name
warnings.warn("Discarded range with reserved name")
就结果而言,一切似乎都很好,但打印区域已重置 有没有办法在新文件中保留模板中的打印区域?
有没有办法看到被丢弃的东西?