audit-e2w 1.11.2 → 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.
- package/README.md +152 -148
- package/dsh_plugins/audit-e2w/lib/index.js +9 -1
- package/dsh_plugins/audit-e2w/lib/skill.js +3 -2
- package/excel_word/README.md +45 -37
- package/excel_word/qoder_engine.py +10 -11
- package/excel_word/wesync/__init__.py +1 -1
- package/excel_word/wesync/ai/__init__.py +52 -0
- package/excel_word/wesync/ai/actions.py +369 -0
- package/excel_word/wesync/ai/client.py +340 -0
- package/excel_word/wesync/ai/config.py +291 -0
- package/excel_word/wesync/ai/docs.py +177 -0
- package/excel_word/wesync/ai/prompts.py +288 -0
- package/excel_word/wesync/ai/tasks/__init__.py +26 -0
- package/excel_word/wesync/ai/tasks/actions_task.py +97 -0
- package/excel_word/wesync/ai/tasks/combined.py +123 -0
- package/excel_word/wesync/ai/tasks/diff_note.py +61 -0
- package/excel_word/wesync/ai/tasks/headings.py +119 -0
- package/excel_word/wesync/ai/tasks/help_task.py +69 -0
- package/excel_word/wesync/ai/tasks/roles.py +128 -0
- package/excel_word/wesync/align.py +1 -0
- package/excel_word/wesync/api.py +544 -92
- package/excel_word/wesync/backup_history.py +44 -9
- package/excel_word/wesync/cli.py +19 -1
- package/excel_word/wesync/commands/blank_cmd.py +59 -30
- package/excel_word/wesync/commands/bookmark_cmd.py +41 -10
- package/excel_word/wesync/commands/clear_cmd.py +5 -3
- package/excel_word/wesync/commands/export_cmd.py +270 -220
- package/excel_word/wesync/commands/incremental_cmd.py +157 -0
- package/excel_word/wesync/commands/marks_cmd.py +24 -16
- package/excel_word/wesync/commands/placeholders_cmd.py +12 -7
- package/excel_word/wesync/commands/writeback_cmd.py +72 -116
- package/excel_word/wesync/config.py +3 -2
- package/excel_word/wesync/console.py +9 -2
- package/excel_word/wesync/docx_bookmarks.py +12 -5
- package/excel_word/wesync/docx_columns.py +1 -1
- package/excel_word/wesync/docx_marks.py +183 -75
- package/excel_word/wesync/docx_placeholders.py +65 -26
- package/excel_word/wesync/excel_blocks.py +144 -185
- package/excel_word/wesync/excel_export.py +15 -8
- package/excel_word/wesync/excel_marks.py +265 -193
- package/excel_word/wesync/fsops.py +11 -6
- package/excel_word/wesync/gui/__init__.py +21 -2
- package/excel_word/wesync/gui/app.py +243 -29
- package/excel_word/wesync/gui/manual.py +5 -3
- package/excel_word/wesync/gui/pages/__init__.py +53 -4
- package/excel_word/wesync/gui/pages/_page.py +129 -7
- package/excel_word/wesync/gui/pages/ai_page.py +854 -0
- package/excel_word/wesync/gui/pages/batch_page.py +64 -31
- package/excel_word/wesync/gui/pages/blank_page.py +529 -464
- package/excel_word/wesync/gui/pages/bookmark_page.py +97 -37
- package/excel_word/wesync/gui/pages/export_page.py +140 -87
- package/excel_word/wesync/gui/pages/feedback_page.py +196 -0
- package/excel_word/wesync/gui/pages/format_page.py +551 -429
- package/excel_word/wesync/gui/pages/help_page.py +73 -7
- package/excel_word/wesync/gui/pages/history_page.py +167 -144
- package/excel_word/wesync/gui/pages/marks_page.py +210 -177
- package/excel_word/wesync/gui/pages/settings_page.py +450 -0
- package/excel_word/wesync/gui/pages/writeback_page.py +167 -146
- package/excel_word/wesync/gui/runner.py +29 -13
- package/excel_word/wesync/gui/store.py +23 -7
- package/excel_word/wesync/gui/theme.py +220 -49
- package/excel_word/wesync/gui/widgets/ai_config.py +362 -0
- package/excel_word/wesync/gui/widgets/cards.py +124 -5
- package/excel_word/wesync/gui/widgets/chips.py +565 -0
- package/excel_word/wesync/gui/widgets/filebar.py +1 -1
- package/excel_word/wesync/gui/widgets/logpane.py +24 -8
- package/excel_word/wesync/gui/widgets/nav.py +267 -12
- package/excel_word/wesync/gui/widgets/theme_choice.py +93 -0
- package/excel_word/wesync/report_format.py +9 -1
- package/excel_word/wesync/settings.py +35 -0
- package/excel_word/wesync/sort_rules.py +75 -26
- package/excel_word/wesync/valuefmt.py +40 -17
- package/package.json +53 -51
- package/packaging//344/275/277/347/224/250/350/257/264/346/230/216.txt +247 -0
- package/qoder_plugins/audit-toolbox/README.md +159 -156
- package/qoder_plugins/audit-toolbox/catalog.mjs +13 -13
|
@@ -1,193 +1,265 @@
|
|
|
1
|
-
"""工作簿里的「链接标注」工作表:高亮标记的导出与回读。
|
|
2
|
-
|
|
3
|
-
列:标记 | 书签 | 位置 | 原文 | 新内容 | 链接地址 | →定位Word
|
|
4
|
-
* 导出/刷新时按书签名保留已填的「新内容」「链接地址」;
|
|
5
|
-
* Word 中已删除的标记保留成行并在位置列标注「(Word 中已删除)」。
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from __future__ import annotations
|
|
9
|
-
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
|
|
12
|
-
from openpyxl import load_workbook
|
|
13
|
-
from openpyxl.styles import Alignment, Border, Font, PatternFill, Side
|
|
14
|
-
from openpyxl.utils import get_column_letter
|
|
15
|
-
from openpyxl.worksheet.hyperlink import Hyperlink
|
|
16
|
-
|
|
17
|
-
from .config import FONT_NAME
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
from .
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if ws.max_row is None:
|
|
52
|
-
return rows
|
|
53
|
-
for row_index in range(2, ws.max_row + 1):
|
|
54
|
-
def
|
|
55
|
-
c = ws.cell(row_index, column)
|
|
56
|
-
raw = c.value
|
|
57
|
-
if resolve_formulas and isinstance(raw, str) and raw.startswith("="):
|
|
58
|
-
raw = formula_result(ws, row_index, column, cached_ws)
|
|
59
|
-
if raw is None:
|
|
60
|
-
raise SyncError(
|
|
61
|
-
f"「{SHEET_MARKS}」{c.coordinate} 是公式但没有可用的计算结果。"
|
|
62
|
-
"请先在 Excel 中打开该工作簿,完成重算并保存后再同步。"
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if
|
|
146
|
-
ws.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
row_index
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
ws.cell(row_index,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
ws
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
ws.cell(row_index,
|
|
179
|
-
|
|
180
|
-
row_index
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
cell
|
|
1
|
+
"""工作簿里的「链接标注」工作表:高亮标记的导出与回读。
|
|
2
|
+
|
|
3
|
+
列:标记 | 书签 | 位置 | 原文 | 新内容 | 链接地址 | →定位Word | 来源 | 登记序号
|
|
4
|
+
* 导出/刷新时按书签名保留已填的「新内容」「链接地址」;
|
|
5
|
+
* Word 中已删除的标记保留成行并在位置列标注「(Word 中已删除)」。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from openpyxl import load_workbook
|
|
13
|
+
from openpyxl.styles import Alignment, Border, Font, PatternFill, Side
|
|
14
|
+
from openpyxl.utils import get_column_letter
|
|
15
|
+
from openpyxl.worksheet.hyperlink import Hyperlink
|
|
16
|
+
|
|
17
|
+
from .config import FONT_NAME
|
|
18
|
+
|
|
19
|
+
SHEET_MARKS = "链接标注"
|
|
20
|
+
HEADERS = ["标记", "书签", "位置", "原文", "新内容", "链接地址", "→定位Word", "来源", "登记序号"]
|
|
21
|
+
HEADER_FILL = PatternFill("solid", fgColor="FFF2CC")
|
|
22
|
+
DELETED_FONT = Font(name=FONT_NAME, size=10, color="9AA3AF")
|
|
23
|
+
THIN = Side(style="thin", color="E3E6EA")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def read_previous_marks(xlsx_path: Path) -> list[dict]:
|
|
27
|
+
"""读取现有工作簿里「链接标注」工作表的历史内容(用于保留已填写项)。"""
|
|
28
|
+
if not xlsx_path.exists():
|
|
29
|
+
return []
|
|
30
|
+
try:
|
|
31
|
+
workbook = load_workbook(str(xlsx_path))
|
|
32
|
+
except Exception:
|
|
33
|
+
return []
|
|
34
|
+
if SHEET_MARKS not in workbook.sheetnames:
|
|
35
|
+
return []
|
|
36
|
+
return parse_marks_rows(workbook[SHEET_MARKS], resolve_formulas=False)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def parse_marks_rows(ws, cached_ws=None, *, resolve_formulas: bool = True, zero_mode: str = "excel") -> list[dict]:
|
|
40
|
+
"""把工作表读成行字典;遇到「标记」列空行就停止。
|
|
41
|
+
|
|
42
|
+
「新内容」按单元格在 Excel 里的显示效果转换(与表格回写/占位符同口径):
|
|
43
|
+
日期按数字格式渲染(如 2025年12月31日),不会出现 2025-12-31 00:00:00;
|
|
44
|
+
金额千分位/小数位照显示。公式优先取 Excel 缓存结果,其次轻量求值。
|
|
45
|
+
"""
|
|
46
|
+
from .errors import SyncError
|
|
47
|
+
from .valuefmt import display_cell, formula_result
|
|
48
|
+
|
|
49
|
+
rows: list[dict] = []
|
|
50
|
+
seen_bookmarks: dict[str, int] = {}
|
|
51
|
+
if ws.max_row is None:
|
|
52
|
+
return rows
|
|
53
|
+
for row_index in range(2, ws.max_row + 1):
|
|
54
|
+
def raw_cell(column: int):
|
|
55
|
+
c = ws.cell(row_index, column)
|
|
56
|
+
raw = c.value
|
|
57
|
+
if resolve_formulas and isinstance(raw, str) and raw.startswith("="):
|
|
58
|
+
raw = formula_result(ws, row_index, column, cached_ws)
|
|
59
|
+
if raw is None:
|
|
60
|
+
raise SyncError(
|
|
61
|
+
f"「{SHEET_MARKS}」{c.coordinate} 是公式但没有可用的计算结果。"
|
|
62
|
+
"请先在 Excel 中打开该工作簿,完成重算并保存后再同步。"
|
|
63
|
+
)
|
|
64
|
+
return raw
|
|
65
|
+
|
|
66
|
+
def cell(column: int, display: bool = False) -> str:
|
|
67
|
+
c = ws.cell(row_index, column)
|
|
68
|
+
raw = raw_cell(column)
|
|
69
|
+
if display:
|
|
70
|
+
return display_cell(c, raw, zero_mode=zero_mode).strip()
|
|
71
|
+
return "" if raw is None else str(raw).strip()
|
|
72
|
+
|
|
73
|
+
label = cell(1)
|
|
74
|
+
if not label:
|
|
75
|
+
break
|
|
76
|
+
bookmark = cell(2)
|
|
77
|
+
if bookmark:
|
|
78
|
+
if bookmark in seen_bookmarks:
|
|
79
|
+
raise SyncError(
|
|
80
|
+
f"「{SHEET_MARKS}」书签 {bookmark} 重复出现在第 {seen_bookmarks[bookmark]} 行和第 {row_index} 行,"
|
|
81
|
+
"无法确定同步目标。请合并为一行后再同步。"
|
|
82
|
+
)
|
|
83
|
+
seen_bookmarks[bookmark] = row_index
|
|
84
|
+
sequence = ws.cell(row_index, 9).value
|
|
85
|
+
try:
|
|
86
|
+
sequence = int(sequence)
|
|
87
|
+
except (TypeError, ValueError):
|
|
88
|
+
sequence = row_index - 1
|
|
89
|
+
rows.append(
|
|
90
|
+
{
|
|
91
|
+
"row": row_index,
|
|
92
|
+
"label": label,
|
|
93
|
+
"bookmark": bookmark,
|
|
94
|
+
"position": cell(3),
|
|
95
|
+
"original": cell(4),
|
|
96
|
+
"new": cell(5, display=True),
|
|
97
|
+
"new_filled": bool(ws.cell(row_index, 5).value is not None and str(raw_cell(5)).strip()),
|
|
98
|
+
"link": cell(6),
|
|
99
|
+
"source": cell(8),
|
|
100
|
+
"sequence": sequence,
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
return rows
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def build_marks_sheet(
|
|
107
|
+
wb,
|
|
108
|
+
docx_name: str,
|
|
109
|
+
marks: list,
|
|
110
|
+
previous: list[dict],
|
|
111
|
+
processed: list[dict] | None = None,
|
|
112
|
+
) -> dict:
|
|
113
|
+
"""在 ``wb`` 中创建/刷新「链接标注」工作表,返回统计。
|
|
114
|
+
|
|
115
|
+
三类行:待处理(仍带高亮)→ 已处理(同步过、已去色,书签仍在)→ 已删除(Word 里连书签都没了)。
|
|
116
|
+
行号(M01…)按书签沿用上一版,保证 Excel 里引用稳定。
|
|
117
|
+
"""
|
|
118
|
+
previous_by_bookmark = {row["bookmark"]: row for row in previous if row["bookmark"]}
|
|
119
|
+
current = {mark.bookmark for mark in marks if mark.bookmark}
|
|
120
|
+
orphans = [row for row in previous if row["bookmark"] and row["bookmark"] not in current]
|
|
121
|
+
processed = processed or []
|
|
122
|
+
processed_names = {item["bookmark"] for item in processed}
|
|
123
|
+
orphans = [row for row in orphans if row["bookmark"] not in processed_names]
|
|
124
|
+
|
|
125
|
+
label_by_bookmark = {row["bookmark"]: row["label"] for row in previous if row["bookmark"]}
|
|
126
|
+
used_numbers = set()
|
|
127
|
+
for label in label_by_bookmark.values():
|
|
128
|
+
if isinstance(label, str) and label.startswith("M") and label[1:].isdigit():
|
|
129
|
+
used_numbers.add(int(label[1:]))
|
|
130
|
+
next_number = 1
|
|
131
|
+
|
|
132
|
+
def label_for(bookmark: str) -> str:
|
|
133
|
+
nonlocal next_number
|
|
134
|
+
if bookmark in label_by_bookmark:
|
|
135
|
+
return label_by_bookmark[bookmark]
|
|
136
|
+
while next_number in used_numbers:
|
|
137
|
+
next_number += 1
|
|
138
|
+
used_numbers.add(next_number)
|
|
139
|
+
label = f"M{next_number:02d}"
|
|
140
|
+
label_by_bookmark[bookmark] = label
|
|
141
|
+
return label
|
|
142
|
+
|
|
143
|
+
if SHEET_MARKS in wb.sheetnames:
|
|
144
|
+
ws = wb[SHEET_MARKS]
|
|
145
|
+
if ws.max_row:
|
|
146
|
+
ws.delete_rows(1, ws.max_row)
|
|
147
|
+
else:
|
|
148
|
+
ws = wb.create_sheet(SHEET_MARKS)
|
|
149
|
+
|
|
150
|
+
for column, title in enumerate(HEADERS, start=1):
|
|
151
|
+
cell = ws.cell(1, column, title)
|
|
152
|
+
cell.font = Font(name=FONT_NAME, size=10, bold=True, color="1F4E79")
|
|
153
|
+
cell.fill = HEADER_FILL
|
|
154
|
+
cell.alignment = Alignment(horizontal="center", vertical="center")
|
|
155
|
+
cell.border = Border(left=THIN, right=THIN, top=THIN, bottom=THIN)
|
|
156
|
+
|
|
157
|
+
row_index = 2
|
|
158
|
+
for mark in marks:
|
|
159
|
+
old = previous_by_bookmark.get(mark.bookmark, {})
|
|
160
|
+
ws.cell(row_index, 1, label_for(mark.bookmark))
|
|
161
|
+
ws.cell(row_index, 2, mark.bookmark)
|
|
162
|
+
ws.cell(row_index, 3, mark.location)
|
|
163
|
+
ws.cell(row_index, 4, mark.text)
|
|
164
|
+
if old.get("new"):
|
|
165
|
+
ws.cell(row_index, 5, old["new"])
|
|
166
|
+
ws.cell(row_index, 6, old.get("link", ""))
|
|
167
|
+
ws.cell(row_index, 8, "全量")
|
|
168
|
+
ws.cell(row_index, 9, row_index - 1)
|
|
169
|
+
link_cell = ws.cell(row_index, 7, "→定位Word")
|
|
170
|
+
link_cell.hyperlink = Hyperlink(
|
|
171
|
+
ref=link_cell.coordinate, target=docx_name, location=mark.bookmark, display="→定位Word"
|
|
172
|
+
)
|
|
173
|
+
_style_row(ws, row_index)
|
|
174
|
+
row_index += 1
|
|
175
|
+
|
|
176
|
+
for item in processed:
|
|
177
|
+
old = previous_by_bookmark.get(item["bookmark"], {})
|
|
178
|
+
ws.cell(row_index, 1, label_for(item["bookmark"]))
|
|
179
|
+
ws.cell(row_index, 2, item["bookmark"])
|
|
180
|
+
ws.cell(row_index, 3, f"{item['location']}(已处理)")
|
|
181
|
+
ws.cell(row_index, 4, item["text"] or old.get("original", ""))
|
|
182
|
+
if old.get("new"):
|
|
183
|
+
ws.cell(row_index, 5, old["new"])
|
|
184
|
+
if old.get("link"):
|
|
185
|
+
ws.cell(row_index, 6, old["link"])
|
|
186
|
+
ws.cell(row_index, 7, "(已处理)")
|
|
187
|
+
ws.cell(row_index, 8, "全量")
|
|
188
|
+
ws.cell(row_index, 9, row_index - 1)
|
|
189
|
+
_style_row(ws, row_index, deleted=True)
|
|
190
|
+
row_index += 1
|
|
191
|
+
|
|
192
|
+
for orphan in orphans:
|
|
193
|
+
ws.cell(row_index, 1, label_for(orphan["bookmark"]) if orphan.get("bookmark") else orphan.get("label", ""))
|
|
194
|
+
ws.cell(row_index, 2, orphan.get("bookmark", ""))
|
|
195
|
+
position = (orphan.get("position") or "").replace("(Word 中已删除)", "")
|
|
196
|
+
ws.cell(row_index, 3, f"{position}(Word 中已删除)")
|
|
197
|
+
ws.cell(row_index, 4, orphan.get("original", ""))
|
|
198
|
+
if orphan.get("new"):
|
|
199
|
+
ws.cell(row_index, 5, orphan["new"])
|
|
200
|
+
if orphan.get("link"):
|
|
201
|
+
ws.cell(row_index, 6, orphan["link"])
|
|
202
|
+
ws.cell(row_index, 7, "(已删除)")
|
|
203
|
+
ws.cell(row_index, 8, "全量")
|
|
204
|
+
ws.cell(row_index, 9, row_index - 1)
|
|
205
|
+
_style_row(ws, row_index, deleted=True)
|
|
206
|
+
row_index += 1
|
|
207
|
+
|
|
208
|
+
for column, width in {1: 7, 2: 12, 3: 18, 4: 26, 5: 26, 6: 34, 7: 12, 8: 10, 9: 10}.items():
|
|
209
|
+
ws.column_dimensions[get_column_letter(column)].width = width
|
|
210
|
+
ws.freeze_panes = "A2"
|
|
211
|
+
return {"marks": len(marks), "processed": len(processed), "orphans": len(orphans)}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def append_marks_sheet(wb, docx_name: str, marks: list, previous: list[dict]) -> dict:
|
|
215
|
+
"""只追加新增标记;既有行、行号、公式和填写值完全不动。"""
|
|
216
|
+
known = {row.get("bookmark") for row in previous if row.get("bookmark")}
|
|
217
|
+
marks = [mark for mark in marks if not mark.bookmark or mark.bookmark not in known]
|
|
218
|
+
if not marks:
|
|
219
|
+
return {"marks": 0, "processed": 0, "orphans": 0}
|
|
220
|
+
if SHEET_MARKS in wb.sheetnames:
|
|
221
|
+
ws = wb[SHEET_MARKS]
|
|
222
|
+
else:
|
|
223
|
+
ws = wb.create_sheet(SHEET_MARKS)
|
|
224
|
+
previous = []
|
|
225
|
+
for column, title in enumerate(HEADERS, start=1):
|
|
226
|
+
cell = ws.cell(1, column, title)
|
|
227
|
+
cell.font = Font(name=FONT_NAME, size=10, bold=True, color="1F4E79")
|
|
228
|
+
cell.fill = HEADER_FILL
|
|
229
|
+
cell.alignment = Alignment(horizontal="center", vertical="center")
|
|
230
|
+
cell.border = Border(left=THIN, right=THIN, top=THIN, bottom=THIN)
|
|
231
|
+
known_labels = {str(row.get("label") or "") for row in previous}
|
|
232
|
+
next_number = 1
|
|
233
|
+
while f"XM{next_number:02d}" in known_labels:
|
|
234
|
+
next_number += 1
|
|
235
|
+
sequence = max([int(row.get("sequence") or 0) for row in previous] + [0]) + 1
|
|
236
|
+
added = 0
|
|
237
|
+
for mark in marks:
|
|
238
|
+
while f"XM{next_number:02d}" in known_labels:
|
|
239
|
+
next_number += 1
|
|
240
|
+
label = f"XM{next_number:02d}"
|
|
241
|
+
next_number += 1
|
|
242
|
+
known_labels.add(label)
|
|
243
|
+
row_index = max(ws.max_row or 1, 1) + 1
|
|
244
|
+
values = [label, mark.bookmark, mark.location, mark.text, "", "", "→定位Word", "增量", sequence]
|
|
245
|
+
for column, value in enumerate(values, start=1):
|
|
246
|
+
ws.cell(row_index, column, value)
|
|
247
|
+
link_cell = ws.cell(row_index, 7)
|
|
248
|
+
link_cell.hyperlink = Hyperlink(
|
|
249
|
+
ref=link_cell.coordinate, target=docx_name, location=mark.bookmark, display="→定位Word"
|
|
250
|
+
)
|
|
251
|
+
_style_row(ws, row_index)
|
|
252
|
+
sequence += 1
|
|
253
|
+
added += 1
|
|
254
|
+
for column, width in {1: 7, 2: 12, 3: 18, 4: 26, 5: 26, 6: 34, 7: 12, 8: 10, 9: 10}.items():
|
|
255
|
+
ws.column_dimensions[get_column_letter(column)].width = width
|
|
256
|
+
ws.freeze_panes = "A2"
|
|
257
|
+
return {"marks": added, "processed": 0, "orphans": 0}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _style_row(ws, row_index: int, deleted: bool = False) -> None:
|
|
261
|
+
for column in range(1, len(HEADERS) + 1):
|
|
262
|
+
cell = ws.cell(row_index, column)
|
|
263
|
+
cell.font = DELETED_FONT if deleted else Font(name=FONT_NAME, size=10)
|
|
264
|
+
cell.alignment = Alignment(vertical="center", wrap_text=column in (3, 4, 5, 6))
|
|
265
|
+
cell.border = Border(left=THIN, right=THIN, top=THIN, bottom=THIN)
|
|
@@ -133,11 +133,13 @@ def _stage_office_file(path: Path, save, validate) -> dict:
|
|
|
133
133
|
try:
|
|
134
134
|
save(staged)
|
|
135
135
|
validate(staged)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
existed = path.exists()
|
|
137
|
+
if existed:
|
|
138
|
+
fd, rollback_name = tempfile.mkstemp(prefix=f".{path.stem}.rollback.", suffix=path.suffix, dir=path.parent)
|
|
139
|
+
os.close(fd)
|
|
140
|
+
rollback = Path(rollback_name)
|
|
141
|
+
shutil.copy2(path, rollback)
|
|
142
|
+
return {"path": path, "new": staged, "old": rollback, "backup": None, "keep_old": False, "existed": existed}
|
|
141
143
|
except Exception:
|
|
142
144
|
staged.unlink(missing_ok=True)
|
|
143
145
|
if rollback is not None:
|
|
@@ -187,7 +189,10 @@ def save_docx_xlsx_transaction(
|
|
|
187
189
|
rollback_errors = []
|
|
188
190
|
for previous in reversed(replaced):
|
|
189
191
|
try:
|
|
190
|
-
|
|
192
|
+
if previous["existed"]:
|
|
193
|
+
os.replace(previous["old"], previous["path"])
|
|
194
|
+
else:
|
|
195
|
+
previous["path"].unlink(missing_ok=True)
|
|
191
196
|
previous["old"] = None
|
|
192
197
|
except OSError as rollback_exc:
|
|
193
198
|
previous["keep_old"] = True
|
|
@@ -9,23 +9,42 @@ from __future__ import annotations
|
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
def _install_translation(app):
|
|
13
|
+
from PySide6 import __file__ as pyside_file
|
|
14
|
+
from PySide6.QtCore import QTranslator
|
|
15
|
+
|
|
16
|
+
class _ChineseTranslator(QTranslator):
|
|
17
|
+
def translate(self, context, sourceText, disambiguation=None, n=-1):
|
|
18
|
+
text = super().translate(context, sourceText, disambiguation, n)
|
|
19
|
+
if text or "&" not in sourceText:
|
|
20
|
+
return text
|
|
21
|
+
return super().translate(context, sourceText.replace("&", ""), disambiguation, n)
|
|
22
|
+
|
|
23
|
+
translator = _ChineseTranslator(app)
|
|
24
|
+
path = Path(pyside_file).parent / "translations" / "qtbase_zh_CN.qm"
|
|
25
|
+
if not translator.load(str(path)):
|
|
26
|
+
raise RuntimeError(f"缺少简体中文界面资源:{path}")
|
|
27
|
+
app.installTranslator(translator)
|
|
28
|
+
return translator
|
|
29
|
+
|
|
30
|
+
|
|
12
31
|
def run(base_dir: Path | None = None) -> int:
|
|
13
32
|
"""启动界面主循环,返回进程退出码。"""
|
|
14
33
|
from PySide6.QtCore import Qt
|
|
15
34
|
from PySide6.QtGui import QIcon
|
|
16
35
|
from PySide6.QtWidgets import QApplication
|
|
17
36
|
|
|
18
|
-
from . import theme
|
|
19
37
|
from .app import WesyncApp
|
|
20
38
|
from .resources import icon_path
|
|
21
39
|
|
|
22
40
|
# 按系统实际缩放比例渲染(150% 即 1.5 倍)。不能用 Round:它会把 150% 取整成 2 倍,
|
|
23
41
|
# 字体在一部分高分屏电脑上显得异常大;Qt6 支持分数缩放,不必担心半像素发虚。
|
|
24
42
|
QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
|
|
43
|
+
QApplication.setAttribute(Qt.ApplicationAttribute.AA_DontUseNativeDialogs, True)
|
|
25
44
|
app = QApplication.instance() or QApplication([])
|
|
45
|
+
_install_translation(app)
|
|
26
46
|
app.setApplicationName("审计工具箱")
|
|
27
47
|
app.setWindowIcon(QIcon(str(icon_path())))
|
|
28
|
-
theme.apply(app)
|
|
29
48
|
window = WesyncApp(base_dir=base_dir)
|
|
30
49
|
window.show()
|
|
31
50
|
return app.exec()
|