geely-kaipiao/脚本/开票.py
2026-05-24 16:43:25 +08:00

48 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import csv
import argparse
EXCEL_PATH = r'd:\Cheney\geely-kaipiao\doc\2025-2026团队结算进度.csv'
def read_team_column(start_team: str = None) -> list:
team_list = []
try:
with open(EXCEL_PATH, 'r', encoding='utf-8-sig') as f:
reader = csv.DictReader(f)
for row in reader:
team_value = row.get('团号', '')
if team_value and isinstance(team_value, str) and team_value.lower().startswith('team'):
team_list.append(team_value)
if start_team and team_list:
lower_start = start_team.lower()
for i, team in enumerate(team_list):
if team.lower() == lower_start:
return team_list[i:]
print(f"警告:未找到团队 '{start_team}',返回全部团队")
return team_list
except FileNotFoundError:
print(f"错误:文件 {EXCEL_PATH} 未找到")
return []
except Exception as e:
print(f"读取文件时出错: {e}")
return []
def print_list_summary(data: list):
total = len(data)
if total <= 6:
print(f"{total} 个团队: {data}")
else:
print(f"{total} 个团队: {data[:3]} ... {data[-3:]}")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='读取CSV文件中的团号列')
parser.add_argument('-s', '--start', type=str, help='从指定的team开始返回不包含之前的team')
args = parser.parse_args()
result = read_team_column(args.start)
print_list_summary(result)