1.排程管理支持主表单元格合并,明细表显示
2.企业微信userid改为下拉框显示姓名+工号
This commit is contained in:
1 parent
05913f742f
commit
7d046862f7
5 files changed
+325
-13
No files matched your search
@@ -80,7 +80,16 @@ def export_schedule_result_excel(
|
||||
if not headers:
|
||||
return None, None, 0
|
||||
|
||||
rows: list[dict[str, Any]] = []
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "result"
|
||||
ws.append([header_labels.get(k, k) for k in headers])
|
||||
|
||||
detail_key_set = set(all_detail_headers)
|
||||
merge_keys = [k for k in headers if k not in detail_key_set]
|
||||
col_index_map = {k: idx + 1 for idx, k in enumerate(headers)}
|
||||
|
||||
current_excel_row = 2 # header is row 1
|
||||
for row in details:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
@@ -98,23 +107,30 @@ def export_schedule_result_excel(
|
||||
base_row[key] = _flatten_value(v)
|
||||
|
||||
detail_rows = row.get("_detail_rows")
|
||||
group_rows: list[dict[str, Any]] = []
|
||||
if all_detail_headers and isinstance(detail_rows, list) and detail_rows:
|
||||
for dr in detail_rows:
|
||||
flat = dict(base_row)
|
||||
if isinstance(dr, dict):
|
||||
for dk in all_detail_headers:
|
||||
flat[dk] = dr.get(dk, "")
|
||||
rows.append(flat)
|
||||
group_rows.append(flat)
|
||||
else:
|
||||
rows.append(base_row)
|
||||
group_rows.append(base_row)
|
||||
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "result"
|
||||
ws.append([header_labels.get(k, k) for k in headers])
|
||||
for out_row in group_rows:
|
||||
ws.append([out_row.get(k, "") for k in headers])
|
||||
|
||||
for row in rows:
|
||||
ws.append([row.get(k, "") for k in headers])
|
||||
group_size = len(group_rows)
|
||||
if group_size > 1:
|
||||
start_row = current_excel_row
|
||||
end_row = current_excel_row + group_size - 1
|
||||
for key in merge_keys:
|
||||
col = col_index_map.get(key)
|
||||
if not col:
|
||||
continue
|
||||
ws.merge_cells(start_row=start_row, start_column=col, end_row=end_row, end_column=col)
|
||||
current_excel_row += group_size
|
||||
|
||||
buf = io.BytesIO()
|
||||
wb.save(buf)
|
||||
|
||||
Reference in new issue
Block a user