From 9e3a940ec2b78bece48d7071f4698394d24fa07c Mon Sep 17 00:00:00 2001 From: Akira Date: Mon, 11 Nov 2024 00:46:28 +0900 Subject: [PATCH] Fix missing print parameters --- SumasenLibs/excel_lib/sumaexcel/sumaexcel.py | 86 ++++++++++++++++++-- 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/SumasenLibs/excel_lib/sumaexcel/sumaexcel.py b/SumasenLibs/excel_lib/sumaexcel/sumaexcel.py index 8336ce3..25e96e9 100644 --- a/SumasenLibs/excel_lib/sumaexcel/sumaexcel.py +++ b/SumasenLibs/excel_lib/sumaexcel/sumaexcel.py @@ -934,6 +934,19 @@ class SumasenExcel: # self.current_sheet.merge_cells(target_merge_range) # #print(f"Merge : {target_merge_range}") + + # 印刷範囲の設定をコピー + if self.template_sheet.print_area: + self.current_sheet.print_area = self.template_sheet.print_area + + # 印刷タイトルの設定をコピー + if self.template_sheet.print_title_rows: + self.current_sheet.print_title_rows = self.template_sheet.print_title_rows + if self.template_sheet.print_title_cols: + self.current_sheet.print_title_cols = self.template_sheet.print_title_cols + + + # Copy cell contents and styles row_offset = target_min_row - orig_min_row for row in range(orig_min_row, orig_max_row + 1): @@ -958,16 +971,24 @@ class SumasenExcel: target_page_setup = self.current_sheet.page_setup source_page_setup = self.template_sheet.page_setup - # Copy supported page setup attributes - copyable_attrs = [ - 'paperSize', - 'orientation', - 'fitToHeight', - 'fitToWidth', - 'scale' + # ページ設定属性のコピー + page_setup_attrs = [ + 'orientation', # 印刷の向き + 'paperSize', # 用紙サイズ + 'scale', # 拡大縮小率 + 'fitToHeight', # 高さの自動調整 + 'fitToWidth', # 幅の自動調整 + 'firstPageNumber', # 開始ページ番号 + 'useFirstPageNumber', # 開始ページ番号の使用 + 'blackAndWhite', # モノクロ印刷 + 'draft', # 下書きモード + 'cellComments', # コメントの印刷方法 + 'errors', # エラーの表示方法 + 'horizontalDpi', # 水平DPI + 'verticalDpi' # 垂直DPI ] - for attr in copyable_attrs: + for attr in page_setup_attrs: try: if hasattr(source_page_setup, attr): setattr(target_page_setup, attr, getattr(source_page_setup, attr)) @@ -1005,12 +1026,61 @@ class SumasenExcel: except Exception as e: logging.warning(f"Could not copy print option {attr}: {str(e)}") + # ヘッダー/フッターのコピー + if hasattr(self.template_sheet, 'oddHeader'): + self.current_sheet.oddHeader = self.template_sheet.oddHeader + if hasattr(self.template_sheet, 'oddFooter'): + self.current_sheet.oddFooter = self.template_sheet.oddFooter + if hasattr(self.template_sheet, 'evenHeader'): + self.current_sheet.evenHeader = self.template_sheet.evenHeader + if hasattr(self.template_sheet, 'evenFooter'): + self.current_sheet.evenFooter = self.template_sheet.evenFooter + if hasattr(self.template_sheet, 'firstHeader'): + self.current_sheet.firstHeader = self.template_sheet.firstHeader + if hasattr(self.template_sheet, 'firstFooter'): + self.current_sheet.firstFooter = self.template_sheet.firstFooter + + # 用紙の向きと用紙サイズの検証 + self._verify_page_setup() + return {"status": True, "message": "Successfully copied template range"} except Exception as e: logging.error(f"Error in copy_template_to_current: {str(e)}") return {"status": False, "message": f"Exception in copy_template_to_current: {str(e)}"} + def _verify_page_setup(self): + """ + ページ設定が正しくコピーされたことを検証する + """ + try: + # 用紙の向きの検証 + if self.template_sheet.page_setup.orientation != self.current_sheet.page_setup.orientation: + logging.warning( + f"Page orientation mismatch: template={self.template_sheet.page_setup.orientation}, " + f"current={self.current_sheet.page_setup.orientation}" + ) + + # 用紙サイズの検証 + if self.template_sheet.page_setup.paperSize != self.current_sheet.page_setup.paperSize: + logging.warning( + f"Paper size mismatch: template={self.template_sheet.page_setup.paperSize}, " + f"current={self.current_sheet.page_setup.paperSize}" + ) + + # 余白設定の検証 + margin_attrs = ['left', 'right', 'top', 'bottom', 'header', 'footer'] + for attr in margin_attrs: + template_margin = getattr(self.template_sheet.page_margins, attr) + current_margin = getattr(self.current_sheet.page_margins, attr) + if abs(template_margin - current_margin) > 0.01: # 小数点の誤差を考慮 + logging.warning( + f"Margin {attr} mismatch: template={template_margin}, current={current_margin}" + ) + + except Exception as e: + logging.error(f"Error in _verify_page_setup: {str(e)}") + # Style operations def apply_style( self,