feat(xq0052): 台账改用 WPS 维护并新增导出快照,支持只导出/只维护台账(0.4.0)
- 新增 logic/snapshot.py:导出后落快照,台账失败可复用上次导出数据重试,不用重新取数 - 台账只走 WPS 表格(不调 Office),字段提示同步改为关闭 WPS - 新增 通联扫码统计 支付数据追加 / 流程 两个测试;前端重建(ui 产物 + usePluginUI/style 拆分)
This commit is contained in:
@@ -0,0 +1,230 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""通联扫码统计:把导出的「支付数据」追加到工作簿「支付数据」sheet(累计粘贴)。
|
||||
|
||||
导出文件 D:\\资料\\财务\\通联数据导出核对\\支付数据-20261109.xlsx
|
||||
sheet「支付数据」,第 1 行标题,A..BK 共 63 列
|
||||
目标文件 D:\\资料\\财务\\通联数据导出核对\\扫码统计11.9.xlsx
|
||||
sheet「支付数据」,第 1 行标题=导出标题前多一列 A「日期」(公式 =IF(HOUR(G)<10,INT(G)-1,INT(G))),
|
||||
即导出 A..BK 对应目标 B..BK。追加时从目标最后一个数据行的下一行起,把导出数据写入 B 列起,
|
||||
A 列沿用目标表已有日期公式。先校验标题逐列对齐,再整块复制粘贴,最后抽样校验首/中/末行。
|
||||
引擎:WPS/Excel COM(Ket.Application → et.Application → Excel.Application)。
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
# ---------- 配置(全部固化在文件内,不接受命令行参数) ----------
|
||||
TARGET_WORKBOOK = r"D:\资料\财务\通联数据导出核对\扫码统计11.9.xlsx"
|
||||
SOURCE_WORKBOOK = r"D:\资料\财务\通联数据导出核对\支付数据-20261109.xlsx"
|
||||
SHEET_NAME = "支付数据"
|
||||
TITLE_ROWS = 1 # 导出表标题行数,追加时跳过
|
||||
TGT_COL_OFFSET = 1 # 目标表在导出列前多 1 列(A 列「日期」)
|
||||
DATE_COL = 1 # 目标表日期列(公式列)
|
||||
COM_PROG_IDS = ("Ket.Application", "et.Application", "Excel.Application")
|
||||
|
||||
XL_UP = -4162 # xlUp
|
||||
XL_PASTE_ALL = -4104 # xlPasteAll
|
||||
|
||||
|
||||
class FlowError(RuntimeError):
|
||||
"""流程执行失败(文件不存在 / COM 不可用 / 标题不一致等)。"""
|
||||
|
||||
|
||||
def log(msg, *args):
|
||||
print("[{}] {}".format(time.strftime("%H:%M:%S"), msg % args if args else msg))
|
||||
|
||||
|
||||
def open_app():
|
||||
import pythoncom
|
||||
import win32com.client
|
||||
|
||||
pythoncom.CoInitialize()
|
||||
app, prog_id, last_err = None, "", None
|
||||
for pid in COM_PROG_IDS:
|
||||
try:
|
||||
app = win32com.client.Dispatch(pid)
|
||||
prog_id = pid
|
||||
break
|
||||
except Exception as e: # noqa: BLE001 - COM 探测失败逐个兜底
|
||||
last_err = e
|
||||
if app is None:
|
||||
pythoncom.CoUninitialize()
|
||||
raise FlowError("本机未检测到可用的 WPS/Excel COM(依次尝试 {} 均失败):{}".format(
|
||||
" / ".join(COM_PROG_IDS), last_err))
|
||||
app.DisplayAlerts = False
|
||||
return app, prog_id
|
||||
|
||||
|
||||
def open_workbook(app, path):
|
||||
"""已打开则复用(不关闭、不影响用户实例),否则自行打开。返回 (workbook, 是否复用)。"""
|
||||
if not os.path.isfile(path):
|
||||
raise FlowError("文件不存在:{}".format(path))
|
||||
abs_path = os.path.normcase(os.path.abspath(path))
|
||||
for w in app.Workbooks:
|
||||
try:
|
||||
if os.path.normcase(os.path.abspath(str(w.FullName or ""))) == abs_path:
|
||||
return w, True
|
||||
except Exception: # noqa: BLE001
|
||||
continue
|
||||
return app.Workbooks.Open(path), False
|
||||
|
||||
|
||||
def read_row(ws, row, first_col, last_col):
|
||||
vals = ws.Range(ws.Cells(row, first_col), ws.Cells(row, last_col)).Value2
|
||||
if not isinstance(vals, tuple):
|
||||
return (vals,)
|
||||
if vals and not isinstance(vals[0], tuple):
|
||||
return vals
|
||||
return vals[0]
|
||||
|
||||
|
||||
def _same(a, b):
|
||||
if a is None and b is None:
|
||||
return True
|
||||
if a is None or b is None:
|
||||
return False
|
||||
if isinstance(a, (int, float)) and isinstance(b, (int, float)) \
|
||||
and not isinstance(a, bool) and not isinstance(b, bool):
|
||||
return abs(float(a) - float(b)) <= 1e-4
|
||||
return str(a).strip() == str(b).strip()
|
||||
|
||||
|
||||
def check_headers(ws_src, ws_tgt, cols):
|
||||
"""校验目标表第 2 列起与导出表标题逐列一致,避免错列追加。"""
|
||||
src_header = read_row(ws_src, 1, 1, cols)
|
||||
tgt_header = read_row(ws_tgt, 1, 1 + TGT_COL_OFFSET, cols + TGT_COL_OFFSET)
|
||||
diffs = [(c + 1, v_s, v_t) for c, (v_s, v_t) in enumerate(zip(src_header, tgt_header))
|
||||
if not _same(v_s, v_t)]
|
||||
if diffs:
|
||||
raise FlowError("标题行不一致,已中止追加(导出列号, 导出, 目标):{}".format(diffs[:8]))
|
||||
log("标题校验通过:导出 A..%s(%d 列)= 目标 B..%s", _col_letter(cols), cols,
|
||||
_col_letter(cols + TGT_COL_OFFSET))
|
||||
|
||||
|
||||
def main():
|
||||
import pythoncom
|
||||
|
||||
app, prog_id = open_app()
|
||||
log("COM 引擎:%s", prog_id)
|
||||
wb_tgt = wb_src = None
|
||||
tgt_opened = src_opened = False
|
||||
try:
|
||||
wb_src, src_reused = open_workbook(app, SOURCE_WORKBOOK)
|
||||
src_opened = not src_reused
|
||||
wb_tgt, tgt_reused = open_workbook(app, TARGET_WORKBOOK)
|
||||
tgt_opened = not tgt_reused
|
||||
if wb_tgt.ReadOnly:
|
||||
raise FlowError("目标工作簿以只读方式打开,无法追加:{}".format(TARGET_WORKBOOK))
|
||||
log("导出表:%s%s", SOURCE_WORKBOOK, "(复用已打开)" if src_reused else "")
|
||||
log("目标簿:%s%s", TARGET_WORKBOOK, "(复用已打开)" if tgt_reused else "")
|
||||
|
||||
ws_src = wb_src.Worksheets(SHEET_NAME)
|
||||
ws_tgt = wb_tgt.Worksheets(SHEET_NAME)
|
||||
src_last = ws_src.Cells(ws_src.Rows.Count, 1).End(XL_UP).Row
|
||||
cols = ws_src.UsedRange.Column + ws_src.UsedRange.Columns.Count - 1
|
||||
if src_last <= TITLE_ROWS:
|
||||
raise FlowError("导出表「{}」没有数据行(最后一行 {})".format(SHEET_NAME, src_last))
|
||||
check_headers(ws_src, ws_tgt, cols)
|
||||
|
||||
try:
|
||||
if ws_tgt.AutoFilterMode:
|
||||
ws_tgt.AutoFilterMode = False
|
||||
log("已取消目标表筛选(追加前)")
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
|
||||
# 目标表最后一个数据行按 B 列(订单id)判定:A 列日期公式已预填到几十万行,不能看 A 列
|
||||
tgt_last = ws_tgt.Cells(ws_tgt.Rows.Count, 1 + TGT_COL_OFFSET).End(XL_UP).Row
|
||||
dst_row = tgt_last + 1
|
||||
rows = src_last - TITLE_ROWS
|
||||
log("导出 %d 行数据(A%d:%s%d),目标数据末行 %d,追加到第 %d 行起(%s 列)",
|
||||
rows, TITLE_ROWS + 1, _col_letter(cols), src_last, tgt_last, dst_row,
|
||||
_col_letter(1 + TGT_COL_OFFSET))
|
||||
|
||||
rng = ws_src.Range(ws_src.Cells(TITLE_ROWS + 1, 1), ws_src.Cells(src_last, cols))
|
||||
rng.Copy()
|
||||
try:
|
||||
ws_tgt.Cells(dst_row, 1 + TGT_COL_OFFSET).PasteSpecial(Paste=XL_PASTE_ALL)
|
||||
finally:
|
||||
try:
|
||||
app.CutCopyMode = False
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
|
||||
new_last = dst_row + rows - 1
|
||||
actual_new_last = ws_tgt.Cells(ws_tgt.Rows.Count, 1 + TGT_COL_OFFSET).End(XL_UP).Row
|
||||
if actual_new_last != new_last:
|
||||
raise FlowError("追加后行号异常:预期最后一行 {},实际 {}".format(new_last, actual_new_last))
|
||||
log("已追加完成:目标「%s」数据行 %d → %d", SHEET_NAME, tgt_last, actual_new_last)
|
||||
|
||||
# A 列日期公式:模板已预填;若最后两行缺失则从上一行填充并重算新增段
|
||||
if not str(ws_tgt.Cells(new_last, DATE_COL).Formula).startswith("="):
|
||||
ws_tgt.Range(ws_tgt.Cells(dst_row - 1, DATE_COL),
|
||||
ws_tgt.Cells(new_last, DATE_COL)).FillDown()
|
||||
log("A 列日期公式缺失,已从第 %d 行向下填充", dst_row - 1)
|
||||
ws_tgt.Range(ws_tgt.Cells(dst_row, DATE_COL),
|
||||
ws_tgt.Cells(new_last, DATE_COL)).Calculate()
|
||||
|
||||
wb_tgt.Save()
|
||||
log("目标工作簿已保存")
|
||||
|
||||
# 抽样校验:首/中/末行,数据列逐格 + A 列日期口径
|
||||
for tag, src_row in (("首行", TITLE_ROWS + 1),
|
||||
("中间行", TITLE_ROWS + 1 + rows // 2),
|
||||
("末行", src_last)):
|
||||
tgt_row = dst_row + (src_row - TITLE_ROWS - 1)
|
||||
diffs = [(c + 1, v_s, v_t)
|
||||
for c, (v_s, v_t) in enumerate(zip(read_row(ws_src, src_row, 1, cols),
|
||||
read_row(ws_tgt, tgt_row, 1 + TGT_COL_OFFSET,
|
||||
cols + TGT_COL_OFFSET)))
|
||||
if not _same(v_s, v_t)]
|
||||
if diffs:
|
||||
raise FlowError("抽样校验失败({},第 {} 行):{}".format(tag, tgt_row, diffs[:8]))
|
||||
pay_time = ws_tgt.Cells(tgt_row, 1 + TGT_COL_OFFSET + 5).Value2 # G 列支付完成时间
|
||||
expect_date = int(pay_time) - 1 if int(pay_time * 24) % 24 < 10 else int(pay_time)
|
||||
actual_date = ws_tgt.Cells(tgt_row, DATE_COL).Value2
|
||||
if not _same(float(expect_date), actual_date):
|
||||
raise FlowError("A 列日期校验失败(第 {} 行):预期 {} 实际 {}".format(
|
||||
tgt_row, expect_date, actual_date))
|
||||
log("抽样校验通过(%s,第 %d 行,日期值 %s)", tag, tgt_row, actual_date)
|
||||
finally:
|
||||
try:
|
||||
if wb_tgt is not None and tgt_opened:
|
||||
wb_tgt.Close(SaveChanges=False)
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
try:
|
||||
if wb_src is not None and src_opened:
|
||||
wb_src.Close(SaveChanges=False)
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
try:
|
||||
app.DisplayAlerts = True
|
||||
if app.Workbooks.Count == 0:
|
||||
app.Quit()
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
try:
|
||||
pythoncom.CoUninitialize()
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
|
||||
log("流程通过")
|
||||
return 0
|
||||
|
||||
|
||||
def _col_letter(col):
|
||||
"""列号转字母(63 → BK)。"""
|
||||
s = ""
|
||||
while col > 0:
|
||||
col, rem = divmod(col - 1, 26)
|
||||
s = chr(65 + rem) + s
|
||||
return s
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main())
|
||||
except FlowError as e:
|
||||
print("[ERROR] {}".format(e))
|
||||
sys.exit(2)
|
||||
@@ -0,0 +1,244 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""通联扫码统计表每日流程(第 1、2 步)演练脚本。
|
||||
|
||||
流程:
|
||||
① 复制上一日的工作簿「扫码统计_<上日>.xlsx」,另存为「扫码统计_<今日>.xlsx」(同一目录)
|
||||
② 打开今日工作簿:「统计表本日」A5:N<最后一行> 复制,「统计表上日」A5 起粘贴为数值
|
||||
|
||||
数据源目录 D:\\资料\\财务\\通联数据导出核对;只新建今日工作簿,不改上一日文件(只读复制)。
|
||||
引擎:WPS/Excel COM(Ket.Application → et.Application → Excel.Application),执行后自动校验。
|
||||
"""
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
# ---------- 配置(全部固化在文件内,不接受命令行参数) ----------
|
||||
SOURCE_DIR = Path(r"D:\资料\财务\通联数据导出核对")
|
||||
SOURCE_GLOB = "扫码统计_*.xlsx"
|
||||
NEW_FILE_PREFIX = "扫码统计" # 今日文件名:扫码统计_YYYYMMDD.xlsx
|
||||
SHEET_DAY = "统计表本日"
|
||||
SHEET_PREV = "统计表上日"
|
||||
START_ROW = 5
|
||||
FIRST_COL = 1 # A
|
||||
LAST_COL = 14 # N
|
||||
OVERWRITE_EXISTING = True # 今日文件已存在时是否覆盖(重新演练可置 True)
|
||||
COM_PROG_IDS = ("Ket.Application", "et.Application", "Excel.Application")
|
||||
|
||||
XL_UP = -4162 # xlUp
|
||||
XL_PASTE_VALUES = -4163 # xlPasteValues
|
||||
|
||||
|
||||
class FlowError(RuntimeError):
|
||||
"""流程执行失败(找不到源文件 / COM 不可用 / 文件被占用等)。"""
|
||||
|
||||
|
||||
def log(msg, *args):
|
||||
print("[{}] {}".format(time.strftime("%H:%M:%S"), msg % args if args else msg))
|
||||
|
||||
|
||||
# ---------- 文件准备 ----------
|
||||
def _file_date(p):
|
||||
"""从文件名提取 8 位日期,取不到返回 0。"""
|
||||
m = re.match(r"{}(\d{{8}})".format(NEW_FILE_PREFIX), p.stem)
|
||||
return int(m.group(1)) if m else 0
|
||||
|
||||
|
||||
def pick_source(target_name):
|
||||
"""取上一日工作簿:排除今日目标文件名,按文件名日期(缺省看修改时间)取最新。"""
|
||||
if not SOURCE_DIR.is_dir():
|
||||
raise FlowError("源目录不存在:{}".format(SOURCE_DIR))
|
||||
files = [p for p in SOURCE_DIR.glob(SOURCE_GLOB)
|
||||
if p.is_file() and p.name != target_name and "流程测试" not in p.name]
|
||||
if not files:
|
||||
raise FlowError("源目录下未找到可复制的 {}:{}".format(SOURCE_GLOB, SOURCE_DIR))
|
||||
return max(files, key=lambda p: (_file_date(p), p.stat().st_mtime))
|
||||
|
||||
|
||||
def copy_to_today(src):
|
||||
"""① 复制上一日工作簿为今日工作簿(同名目录、文件名带今日日期)。"""
|
||||
target = SOURCE_DIR / "{}_{}.xlsx".format(NEW_FILE_PREFIX, time.strftime("%Y%m%d"))
|
||||
if target.exists() and not OVERWRITE_EXISTING:
|
||||
raise FlowError("今日工作簿已存在,未覆盖:{}(如需重新演练请改 OVERWRITE_EXISTING".format(target))
|
||||
try:
|
||||
shutil.copy2(str(src), str(target))
|
||||
except OSError as e:
|
||||
raise FlowError("复制今日工作簿失败(目标文件可能正被 WPS/Excel 打开):{}\n{}".format(target, e)) from e
|
||||
log("① 已复制工作簿:%s → %s", src.name, target.name)
|
||||
return target
|
||||
|
||||
|
||||
# ---------- COM 准备 ----------
|
||||
def open_app():
|
||||
import pythoncom
|
||||
import win32com.client
|
||||
|
||||
pythoncom.CoInitialize()
|
||||
app, prog_id, last_err = None, "", None
|
||||
for pid in COM_PROG_IDS:
|
||||
try:
|
||||
app = win32com.client.Dispatch(pid)
|
||||
prog_id = pid
|
||||
break
|
||||
except Exception as e: # noqa: BLE001 - COM 探测失败逐个兜底
|
||||
last_err = e
|
||||
if app is None:
|
||||
pythoncom.CoUninitialize()
|
||||
raise FlowError("本机未检测到可用的 WPS/Excel COM(依次尝试 {} 均失败):{}".format(
|
||||
" / ".join(COM_PROG_IDS), last_err))
|
||||
app.DisplayAlerts = False
|
||||
return app, prog_id
|
||||
|
||||
|
||||
def recalc(wb):
|
||||
"""全量重算(WPS/Excel 版本兼容兜底)。"""
|
||||
try:
|
||||
wb.Application.CalculateFullRebuild()
|
||||
except Exception: # noqa: BLE001
|
||||
try:
|
||||
wb.Application.CalculateFull()
|
||||
except Exception: # noqa: BLE001
|
||||
wb.Application.Calculate()
|
||||
|
||||
|
||||
# ---------- 单元格读写 ----------
|
||||
def last_data_row(ws):
|
||||
"""A/B 列自下往上找最后一行有数据的位置。"""
|
||||
return max(ws.Cells(ws.Rows.Count, 1).End(XL_UP).Row,
|
||||
ws.Cells(ws.Rows.Count, 2).End(XL_UP).Row)
|
||||
|
||||
|
||||
def read_matrix(ws, last_row):
|
||||
rng = ws.Range(ws.Cells(START_ROW, FIRST_COL), ws.Cells(last_row, LAST_COL))
|
||||
vals = rng.Value2
|
||||
if not isinstance(vals, tuple):
|
||||
return ((vals,),)
|
||||
if vals and not isinstance(vals[0], tuple):
|
||||
return (vals,)
|
||||
return vals
|
||||
|
||||
|
||||
def _same(a, b):
|
||||
if a is None and b is None:
|
||||
return True
|
||||
if a is None or b is None:
|
||||
return False
|
||||
if isinstance(a, (int, float)) and isinstance(b, (int, float)) \
|
||||
and not isinstance(a, bool) and not isinstance(b, bool):
|
||||
return abs(float(a) - float(b)) <= 1e-4
|
||||
return str(a).strip() == str(b).strip()
|
||||
|
||||
|
||||
def compare(expect, actual):
|
||||
"""逐格比对矩阵,返回差异列表。"""
|
||||
diffs = []
|
||||
for i, row_e in enumerate(expect):
|
||||
for j, v_e in enumerate(row_e):
|
||||
v_a = actual[i][j] if i < len(actual) and j < len(actual[i]) else None
|
||||
if not _same(v_e, v_a):
|
||||
diffs.append((i + START_ROW, j + FIRST_COL, v_e, v_a))
|
||||
return diffs
|
||||
|
||||
|
||||
# ---------- 流程步骤 ----------
|
||||
def step2_paste_values(app, ws_day, ws_prev, day_last_row, day_values):
|
||||
"""② 「统计表本日」A5:N<最后一行> → 「统计表上日」A5 起,粘贴为数值。"""
|
||||
rng = ws_day.Range(ws_day.Cells(START_ROW, FIRST_COL), ws_day.Cells(day_last_row, LAST_COL))
|
||||
rng.Copy()
|
||||
try:
|
||||
ws_prev.Range("A5").PasteSpecial(Paste=XL_PASTE_VALUES)
|
||||
except Exception as e: # noqa: BLE001 - 合并单元格场景(M/N 列纵向合并)兜底逐格写值
|
||||
log("② 区域粘贴为数值失败(%s),改为逐格写值", e)
|
||||
app.CutCopyMode = False
|
||||
for i, row in enumerate(day_values):
|
||||
for j, val in enumerate(row):
|
||||
cell = ws_prev.Cells(i + START_ROW, j + FIRST_COL)
|
||||
if cell.MergeCells and cell.Address != cell.MergeArea.Cells(1, 1).Address:
|
||||
continue
|
||||
cell.Value2 = val
|
||||
finally:
|
||||
try:
|
||||
app.CutCopyMode = False
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
rows = day_last_row - START_ROW + 1
|
||||
log("② 已将 A%d:N%d(%d 行 × %d 列)粘贴为数值到「%s」A5 起",
|
||||
START_ROW, day_last_row, rows, LAST_COL - FIRST_COL + 1, SHEET_PREV)
|
||||
|
||||
|
||||
# ---------- 校验 ----------
|
||||
def verify(wb, day_last_row, day_values):
|
||||
ok = True
|
||||
ws_prev = wb.Worksheets(SHEET_PREV)
|
||||
diffs = compare(day_values, read_matrix(ws_prev, day_last_row))
|
||||
if diffs:
|
||||
ok = False
|
||||
log("校验失败:「%s」A5:N%d 与本日粘贴前数值不一致 %d 格,前 5 处:%s",
|
||||
SHEET_PREV, day_last_row, len(diffs), diffs[:5])
|
||||
else:
|
||||
log("校验通过:「%s」A5:N%d 与本日粘贴前数值完全一致", SHEET_PREV, day_last_row)
|
||||
|
||||
summary = ws_prev.Range("A5:N5").Value2[0]
|
||||
log("「%s」第 5 行(合计):%s", SHEET_PREV,
|
||||
" | ".join("" if v is None else str(v) for v in summary))
|
||||
return ok
|
||||
|
||||
|
||||
# ---------- 主流程 ----------
|
||||
def main():
|
||||
import pythoncom
|
||||
|
||||
today_name = "{}_{}.xlsx".format(NEW_FILE_PREFIX, time.strftime("%Y%m%d"))
|
||||
src = pick_source(today_name)
|
||||
log("上一日工作簿:%s", src)
|
||||
out = copy_to_today(src)
|
||||
|
||||
app, prog_id = open_app()
|
||||
log("COM 引擎:%s", prog_id)
|
||||
wb = None
|
||||
try:
|
||||
wb = app.Workbooks.Open(str(out))
|
||||
if wb.ReadOnly:
|
||||
raise FlowError("今日工作簿被以只读方式打开,请关闭 WPS/Excel 中同名文件后重试:{}".format(out))
|
||||
|
||||
recalc(wb)
|
||||
ws_day = wb.Worksheets(SHEET_DAY)
|
||||
ws_prev = wb.Worksheets(SHEET_PREV)
|
||||
day_last_row = last_data_row(ws_day)
|
||||
day_values = read_matrix(ws_day, day_last_row)
|
||||
log("数据范围:%s 第 %d 行(%d 行 × %d 列)", SHEET_DAY, day_last_row,
|
||||
day_last_row - START_ROW + 1, LAST_COL - FIRST_COL + 1)
|
||||
|
||||
step2_paste_values(app, ws_day, ws_prev, day_last_row, day_values)
|
||||
|
||||
recalc(wb)
|
||||
wb.Save()
|
||||
ok = verify(wb, day_last_row, day_values)
|
||||
finally:
|
||||
try:
|
||||
if wb is not None:
|
||||
wb.Close(SaveChanges=False)
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
try:
|
||||
app.DisplayAlerts = True
|
||||
if app.Workbooks.Count == 0:
|
||||
app.Quit()
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
try:
|
||||
pythoncom.CoUninitialize()
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
|
||||
log("流程%s,产物:%s", "通过" if ok else "存在差异(见上方日志)", out)
|
||||
return 0 if ok else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main())
|
||||
except FlowError as e:
|
||||
print("[ERROR] {}".format(e))
|
||||
sys.exit(2)
|
||||
Reference in New Issue
Block a user