audit-e2w 0.0.0-stage → 1.11.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -3
  3. package/cordis.patch.yml +3 -0
  4. package/dsh_plugins/audit-e2w/lib/engine.mjs +174 -0
  5. package/dsh_plugins/audit-e2w/lib/index.js +122 -0
  6. package/dsh_plugins/audit-e2w/lib/skill.js +42 -0
  7. package/excel_word/README.md +388 -0
  8. package/excel_word/qoder_engine.py +437 -0
  9. package/excel_word/requirements.txt +4 -0
  10. package/excel_word/wesync/__init__.py +19 -0
  11. package/excel_word/wesync/__main__.py +6 -0
  12. package/excel_word/wesync/ai/__init__.py +52 -0
  13. package/excel_word/wesync/ai/actions.py +369 -0
  14. package/excel_word/wesync/ai/client.py +340 -0
  15. package/excel_word/wesync/ai/config.py +291 -0
  16. package/excel_word/wesync/ai/docs.py +177 -0
  17. package/excel_word/wesync/ai/prompts.py +288 -0
  18. package/excel_word/wesync/ai/tasks/__init__.py +26 -0
  19. package/excel_word/wesync/ai/tasks/actions_task.py +97 -0
  20. package/excel_word/wesync/ai/tasks/combined.py +123 -0
  21. package/excel_word/wesync/ai/tasks/diff_note.py +61 -0
  22. package/excel_word/wesync/ai/tasks/headings.py +119 -0
  23. package/excel_word/wesync/ai/tasks/help_task.py +69 -0
  24. package/excel_word/wesync/ai/tasks/roles.py +128 -0
  25. package/excel_word/wesync/align.py +155 -0
  26. package/excel_word/wesync/api.py +1292 -0
  27. package/excel_word/wesync/backup_history.py +100 -0
  28. package/excel_word/wesync/changelog.py +58 -0
  29. package/excel_word/wesync/cli.py +191 -0
  30. package/excel_word/wesync/commands/__init__.py +8 -0
  31. package/excel_word/wesync/commands/blank_cmd.py +279 -0
  32. package/excel_word/wesync/commands/bookmark_cmd.py +146 -0
  33. package/excel_word/wesync/commands/clear_cmd.py +50 -0
  34. package/excel_word/wesync/commands/export_cmd.py +270 -0
  35. package/excel_word/wesync/commands/incremental_cmd.py +157 -0
  36. package/excel_word/wesync/commands/marks_cmd.py +160 -0
  37. package/excel_word/wesync/commands/placeholders_cmd.py +92 -0
  38. package/excel_word/wesync/commands/writeback_cmd.py +469 -0
  39. package/excel_word/wesync/config.py +97 -0
  40. package/excel_word/wesync/console.py +85 -0
  41. package/excel_word/wesync/docx_blank.py +156 -0
  42. package/excel_word/wesync/docx_bookmarks.py +294 -0
  43. package/excel_word/wesync/docx_columns.py +257 -0
  44. package/excel_word/wesync/docx_edit.py +77 -0
  45. package/excel_word/wesync/docx_grid.py +212 -0
  46. package/excel_word/wesync/docx_marks.py +399 -0
  47. package/excel_word/wesync/docx_meta.py +157 -0
  48. package/excel_word/wesync/docx_newtable.py +220 -0
  49. package/excel_word/wesync/docx_placeholders.py +200 -0
  50. package/excel_word/wesync/docx_rows.py +67 -0
  51. package/excel_word/wesync/errors.py +5 -0
  52. package/excel_word/wesync/excel_blocks.py +502 -0
  53. package/excel_word/wesync/excel_export.py +143 -0
  54. package/excel_word/wesync/excel_marks.py +265 -0
  55. package/excel_word/wesync/excel_totals.py +53 -0
  56. package/excel_word/wesync/fsops.py +219 -0
  57. package/excel_word/wesync/gui/__init__.py +53 -0
  58. package/excel_word/wesync/gui/__main__.py +6 -0
  59. package/excel_word/wesync/gui/app.py +613 -0
  60. package/excel_word/wesync/gui/manual.py +70 -0
  61. package/excel_word/wesync/gui/pages/__init__.py +80 -0
  62. package/excel_word/wesync/gui/pages/_page.py +211 -0
  63. package/excel_word/wesync/gui/pages/ai_page.py +854 -0
  64. package/excel_word/wesync/gui/pages/batch_page.py +456 -0
  65. package/excel_word/wesync/gui/pages/blank_page.py +530 -0
  66. package/excel_word/wesync/gui/pages/bookmark_page.py +97 -0
  67. package/excel_word/wesync/gui/pages/export_page.py +141 -0
  68. package/excel_word/wesync/gui/pages/feedback_page.py +196 -0
  69. package/excel_word/wesync/gui/pages/format_page.py +551 -0
  70. package/excel_word/wesync/gui/pages/help_page.py +158 -0
  71. package/excel_word/wesync/gui/pages/history_page.py +168 -0
  72. package/excel_word/wesync/gui/pages/marks_page.py +211 -0
  73. package/excel_word/wesync/gui/pages/settings_page.py +450 -0
  74. package/excel_word/wesync/gui/pages/writeback_page.py +473 -0
  75. package/excel_word/wesync/gui/resources.py +22 -0
  76. package/excel_word/wesync/gui/runner.py +90 -0
  77. package/excel_word/wesync/gui/store.py +50 -0
  78. package/excel_word/wesync/gui/theme.py +271 -0
  79. package/excel_word/wesync/gui/widgets/__init__.py +8 -0
  80. package/excel_word/wesync/gui/widgets/ai_config.py +362 -0
  81. package/excel_word/wesync/gui/widgets/cards.py +139 -0
  82. package/excel_word/wesync/gui/widgets/chips.py +565 -0
  83. package/excel_word/wesync/gui/widgets/filebar.py +58 -0
  84. package/excel_word/wesync/gui/widgets/logpane.py +126 -0
  85. package/excel_word/wesync/gui/widgets/nav.py +294 -0
  86. package/excel_word/wesync/gui/widgets/theme_choice.py +93 -0
  87. package/excel_word/wesync/report_format.py +1585 -0
  88. package/excel_word/wesync/settings.py +35 -0
  89. package/excel_word/wesync/sort_rules.py +293 -0
  90. package/excel_word/wesync/valuefmt.py +485 -0
  91. package/package.json +53 -6
  92. package/packaging//344/275/277/347/224/250/350/257/264/346/230/216.txt +247 -0
  93. package/qoder_plugins/audit-toolbox/README.md +159 -0
  94. package/qoder_plugins/audit-toolbox/catalog.mjs +265 -0
@@ -0,0 +1,35 @@
1
+ """全局操作默认值与 Word 零值显示策略。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ DEFAULTS = {
6
+ "auto_backup": True,
7
+ "excel_links": True,
8
+ "totals_formula": True,
9
+ # 默认三项全同步:表格、标注、占位符。多数报告三类内容都有,
10
+ # 只同步表格会让人以为「标注丢了」,所以默认全开。
11
+ "sync_tables": True,
12
+ "sync_marks": True,
13
+ "sync_placeholders": True,
14
+ "keep_highlight": True,
15
+ "reversible_delete": True,
16
+ "table_zero": "blank",
17
+ "mark_zero": "fixed",
18
+ "placeholder_zero": "fixed",
19
+ }
20
+
21
+ ZERO_MODES = {"excel", "fixed", "dash", "blank"}
22
+ ZERO_LABELS = {"excel": "按 Excel 格式", "fixed": "0.00", "dash": "小横杠 -", "blank": "空白"}
23
+ BOOL_KEYS = {key for key, value in DEFAULTS.items() if isinstance(value, bool)}
24
+ ZERO_KEYS = {"table_zero", "mark_zero", "placeholder_zero"}
25
+
26
+
27
+ def normalize(values: dict) -> dict:
28
+ result = dict(DEFAULTS)
29
+ for key in DEFAULTS:
30
+ value = values.get(key, DEFAULTS[key])
31
+ if key in BOOL_KEYS and isinstance(value, bool):
32
+ result[key] = value
33
+ elif key in ZERO_KEYS and value in ZERO_MODES:
34
+ result[key] = value
35
+ return result
@@ -0,0 +1,293 @@
1
+ """按金额列排序:锚点行「排序:」设置的读写、数据行重排、导出重建时按书签沿用。
2
+
3
+ 规则:表头行与合计行不动;首列(或第二列)项目名为「其他」的行不参与排序,
4
+ 统一放在数据区末尾(合计行之前);解析不了的金额按最小值排在排序段末尾。
5
+ 数据区含合并单元格的表保守跳过,避免错位。
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from copy import copy
12
+
13
+ from openpyxl.formula import Tokenizer
14
+ from openpyxl.styles import Alignment, Font
15
+
16
+ from .config import FILL_ANCHOR, FONT_NAME, FONT_SIZE, META_SCAN_COLUMNS, NUMBER_RE, SHEET_NAME
17
+ from .console import log, warn
18
+ from .errors import SyncError
19
+ from .valuefmt import display_cell, evaluate_formula
20
+
21
+ SORT_PREFIX = "排序:"
22
+ DESC = "降序"
23
+ ASC = "升序"
24
+ OTHER_ITEM = "其他"
25
+
26
+ _A1_RANGE_RE = re.compile(r"(\$?[A-Za-z]{1,3})(\$?\d+)(?::(\$?[A-Za-z]{1,3})(\$?\d+))?")
27
+ _SHEET_RANGE_RE = re.compile(r"('(?:[^']|'')*'|[^!]+)!(.+)")
28
+
29
+
30
+ def sort_setting_text(column: str, descending: bool = True) -> str:
31
+ return f"{SORT_PREFIX}{column.strip()} {DESC if descending else ASC}"
32
+
33
+
34
+ def parse_sort_setting(text: str) -> tuple[str, bool] | None:
35
+ text = (text or "").strip()
36
+ if not text.startswith(SORT_PREFIX):
37
+ return None
38
+ body = text[len(SORT_PREFIX):].strip()
39
+ descending = True
40
+ if body.endswith(DESC):
41
+ body = body[: -len(DESC)].strip()
42
+ elif body.endswith(ASC):
43
+ descending = False
44
+ body = body[: -len(ASC)].strip()
45
+ return (body, descending) if body else None
46
+
47
+
48
+ def _anchor_style(cell) -> None:
49
+ cell.font = Font(name=FONT_NAME, size=FONT_SIZE, bold=True, color="1F4E79")
50
+ cell.fill = FILL_ANCHOR
51
+ cell.alignment = Alignment(horizontal="left", vertical="center")
52
+
53
+
54
+ def write_block_sort(ws, block: dict, column: str, descending: bool = True) -> None:
55
+ """把排序设置写进锚点行第一个空闲元数据列(列数格之后),已有设置则原位更新。"""
56
+ row = block["anchor_row"]
57
+ col0 = block.get("col0", 2)
58
+ target = None
59
+ for col in range(col0 + 4, META_SCAN_COLUMNS + 1):
60
+ text = "" if ws.cell(row, col).value is None else str(ws.cell(row, col).value).strip()
61
+ if text.startswith(SORT_PREFIX):
62
+ target = col
63
+ break
64
+ if target is None and text == "":
65
+ target = col
66
+ if target is None:
67
+ raise SyncError(f"{block['code']}:锚点行元数据列已满,无法写入排序设置")
68
+ cell = ws.cell(row, target, sort_setting_text(column, descending))
69
+ _anchor_style(cell)
70
+
71
+
72
+ def clear_block_sort(ws, block: dict) -> bool:
73
+ row = block["anchor_row"]
74
+ col0 = block.get("col0", 2)
75
+ cleared = False
76
+ for col in range(col0 + 4, META_SCAN_COLUMNS + 1):
77
+ cell = ws.cell(row, col)
78
+ text = "" if cell.value is None else str(cell.value).strip()
79
+ if text.startswith(SORT_PREFIX):
80
+ cell.value = None
81
+ cleared = True
82
+ return cleared
83
+
84
+
85
+ def block_headers(ws, block: dict) -> list[str]:
86
+ """表块首行(表头)各列显示文本,供界面选择金额列。"""
87
+ if not block["grid_rows"]:
88
+ return []
89
+ head = block["grid_rows"][0]
90
+ col0 = block.get("col0", 2)
91
+ return [
92
+ display_cell(ws.cell(head, col0 + c)).strip()
93
+ for c in range(block["ncols"])
94
+ ]
95
+
96
+
97
+ def _row_text(ws, row: int, col: int) -> str:
98
+ return display_cell(ws.cell(row, col)).strip()
99
+
100
+
101
+ def _amount(ws, row: int, col: int, cached) -> float | None:
102
+ cell = ws.cell(row, col)
103
+ raw = cell.value
104
+ if isinstance(raw, str) and raw.startswith("="):
105
+ raw = cached.get((ws.title, row, col))
106
+ if raw is None:
107
+ raw = evaluate_formula(ws, row, col, cached)
108
+ if isinstance(raw, (int, float)) and not isinstance(raw, bool):
109
+ return float(raw)
110
+ if isinstance(raw, str) and NUMBER_RE.match(raw.strip()):
111
+ try:
112
+ return float(raw.strip().replace(",", ""))
113
+ except ValueError:
114
+ return None
115
+ return None
116
+
117
+
118
+ def _is_other(ws, row: int, ncols: int, col0: int = 2) -> bool:
119
+ if _row_text(ws, row, col0) == OTHER_ITEM:
120
+ return True
121
+ return ncols > 1 and _row_text(ws, row, col0 + 1) == OTHER_ITEM
122
+
123
+
124
+ def _remap_formula(text: str, rowmap: dict[int, int], sheet_name: str | None = None) -> str:
125
+ """仅重映射当前表的相对行引用;绝对行、跨表及复杂引用保守保留。"""
126
+
127
+ def unsupported() -> str:
128
+ warn(f"[排序] 公式含无法可靠处理的引用,已保留原公式:{text}")
129
+ return text
130
+
131
+ try:
132
+ tokens = Tokenizer(text).items
133
+ except Exception:
134
+ return unsupported()
135
+ significant = [token for token in tokens if token.type != "WSPACE"]
136
+ if not significant or significant[-1].type in {"OPERATOR-INFIX", "OPERATOR-PREFIX"}:
137
+ return unsupported()
138
+ depth = 0
139
+ for token in significant:
140
+ if token.type in {"FUNC", "PAREN"} and token.subtype == "OPEN":
141
+ depth += 1
142
+ elif token.type in {"FUNC", "PAREN"} and token.subtype == "CLOSE":
143
+ depth -= 1
144
+ if depth < 0:
145
+ return unsupported()
146
+ if depth:
147
+ return unsupported()
148
+
149
+ rewritten = []
150
+ changed = False
151
+ for token in tokens:
152
+ value = token.value
153
+ if token.type == "OPERAND" and token.subtype == "RANGE":
154
+ if any(mark in value for mark in "[]{}#"): # 结构化/外部/动态引用
155
+ return unsupported()
156
+ ref = value
157
+ qualifier_prefix = ""
158
+ if "!" in value:
159
+ qualified = _SHEET_RANGE_RE.fullmatch(value)
160
+ if qualified is None:
161
+ return unsupported()
162
+ qualifier, ref = qualified.groups()
163
+ qualifier_prefix = value[:len(qualifier) + 1]
164
+ if qualifier.startswith("'"):
165
+ qualifier = qualifier[1:-1].replace("''", "'")
166
+ if ":" in qualifier: # 三维工作表引用
167
+ return unsupported()
168
+ if sheet_name is None or qualifier.casefold() != sheet_name.casefold():
169
+ rewritten.append(value)
170
+ continue
171
+ match = _A1_RANGE_RE.fullmatch(ref)
172
+ if match is None: # 名称、整列/整行等无法可靠按行重映射
173
+ return unsupported()
174
+ col1, row1, col2, row2 = match.groups()
175
+ if row1.startswith("$") or (row2 and row2.startswith("$")):
176
+ rewritten.append(value)
177
+ continue
178
+ if row2 is None:
179
+ value = f"{qualifier_prefix}{col1}{rowmap.get(int(row1), int(row1))}"
180
+ else:
181
+ r1, r2 = int(row1), int(row2)
182
+ rows = [rowmap.get(r, r) for r in range(min(r1, r2), max(r1, r2) + 1)]
183
+ value = f"{qualifier_prefix}{col1}{min(rows)}:{col2}{max(rows)}"
184
+ changed = changed or value != token.value
185
+ rewritten.append(value)
186
+ return ("=" if text.startswith("=") else "") + "".join(rewritten) if changed else text
187
+
188
+
189
+ def apply_block_sort(ws, block: dict, cached: dict, dry_run: bool = False) -> dict | None:
190
+ """按表块保存的排序设置重排数据行(原地修改 ws)。无设置/无需改动时返回 None。"""
191
+ from .excel_blocks import block_merges
192
+
193
+ setting = parse_sort_setting(block.get("meta", {}).get("sort", ""))
194
+ if setting is None:
195
+ return None
196
+ column, descending = setting
197
+ code = block["code"]
198
+ rows = block["grid_rows"]
199
+ ncols = block["ncols"]
200
+ if len(rows) < 3:
201
+ return None
202
+ headers = block_headers(ws, block)
203
+ matches = [c for c, h in enumerate(headers) if h == column]
204
+ if not matches:
205
+ warn(f"[排序] {code}:找不到金额列「{column}」(表头可能已改),本次跳过排序")
206
+ return None
207
+ sort_col = block.get("col0", 2) + matches[0]
208
+ col0 = block.get("col0", 2)
209
+
210
+ data = rows[1:]
211
+ tail_start = next((i for i, r in enumerate(data) if _row_text(ws, r, col0).startswith("合计")), len(data))
212
+ sortable, tail = data[:tail_start], data[tail_start:]
213
+ if len(sortable) < 2:
214
+ return None
215
+ sort_idx = {r: i + 1 for i, r in enumerate(sortable)} # 相对块内网格的行号(表头为 0)
216
+ for (r, _c, rs, cs) in block_merges(ws, block):
217
+ if (rs > 1 or cs > 1) and any(r <= idx < r + rs for idx in sort_idx.values()):
218
+ warn(f"[排序] {code}:数据区含合并单元格,为避免错位本次跳过排序")
219
+ return None
220
+
221
+ normal = [r for r in sortable if not _is_other(ws, r, ncols, col0)]
222
+ others = [r for r in sortable if _is_other(ws, r, ncols, col0)]
223
+ parsed = [r for r in normal if _amount(ws, r, sort_col, cached) is not None]
224
+ unparsed_rows = [r for r in normal if r not in parsed]
225
+ unparsed = [_row_text(ws, r, col0) or f"第{sort_idx[r] + 1}行" for r in unparsed_rows]
226
+ ordered = sorted(parsed, key=lambda r: _amount(ws, r, sort_col, cached), reverse=descending)
227
+ new_data = ordered + unparsed_rows + others + tail
228
+ if new_data == data:
229
+ log(f"[排序] {code}:已是「{column} {DESC if descending else ASC}」顺序,无需改动")
230
+ return None
231
+ moved = sum(1 for old, new in zip(data, new_data) if old != new)
232
+ note = f"(其他 {len(others)} 行置底" + (f",{len(unparsed)} 行金额无法解析按最小值处理:{'、'.join(unparsed[:5])}" if unparsed else "") + ")"
233
+ if dry_run:
234
+ log(f"[排序·预演] {code}:按「{column}」{DESC if descending else ASC}重排,{moved} 行将移动{note},合计行不动")
235
+ return {"moved": moved, "others": len(others), "unparsed": unparsed}
236
+
237
+ snapshot = {}
238
+ for r in data:
239
+ for c in range(2, col0 + ncols):
240
+ cell = ws.cell(r, c)
241
+ snapshot[(r, c)] = (cell.value, copy(cell._style) if cell.has_style else None,
242
+ copy(cell.hyperlink) if cell.hyperlink is not None else None)
243
+ heights = {r: ws.row_dimensions[r].height for r in data if r in ws.row_dimensions and ws.row_dimensions[r].height is not None}
244
+ rowmap = {old: new for old, new in zip(data, new_data)}
245
+ for target, source in zip(data, new_data):
246
+ for c in range(2, col0 + ncols):
247
+ value, style, link = snapshot[(source, c)]
248
+ cell = ws.cell(target, c)
249
+ cell.value = value
250
+ if style is not None:
251
+ cell._style = style
252
+ if link is not None:
253
+ link.ref = cell.coordinate
254
+ cell.hyperlink = link
255
+ else:
256
+ cell.hyperlink = None
257
+ if source in heights:
258
+ ws.row_dimensions[target].height = heights[source]
259
+ ws.row_dimensions[target].customHeight = True
260
+ for r in data:
261
+ for c in range(2, col0 + ncols):
262
+ cell = ws.cell(r, c)
263
+ if isinstance(cell.value, str) and cell.value.startswith("="):
264
+ cell.value = _remap_formula(cell.value, rowmap, ws.title)
265
+ cached_snapshot = {
266
+ (sheet, r, c): value
267
+ for (sheet, r, c), value in cached.items()
268
+ if sheet == ws.title and r in rowmap
269
+ }
270
+ for key in cached_snapshot:
271
+ del cached[key]
272
+ for (sheet, r, c), value in cached_snapshot.items():
273
+ cached[(sheet, rowmap[r], c)] = value
274
+ log(f"[排序] {code}:已按「{column}」{DESC if descending else ASC}重排 {moved} 行{note},合计行保持末行")
275
+ return {"moved": moved, "others": len(others), "unparsed": unparsed}
276
+
277
+
278
+ def carry_over_sort_settings(wb_new, ws_old, blocks_old: dict) -> list[str]:
279
+ """导出重建工作簿后,把旧表块的排序设置按书签名沿用到新表块。"""
280
+ from .excel_blocks import parse_blocks
281
+
282
+ ws_new = wb_new[SHEET_NAME]
283
+ _, blocks_new = parse_blocks(ws_new)
284
+ by_bookmark = {b["bookmark"]: b for b in blocks_new.values() if b.get("bookmark")}
285
+ carried = []
286
+ for block in blocks_old.values():
287
+ setting = parse_sort_setting(block.get("meta", {}).get("sort", ""))
288
+ bookmark = block.get("bookmark", "")
289
+ if setting is None or not bookmark or bookmark not in by_bookmark:
290
+ continue
291
+ write_block_sort(ws_new, by_bookmark[bookmark], setting[0], setting[1])
292
+ carried.append(by_bookmark[bookmark]["code"])
293
+ return carried