改为使用 csv
This commit is contained in:
parent
8b6d5a75b9
commit
20fd5d19f6
38
脚本/开票.py
38
脚本/开票.py
@ -1,35 +1,23 @@
|
|||||||
from openpyxl import load_workbook
|
import csv
|
||||||
from openpyxl.styles.fills import PatternFill
|
|
||||||
|
|
||||||
EXCEL_PATH = r'd:\Cheney\geely-kaipiao\doc\2025-2026团队结算进度.xlsx'
|
EXCEL_PATH = r'd:\Cheney\geely-kaipiao\doc\2025-2026团队结算进度.csv'
|
||||||
|
|
||||||
|
|
||||||
def read_team_column() -> list:
|
def read_team_column() -> list:
|
||||||
|
team_list = []
|
||||||
try:
|
try:
|
||||||
wb = load_workbook(EXCEL_PATH, read_only=True)
|
with open(EXCEL_PATH, 'r', encoding='utf-8-sig') as f:
|
||||||
ws = wb.active
|
reader = csv.DictReader(f)
|
||||||
team_list = []
|
for row in reader:
|
||||||
|
team_value = row.get('团号', '')
|
||||||
header_row = 1
|
if team_value and isinstance(team_value, str) and team_value.lower().startswith('team'):
|
||||||
team_col_index = None
|
team_list.append(team_value)
|
||||||
|
|
||||||
for col in range(1, ws.max_column + 1):
|
|
||||||
cell_value = ws.cell(row=header_row, column=col).value
|
|
||||||
if cell_value == '团号':
|
|
||||||
team_col_index = col
|
|
||||||
break
|
|
||||||
|
|
||||||
if team_col_index is None:
|
|
||||||
return team_list
|
|
||||||
|
|
||||||
for row in range(2, ws.max_row + 1):
|
|
||||||
cell_value = ws.cell(row=row, column=team_col_index).value
|
|
||||||
if cell_value and isinstance(cell_value, str) and cell_value.lower().startswith('team'):
|
|
||||||
team_list.append(cell_value)
|
|
||||||
|
|
||||||
return team_list
|
return team_list
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"错误:文件 {EXCEL_PATH} 未找到")
|
||||||
|
return []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"读取Excel时出错: {e}")
|
print(f"读取文件时出错: {e}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user