From 65692fc7985255a1a5ff0205ce5125c566f5d4f5 Mon Sep 17 00:00:00 2001 From: user9994793890 <3722323274763196-user9994793890@noreply.coze.cn> Date: Fri, 10 Jul 2026 10:01:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DExcel=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=97=B6=E7=9A=84MergedCell=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:'MergedCell' object has no attribute 'column_letter' 原因: - 第1行和第2行的单元格被合并(merge_cells) - 代码尝试访问合并单元格的 column_letter 属性 - 合并单元格(MergedCell)没有这个属性 修复: - 使用 openpyxl.utils.get_column_letter(col_idx) 获取列字母 - 不再依赖单元格的 column_letter 属性 现在可以正常生成Excel文件了。 Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087 --- lib/report_generator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/report_generator.py b/lib/report_generator.py index 33a4a14..6aef469 100644 --- a/lib/report_generator.py +++ b/lib/report_generator.py @@ -268,7 +268,10 @@ def generate_excel(orders, selected_fields, sum_fields, sum_results, for cell in row: if cell.value: max_length = max(max_length, len(str(cell.value))) - ws.column_dimensions[ws.cell(row=1, column=col_idx).column_letter].width = min(max_length + 2, 50) + # 使用 openpyxl 的列字母转换函数 + from openpyxl.utils import get_column_letter + col_letter = get_column_letter(col_idx) + ws.column_dimensions[col_letter].width = min(max_length + 2, 50) # 保存文件 wb.save(file_path)