以下を使用して、パンダのデータフレームを事前にフォーマットされた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")
結果的にはすべて問題ないようですが、印刷領域がリセットされます。
新しいファイルのテンプレートから印刷領域を保持する方法はありますか?
何が破棄されているかを確認する方法はありますか?
これはopenpyxl2.4で可能になります。これがリリースされるまで、印刷設定を手動で再作成する必要があります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加