@@ -1,14 +1,19 @@
# -*- coding: utf-8 -*-
""" 「新美大核对统计」按日期补 V/W 列外部链接公式 。
""" 「新美大核对统计」按日期补共享总表取数公式(自动扫描整行同源公式) 。
业务口径(从台账既有 62 条链接反推):
V = =[N]资金组取数!$B$5 (应收岗-团购统计表-昨日遗留)
W = =[N ]资金组取数!$B$6 ( 应收岗-团购统计表-本 日遗留)
业务口径:该 sheet 里所有形如 `[n]资金组取数!$B$xx` 的公式都属于「同源取数」,每行应按 A 列日期
指向**当天那份**财务共享总表(当前实测 4 列 × 62 行 = 248 个):
V = [n ]资金组取数!$B$5 应收岗-团购统计表-昨 日遗留
W = [n]资金组取数!$B$6 应收岗-团购统计表-本日遗留
Y = [n]资金组取数!$B$3
Z = [n]资金组取数!$B$4
外部文件:file:/// \\ \\ caiwu01 \\ 共享文件夹 \\ 1111 \\ TG \\ {YYYY} 年 {M} 月 \\ {M} . {D} \\ 马敏团购总表 {M} . {D} .xlsx
实现:能复用的链接按 target 匹配复用,缺的新增 externalLinkNN.xml + rels +
workbook.xml 的 externalReferences + workbook.xml.rels + Content_Types 声明;
目标 sheet 只改对应行的 V/W 单元格,其余部件原样拷贝 。
实现:**不写死列名**——扫描目标行里每个公式,凡含 `[n]资金组取数!` 就把其中的 [n] 换成该行日期
对应的编号(前置负号、单元格地址、公式其它部分原样保留;引用别的工作簿的 [n] 不动)。
已是目标编号的单元格原样保留(含缓存值),只改对不上的。缺的外部链接新增部件并五处同步 。
日期范围:不给区间就处理整表 A 列所有日期行(幂等),给了就只处理区间内。
共享盘不可达不阻塞:公式照写,Excel 打开点「更新链接」即可取值。
"""
import os
import re
@@ -20,6 +25,7 @@ from datetime import date, datetime, timedelta
from openpyxl import load_workbook
from . . import config
from . zipio import open_zip
_EXTLINK_TPL = (
' <?xml version= " 1.0 " encoding= " UTF-8 " standalone= " yes " ?> \r \n '
@@ -35,12 +41,15 @@ _EXTLINK_RELS_TPL = (
' relationships/externalLinkPath " Target= " %s " TargetMode= " External " /></Relationships> '
)
_CELL_RE = re . compile ( r ' <c r= " ([A-Z]+)( \ d+) " ([^>]*?)(?:/>|>(.*?)</c>) ' , re . S )
_F_RE = re . compile ( r ' <f([^>]*?)(?:/>|>(.*?)</f>) ' , re . S )
_ROW_RE = re . compile ( r ' <row r= " ( \ d+) " [^>]*?(?:/>|>.*?</row>) ' , re . S )
_EXT_REF = re . compile ( r ' \ [( \ d+) \ ] ' + re . escape ( config . LINK_SHEET ) + r ' ! ' )
def _pick_latest ( pattern ) :
def _pick_ledger ( ) :
import glob
files = [ p for p in glob . glob ( os . path . join ( config . WORK_DIR , pattern ) )
if ' 备份 ' not in os . path . basename ( p ) ]
files = [ p for p in glob . glob ( os . path . join ( config . WORK_DIR , config . LEDGER_GLOB ) )
if ' 备份 ' not in os . path . basename ( p ) and not p . endswith ( ' .tmp ' ) ]
if not files :
return None
files . sort ( key = os . path . getmtime )
@@ -57,6 +66,14 @@ def _file_uri(path):
return ' file:/// ' + path
def _norm_uri ( uri ) :
""" 外部链接目标归一化:去掉 file:/// 前缀、双反斜杠归一、小写(否则每次都新增重复链接)。 """
u = ( uri or ' ' ) . strip ( )
if u . lower ( ) . startswith ( ' file:/// ' ) :
u = u [ len ( ' file:/// ' ) : ]
return u . replace ( ' \\ \\ ' , ' \\ ' ) . lower ( )
def _sheet_xml_path ( zf , sheet_name ) :
import xml . etree . ElementTree as ET
main = ' { http://schemas.openxmlformats.org/spreadsheetml/2006/main} '
@@ -78,47 +95,8 @@ def _sheet_xml_path(zf, sheet_name):
return None
def _col_num ( letters ) :
n = 0
for ch in letters :
n = n * 26 + ( ord ( ch ) - 64 )
return n
def _set_row_cells ( row_xml , row_no , cells ) :
keep = [ ]
style_default = None
for m in _CELL_RE . finditer ( row_xml ) :
col = m . group ( 1 )
sm = re . search ( r ' \ bs= " ( \ d+) " ' , m . group ( 3 ) )
if style_default is None and sm :
style_default = sm . group ( 1 )
if col in cells :
continue
keep . append ( ( _col_num ( col ) , m . group ( 0 ) ) )
for col , ( formula , style ) in cells . items ( ) :
s = style or style_default
s_attr = f ' s= " { s } " ' if s else ' '
keep . append ( ( _col_num ( col ) , f ' <c r= " { col } { row_no } " { s_attr } ><f> { formula } </f></c> ' ) )
keep . sort ( key = lambda x : x [ 0 ] )
attrs = re . match ( r ' <row([^>]*)> ' , row_xml )
head = f ' <row { attrs . group ( 1 ) } > ' if attrs else f ' <row r= " { row_no } " > '
return f ' { head } { " " . join ( c for _ , c in keep ) } </row> '
def _norm_uri ( uri ) :
""" 外部链接目标归一化:`file:/// \\ \\ caiwu01 \\ 共享...` → ` \\ \\ caiwu01 \\ 共享...`(小写)。
比对方是本地路径,不带 file:/// 前缀;不归一会永远匹配不上,
导致每次运行都新增一条重复的外部链接。
"""
u = ( uri or ' ' ) . strip ( )
if u . lower ( ) . startswith ( ' file:/// ' ) :
u = u [ len ( ' file:/// ' ) : ]
return u . replace ( ' \\ \\ ' , ' \\ ' ) . lower ( )
def _parse_links ( zf ) :
""" 既有外部链接: { 归一化路径: 序号} + 最大序号。 """
mapping , max_n = { } , 0
for name in zf . namelist ( ) :
m = re . match ( r ' xl/externalLinks/_rels/externalLink( \ d+) \ .xml \ .rels$ ' , name )
@@ -129,108 +107,190 @@ def _parse_links(zf):
txt = zf . read ( name ) . decode ( ' utf-8 ' , ' replace ' )
tm = re . search ( r ' Target= " ([^ " ]+) " ' , txt )
if tm :
mapping . setdefault ( _norm_uri ( tm . group ( 1 ) ) , n ) # 同路径多条时保留最早那条
mapping . setdefault ( _norm_uri ( tm . group ( 1 ) ) , n )
return mapping , max_n
def _col_num ( letters ) :
n = 0
for ch in letters :
n = n * 26 + ( ord ( ch ) - 64 )
return n
def _set_row_cells ( row_xml , row_no , cells ) :
""" 用新单元格替换指定列(保留该列原有样式 s),行内其余单元格原样保留。 """
keep , styles = [ ] , { }
for m in _CELL_RE . finditer ( row_xml ) :
col = m . group ( 1 )
sm = re . search ( r ' \ bs= " ( \ d+) " ' , m . group ( 3 ) )
if sm :
styles . setdefault ( col , sm . group ( 1 ) )
if col in cells :
continue
keep . append ( ( _col_num ( col ) , m . group ( 0 ) ) )
for col , formula in cells . items ( ) :
s = styles . get ( col )
s_attr = f ' s= " { s } " ' if s else ' '
keep . append ( ( _col_num ( col ) , f ' <c r= " { col } { row_no } " { s_attr } ><f> { formula } </f></c> ' ) )
keep . sort ( key = lambda x : x [ 0 ] )
attrs = re . match ( r ' <row([^>]*)> ' , row_xml )
head = f ' <row { attrs . group ( 1 ) } > ' if attrs else f ' <row r= " { row_no } " > '
return f ' { head } { " " . join ( c for _ , c in keep ) } </row> '
def _same_src_formulas ( row_inner ) :
""" 该行里所有引用共享总表的公式 { 列: 公式文本}(共享公式引用无文本的跳过)。 """
out = { }
for c in _CELL_RE . finditer ( row_inner ) :
body = c . group ( 4 ) or ' '
fm = _F_RE . search ( body )
if not fm :
continue
text = fm . group ( 2 ) or ' '
if text and _EXT_REF . search ( text ) :
out [ c . group ( 1 ) ] = text
return out
def _date_rows ( ledger ) :
""" 读「新美大核对统计」A 列日期 → { date: 行号}。 """
wb = load_workbook ( ledger , read_only = True , data_only = False )
try :
if config . STAT_SHEET not in wb . sheetnames :
raise RuntimeError ( f ' 台账缺少 sheet「 { config . STAT_SHEET } 」 ' )
ws = wb [ config . STAT_SHEET ]
out = { }
for i , row in enumerate ( ws . iter_rows ( min_col = 1 , max_col = 1 , values_only = True ) , start = 1 ) :
v = row [ 0 ]
if isinstance ( v , datetime ) :
out [ v . date ( ) ] = i
elif isinstance ( v , date ) :
out [ v ] = i
return out
finally :
wb . close ( )
def run ( d_from = None , d_to = None , dry_run = False ) :
""" 按日期区间补 V/W。d_from/d_to 为空则取最新「团购收益明细_YYYYMMDD_YYYYMMDD.xlsx」的日期。 """
ledger = _pick_latest ( config . LEDGER_GLOB )
""" 按 A 列日期给「新美大核对统计」整行同源取数公式换链接编号。
d_from/d_to 为空 → 处理整表所有日期行;给了区间 → 只处理区间内的日期行。
"""
ledger = _pick_ledger ( )
if not ledger :
return { ' ok ' : False , ' message ' : f ' 未找到台账: { config . LEDGER_GLOB } ' }
config . log ( f ' 台账: { os . path . basename ( ledger ) } ' )
config . log ( f ' 台账: { os . path . basename ( ledger ) } ( { config . STAT_SHEET } ) ' )
if not d_from :
detail = _pick_latest ( config . DETAIL_GLOB )
if detail :
m = re . search ( r ' ( \ d {8} )_( \ d {8} ) ' , os . path . basename ( detail ) ) or \
re . search ( r ' ( \ d {8} ) ' , os . path . basename ( detail ) )
if m :
d_from = m . group ( 1 )
d_to = m . group ( 2 ) if m . lastindex and m . lastindex > = 2 else m . group ( 1 )
if not d_from :
today = date . today ( )
d_from = ( today - timedelta ( days = 1 ) ) . isoformat ( )
d_to = today . isoformat ( )
try :
rows_by_date = _date_rows ( ledger )
except RuntimeError as e :
return { ' ok ' : False , ' message ' : str ( e ) }
if not rows_by_date :
return { ' ok ' : False , ' message ' : f ' 「 { config . STAT_SHEET } 」A 列没有日期行 ' }
d1 = datetime . strptime ( d_from . replace ( ' - ' , ' ' ) [ : 8 ] , ' % Y % m %d ' ) . date ( )
d2 = datetime . strptime ( str ( d_to ) . replace ( ' - ' , ' ' ) [ : 8 ] , ' % Y % m %d ' ) . date ( )
config . log ( f ' 日期区间: { d1 } ~ { d2 } ' )
wb = load_workbook ( ledger , read_only = True , data_only = False )
if config . STAT_SHEET not in wb . sheetnames :
wb . close ( )
return { ' ok ' : False , ' message ' : f ' 台账缺少 sheet「 { config . STAT_SHEET } 」 ' }
ws = wb [ config . STAT_SHEET ]
date_rows = { }
for i , row in enumerate ( ws . iter_rows ( min_col = 1 , max_col = 1 , values_only = True ) , start = 1 ) :
v = row [ 0 ]
if isinstance ( v , datetime ) :
date_rows [ v . date ( ) ] = i
elif isinstance ( v , date ) :
date_rows [ v ] = i
wb . close ( )
days , day = [ ] , d1
while day < = d2 :
days . append ( day )
day + = timedelta ( days = 1 )
skipped = [ d for d in days if d not in date_rows ]
if skipped :
config . log ( f ' 核对统计表里没有这些日期行,跳过: { [ str ( d ) for d in skipped ] } ' , ' WARN ' )
days = [ d for d in days if d in date_rows ]
days = sorted ( rows_by_date )
if d_from or d_to :
d1 = datetime . strptime ( str ( d_from ) . replace ( ' - ' , ' ' ) [ : 8 ] , ' % Y % m %d ' ) . date ( ) if d_from else days [ 0 ]
d2 = datetime . strptime ( str ( d_to ) . replace ( ' - ' , ' ' ) [ : 8 ] , ' % Y % m %d ' ) . date ( ) if d_to else days [ - 1 ]
if d2 < d1 :
d1 , d2 = d2 , d1
skipped = [ x for x in days if not ( d1 < = x < = d2 ) ]
days = [ x for x in days if d1 < = x < = d2 ]
config . log ( f ' 日期区间 { d1 } ~ { d2 } :命中 { len ( days ) } 行,跳过 { len ( skipped ) } 行 ' )
if not days :
return { ' ok ' : False , ' message ' : ' 没有可处理的日期行 ' }
return { ' ok ' : True , ' rows ' : [ ] , ' new_links ' : 0 , ' ledger ' : ledger ,
' message ' : f ' 区间内没有 { config . STAT_SHEET } 日期行 ' }
config . log ( f ' 核对表 { len ( days ) } 个日期行: { days [ 0 ] } ~ { days [ - 1 ] } ' )
zf = zipfile . ZipFile ( ledger )
link_map , max_link = _parse_links ( zf )
config . log ( f ' 既有外部链接 { len ( link_map ) } 条,最大序号 { max_link } ' )
zf = open_zip ( ledger )
try :
link_map , max_link = _parse_links ( zf )
config . log ( f ' 既有外部链接 { len ( link_map ) } 条,最大序号 { max_link } ' )
sheet_path = _sheet_xml_path ( zf , config . STAT_SHEET )
if not sheet_path :
return { ' ok ' : False , ' message ' : f ' 找不到「 { config . STAT_SHEET } 」的 xml ' }
sheet_xml = zf . read ( sheet_path ) . decode ( ' utf-8 ' )
wb_xml = zf . read ( ' xl/workbook.xml ' ) . decode ( ' utf-8 ' )
wb_rels = zf . read ( ' xl/_rels/workbook.xml.rels ' ) . decode ( ' utf-8 ' )
ct_xml = zf . read ( ' [Content_Types].xml ' ) . decode ( ' utf-8 ' )
finally :
zf . close ( )
plan , need_new = [ ] , [ ]
row_spans = { }
for m in _ROW_RE . finditer ( sheet_xml ) :
row_spans [ int ( m . group ( 1 ) ) ] = m . group ( 0 )
plan , need_new , skipped , no_formula = [ ] , { } , 0 , 0
for d in days :
path = _target_path ( d )
if _norm_uri ( path ) in link_map :
plan . append ( ( d , date_rows [ d ] , link_map [ _norm_uri ( path ) ] , path , ' 复用 ' ) )
row_no = rows_by_date [ d ]
row_xml = row_spans . get ( row_no )
if row_xml is None :
config . log ( f ' { d } 第 { row_no } 行 XML 未找到,跳过 ' , ' WARN ' )
continue
srcs = _same_src_formulas ( row_xml )
if not srcs :
no_formula + = 1
continue
key = _norm_uri ( _target_path ( d ) )
have = link_map . get ( key )
if have is not None and all ( set ( _EXT_REF . findall ( f ) ) == { str ( have ) }
for f in srcs . values ( ) ) :
skipped + = 1
continue
if have is not None :
idx , mode = have , ' 复用 '
else :
idx = max_link + len ( need_new ) + 1
need_new . append ( ( idx , path , _file_uri ( path ) ) )
plan . append ( ( d , date_rows [ d ] , idx , path , ' 新增 ' ) )
if key not in need_new :
need_new [ key ] = ( max_link + len ( need_new ) + 1 , _target_path ( d ) )
idx , mode = need_new [ key ] [ 0 ] , ' 新增 '
todo = { }
for col , fml in srcs . items ( ) :
if set ( _EXT_REF . findall ( fml ) ) == { str ( idx ) } :
continue
todo [ col ] = _EXT_REF . sub ( f ' [ { idx } ] { config . LINK_SHEET } ! ' , fml )
if not todo :
skipped + = 1
continue
plan . append ( ( d , row_no , idx , _target_path ( d ) , mode , todo ) )
for d , row_no , idx , path , mode in plan :
config . log ( f ' { d } → 第 { row_no } 行 [ { idx } ]( { mode } ) { path } ' )
config . log ( f ' 需更新 { len ( plan ) } 行(已正确 { skipped } 行、无同源公式 { no_formula } 行), '
f ' 新增外部链接 { len ( need_new ) } 条 ' )
for d , row_no , idx , path , mode , todo in plan :
cols = ' , ' . join ( f ' { c } ( { f } ) ' for c , f in sorted ( todo . items ( ) ) )
config . log ( f ' { d } 第 { row_no } 行 → [ { idx } ]( { mode } ) { cols } { path } ' , ' DEBUG ' )
if not plan :
return { ' ok ' : True , ' rows ' : [ ] , ' new_links ' : 0 , ' ledger ' : ledger ,
' message ' : f ' { config . STAT_SHEET } 同源取数公式已是最新,无需改动 ' }
if dry_run :
zf . close ( )
return { ' ok ' : True , ' rows ' : [ p [ 1 ] for p in plan ] ,
' message ' : f ' [演练] { len ( plan ) } 行将更新 V/W ,需新增 { len ( need_new ) } 条外部链接 ' }
return { ' ok ' : True , ' rows ' : [ p [ 1 ] for p in plan ] , ' new_links ' : len ( need_new ) ,
' ledger ' : ledger ,
' message ' : f ' [演练] 将更新 { len ( plan ) } 行,需新增 { len ( need_new ) } 条外部链接 ' }
if not os . path . isdir ( config . SHARE_ROOT ) :
config . log ( f ' 共享盘当前不可达( { config . SHARE_ROOT } ),公式照写, '
f ' 恢复后打开 Excel 点「更新链接」即可取值 ' , ' WARN ' )
f ' 恢复到内网 后打开 Excel 点「更新链接」即可取值 ' , ' WARN ' )
sheet_path = _sheet_xml_path ( zf , config . STAT_SHEET )
if not sheet_path :
zf . close ( )
return { ' ok ' : False , ' message ' : f ' 找不到「 { config . STAT_SHEET } 」的 xml ' }
sheet_xml = zf . read ( sheet_path ) . decode ( ' utf-8 ' )
wb_xml = zf . read ( ' xl/workbook.xml ' ) . decode ( ' utf-8 ' )
wb_rels = zf . read ( ' xl/_rels/workbook.xml.rels ' ) . decode ( ' utf-8 ' )
ct_xml = zf . read ( ' [Content_Types].xml ' ) . decode ( ' utf-8 ' )
lock = os . path . join ( os . path . dirname ( ledger ) , ' ~$ ' + os . path . basename ( ledger ) )
if os . path . exists ( lock ) :
return { ' ok ' : False , ' message ' : ' 台账正在 Excel 中打开(检测到 ~$ 锁文件),请关闭后重跑 ' }
backup = os . path . join (
config . WORK_DIR ,
f ' { os . path . splitext ( os . path . basename ( ledger ) ) [ 0 ] } _核对备份 '
f ' { time . strftime ( " % Y % m %d _ % H % M % S " ) } .xlsx ' )
shutil . copy2 ( ledger , backup )
config . log ( f ' 已备份 → { os . path . basename ( backup ) } ' )
for d , row_no , idx , path , mode in plan :
m = re . search ( r ' <row r= " ' + str ( row_no ) + r ' " [^>]*>.*?</row> ' , sheet_xml , re . S )
if not m :
config . log ( f ' 第 { row_no } 行 XML 未找到,跳过 ' , ' WARN ' )
continue
# 注意:XML 的 <f> 里放公式正文,不带 Excel 界面上的前导 '='
new_row = _set_row_cells ( m . group ( 0 ) , row_no , {
' V ' : ( f ' [ { idx } ] { config . LINK_SHEET } !$B$5 ' , None ) ,
' W ' : ( f ' [ { idx } ] { config . LINK_SHEET } !$B$6 ' , None ) ,
} )
sheet_xml = sheet_xml [ : m . start ( ) ] + new_row + sheet_xml [ m . end ( ) : ]
config . log ( f ' { d } 行已补上团购统计表取数链接 ' )
spans = { }
for m in _ROW_RE . finditer ( sheet_xml ) :
spans [ int ( m . group ( 1 ) ) ] = ( m . start ( ) , m . end ( ) )
for d , row_no , idx , path , mode , todo in sorted ( plan , key = lambda p : - p [ 1 ] ) :
s , e = spans [ row_no ]
sheet_xml = sheet_xml [ : s ] + _set_row_cells ( sheet_xml [ s : e ] , row_no , todo ) + sheet_xml [ e : ]
for idx , path , uri in need_new :
for key , ( idx , path ) in need_new . items ( ) :
rid_num = max ( int ( x ) for x in re . findall ( r ' Id= " rId( \ d+) " ' , wb_rels ) ) + 1
rid = f ' rId { rid_num } '
wb_rels = wb_rels . replace (
@@ -246,7 +306,7 @@ def run(d_from=None, d_to=None, dry_run=False):
f ' ContentType= " application/vnd.openxmlformats-officedocument. '
f ' spreadsheetml.externalLink+xml " /></Types> ' )
tmp = ledger + ' .rebuild.tmp '
tmp = ledger + ' .links.tmp '
replace = {
sheet_path : sheet_xml . encode ( ' utf-8 ' ) ,
' xl/workbook.xml ' : wb_xml . encode ( ' utf-8 ' ) ,
@@ -254,29 +314,34 @@ def run(d_from=None, d_to=None, dry_run=False):
' [Content_Types].xml ' : ct_xml . encode ( ' utf-8 ' ) ,
}
new_files = { }
for idx , path , uri in need_new :
for key , ( idx , path ) in need_new . items ( ) :
new_files [ f ' xl/externalLinks/externalLink { idx } .xml ' ] = \
( _EXTLINK_TPL % config . LINK_SHEET ) . encode ( ' utf-8 ' )
new_files [ f ' xl/externalLinks/_rels/externalLink { idx } .xml.rels ' ] = \
( _EXTLINK_RELS_TPL % uri ) . encode ( ' utf-8 ' )
( _EXTLINK_RELS_TPL % _file_uri ( path ) ) . encode ( ' utf-8 ' )
with zipfile . ZipFile ( tmp , ' w ' , zipfile . ZIP_DEFLATED , allowZip64 = True ) as dst :
for info in zf . infolist ( ) :
if info . is_dir ( ) :
continue
zi = zipfile . ZipInfo ( info . filename , date_time = info . date_time )
zi . compress_type = zipfile . ZIP_DEFLATED
zi . external_attr = info . external_attr
if info . filename in replace :
dst . writestr ( zi , replace . pop ( info . filename ) )
else :
with zf . open ( info ) as fin , dst . open ( zi , ' w ' , force_zip64 = True ) as fout :
shutil . copyfileobj ( fin , fout , 4 << 20 )
for name , data in list ( replace . items ( ) ) + list ( new_files . items ( ) ) :
dst . writestr ( name , data )
zf . close ( )
zf = open_zip ( ledger )
try :
with zipfile . ZipFile ( tmp , ' w ' , zipfile . ZIP_DEFLATED , allowZip64 = True ) as dst :
for info in zf . infolist ( ) :
if info . is_dir ( ) :
continue
zi = zipfile . ZipInfo ( info . filename , date_time = info . date_time )
zi . compress_type = zipfile . ZIP_DEFLATED
zi . external_attr = info . external_attr
if info . filename in replace :
dst . writestr ( zi , replace . pop ( info . filename ) )
else :
with zf . open ( info ) as fin , dst . open ( zi , ' w ' , force_zip64 = True ) as fout :
shutil . copyfileobj ( fin , fout , 4 << 20 )
for name , data in list ( replace . items ( ) ) + list ( new_files . items ( ) ) :
dst . writestr ( name , data )
finally :
zf . close ( )
os . replace ( tmp , ledger )
config . log ( f ' 完成: { len ( plan ) } 行更新 V/W ,新增外部链接 { len ( need_new ) } 条 ' )
config . log ( f ' 完成: { len ( plan ) } 行同源公式已 更新,新增外部链接 { len ( need_new ) } 条 ' )
return { ' ok ' : True , ' rows ' : [ p [ 1 ] for p in plan ] , ' new_links ' : len ( need_new ) ,
' message ' : f ' 核对统计 V/W 已更新 { len ( plan ) } 行 ' }
' ledger ' : ledger ,
' message ' : f ' { config . STAT_SHEET } 同源取数公式已更新 { len ( plan ) } 行 '
f ' (新增外部链接 { len ( need_new ) } 条) ' }