1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| import json,hashlib
| from pathlib import Path
| import openpyxl
| P=Path(__file__).parent
| source=Path('D:/WechatRecord/xwechat_files/wxid_vmeut7wztkbp22_1546/temp/RWTemp/2026-10/c40afdcfa98e2b4561823e6babbefa33/2026年销售收入台账9.29(1).xlsx')
| book=openpyxl.load_workbook(source,data_only=True,read_only=False)
| formulas=openpyxl.load_workbook(source,data_only=False,read_only=False)
| s={'source':str(source),'sha256':hashlib.sha256(source.read_bytes()).hexdigest(),'sheets':{}}
| for sheet in book:
| rows=[{'row':i,'values':list(values)} for i,values in enumerate(sheet.values,1) if any(v is not None for v in values)]
| s['sheets'][sheet.title]={'max_row':sheet.max_row,'max_column':sheet.max_column,'merged_ranges':[str(r) for r in sheet.merged_cells.ranges],
| 'rows':rows,'formulas':[{'cell':c.coordinate,'formula':c.value,'cached':sheet[c.coordinate].value} for row in formulas[sheet.title] for c in row if c.data_type=='f']}
| print(sheet.title,sheet.max_row,sheet.max_column,'nonempty',len(rows),'formulas',len(s['sheets'][sheet.title]['formulas']))
| print(json.dumps(rows[:7],ensure_ascii=False,default=str))
| (P/'ledger-extracted.json').write_text(json.dumps(s,ensure_ascii=False,default=str,indent=2),encoding='utf8')
|
|