#!/usr/bin/env python3 """ 调试报告生成过程,找出卡住的具体位置 """ import json import sys from pathlib import Path def analyze_script_data(): """分析脚本返回的数据结构""" script_data_json = '''{"tables": [{"token": "scriptTable1", "startRow": 0, "startCol": 0, "cells": [{"row": 4, "col": 0, "value": ""}, {"row": 4, "col": 1, "value": ""}, {"row": 4, "col": 2, "value": ""}, {"row": 4, "col": 3, "value": ""}, {"row": 4, "col": 4, "value": ""}, {"row": 4, "col": 5, "value": ""}, {"row": 4, "col": 6, "value": ""}, {"row": 5, "col": 0, "value": ""}, {"row": 5, "col": 1, "value": ""}, {"row": 5, "col": 2, "value": ""}, {"row": 5, "col": 3, "value": ""}, {"row": 5, "col": 4, "value": ""}, {"row": 5, "col": 5, "value": ""}, {"row": 5, "col": 6, "value": ""}, {"row": 6, "col": 0, "value": ""}, {"row": 6, "col": 1, "value": ""}, {"row": 6, "col": 2, "value": ""}, {"row": 6, "col": 3, "value": ""}, {"row": 6, "col": 4, "value": ""}, {"row": 6, "col": 5, "value": ""}, {"row": 6, "col": 6, "value": ""}, {"row": 7, "col": 0, "value": ""}, {"row": 7, "col": 1, "value": ""}, {"row": 7, "col": 2, "value": ""}, {"row": 7, "col": 3, "value": ""}, {"row": 7, "col": 4, "value": ""}, {"row": 7, "col": 5, "value": ""}, {"row": 7, "col": 6, "value": ""}, {"row": 8, "col": 0, "value": ""}, {"row": 8, "col": 1, "value": ""}, {"row": 8, "col": 2, "value": ""}, {"row": 8, "col": 3, "value": ""}, {"row": 8, "col": 4, "value": ""}, {"row": 8, "col": 5, "value": ""}, {"row": 8, "col": 6, "value": ""}, {"row": 9, "col": 0, "value": ""}, {"row": 9, "col": 1, "value": ""}, {"row": 9, "col": 2, "value": ""}, {"row": 9, "col": 3, "value": ""}, {"row": 9, "col": 4, "value": ""}, {"row": 9, "col": 5, "value": ""}, {"row": 9, "col": 6, "value": ""}, {"row": 10, "col": 0, "value": ""}, {"row": 10, "col": 1, "value": ""}, {"row": 10, "col": 2, "value": ""}, {"row": 10, "col": 3, "value": ""}, {"row": 10, "col": 4, "value": ""}, {"row": 10, "col": 5, "value": ""}, {"row": 10, "col": 6, "value": ""}, {"row": 11, "col": 0, "value": ""}, {"row": 11, "col": 1, "value": ""}, {"row": 11, "col": 2, "value": ""}, {"row": 11, "col": 3, "value": ""}, {"row": 11, "col": 4, "value": ""}, {"row": 11, "col": 5, "value": ""}, {"row": 11, "col": 6, "value": ""}, {"row": 12, "col": 0, "value": ""}, {"row": 12, "col": 1, "value": ""}, {"row": 12, "col": 2, "value": ""}, {"row": 12, "col": 3, "value": ""}, {"row": 12, "col": 4, "value": ""}, {"row": 12, "col": 5, "value": ""}, {"row": 12, "col": 6, "value": ""}, {"row": 13, "col": 0, "value": ""}, {"row": 13, "col": 1, "value": ""}, {"row": 13, "col": 2, "value": ""}, {"row": 13, "col": 3, "value": ""}, {"row": 13, "col": 4, "value": ""}, {"row": 13, "col": 5, "value": ""}, {"row": 13, "col": 6, "value": ""}, {"row": 14, "col": 0, "value": ""}, {"row": 14, "col": 1, "value": ""}, {"row": 14, "col": 2, "value": ""}, {"row": 14, "col": 3, "value": ""}, {"row": 14, "col": 4, "value": ""}, {"row": 14, "col": 5, "value": ""}, {"row": 14, "col": 6, "value": ""}, {"row": 15, "col": 0, "value": ""}, {"row": 15, "col": 1, "value": ""}, {"row": 15, "col": 2, "value": ""}, {"row": 15, "col": 3, "value": ""}, {"row": 15, "col": 4, "value": ""}, {"row": 15, "col": 5, "value": ""}, {"row": 15, "col": 6, "value": ""}, {"row": 16, "col": 0, "value": ""}, {"row": 16, "col": 1, "value": ""}, {"row": 16, "col": 2, "value": ""}, {"row": 16, "col": 3, "value": ""}, {"row": 16, "col": 4, "value": ""}, {"row": 16, "col": 5, "value": ""}, {"row": 16, "col": 6, "value": ""}, {"row": 17, "col": 0, "value": ""}, {"row": 17, "col": 1, "value": ""}, {"row": 17, "col": 2, "value": ""}, {"row": 17, "col": 3, "value": ""}, {"row": 17, "col": 4, "value": ""}, {"row": 17, "col": 5, "value": ""}, {"row": 17, "col": 6, "value": ""}, {"row": 18, "col": 0, "value": ""}, {"row": 18, "col": 1, "value": ""}, {"row": 18, "col": 2, "value": ""}, {"row": 18, "col": 3, "value": ""}, {"row": 18, "col": 4, "value": ""}, {"row": 18, "col": 5, "value": ""}, {"row": 18, "col": 6, "value": ""}, {"row": 19, "col": 0, "value": ""}, {"row": 19, "col": 1, "value": ""}, {"row": 19, "col": 2, "value": ""}, {"row": 19, "col": 3, "value": ""}, {"row": 19, "col": 4, "value": ""}, {"row": 19, "col": 5, "value": ""}, {"row": 19, "col": 6, "value": ""}, {"row": 20, "col": 0, "value": ""}, {"row": 20, "col": 1, "value": ""}, {"row": 20, "col": 2, "value": ""}, {"row": 20, "col": 3, "value": ""}, {"row": 20, "col": 4, "value": ""}, {"row": 20, "col": 5, "value": ""}, {"row": 20, "col": 6, "value": ""}, {"row": 1, "col": 1, "value": "2025-11-27 11:30:00"}, {"row": 1, "col": 3, "value": "2025-11-27 15:00:00"}, {"row": 0, "col": 1, "value": null}]}]}''' data = json.loads(script_data_json) print("=== 脚本数据分析 ===") print(f"数据结构: {type(data)}") if "tables" in data: print(f"表格数量: {len(data['tables'])}") for i, table in enumerate(data["tables"]): print(f"\n表格 {i+1}:") print(f" token: {table.get('token')}") print(f" startRow: {table.get('startRow')}") print(f" startCol: {table.get('startCol')}") print(f" cells数量: {len(table.get('cells', []))}") cells = table.get('cells', []) # 统计单元格类型 empty_cells = 0 null_cells = 0 valid_cells = 0 for cell in cells: value = cell.get('value') if value is None: null_cells += 1 print(f" NULL单元格: row={cell.get('row')}, col={cell.get('col')}") elif str(value).strip() == "": empty_cells += 1 else: valid_cells += 1 print(f" 有效单元格: row={cell.get('row')}, col={cell.get('col')}, value='{value}'") print(f" 统计: 有效={valid_cells}, 空白={empty_cells}, NULL={null_cells}") # 检查行列范围 if cells: max_row = max(cell.get('row', 0) for cell in cells) max_col = max(cell.get('col', 0) for cell in cells) print(f" 范围: 最大行={max_row}, 最大列={max_col}") def check_potential_issues(): """检查可能导致卡住的问题""" print("\n=== 潜在问题检查 ===") issues = [] # 1. NULL值问题 issues.append("1. 存在NULL值的单元格,可能导致Word COM操作异常") # 2. 大量空单元格 issues.append("2. 存在大量空单元格(119个),可能导致处理缓慢") # 3. 行列索引问题 issues.append("3. 单元格行索引从0-20,可能超出模板表格范围") # 4. Word COM性能问题 issues.append("4. Word COM操作可能因为大量单元格操作而卡住") for issue in issues: print(f" {issue}") def suggest_solutions(): """建议解决方案""" print("\n=== 建议解决方案 ===") solutions = [ "1. 修复temperature_table.py中的NULL值问题", "2. 过滤掉空白单元格,只处理有数据的单元格", "3. 添加更多调试日志到report_generator.py", "4. 增加Word COM操作的超时和错误处理", "5. 考虑批量操作而不是逐个单元格操作" ] for solution in solutions: print(f" {solution}") def main(): print("调试报告生成卡住问题") print("=" * 50) analyze_script_data() check_potential_issues() suggest_solutions() if __name__ == "__main__": main()