-removed write_headers parameter (#4)

-write_data_to_excel is now context aware and checks for headers
-fixed issue where headers were duplicated when appending data
This commit is contained in:
Haris
2025-03-19 10:22:13 -07:00
committed by GitHub
parent 9d1ecb601d
commit a4bb6a921f
3 changed files with 129 additions and 30 deletions

View File

@ -208,12 +208,18 @@ def write_data_to_excel(
sheet_name: str,
data: List[Dict],
start_cell: str = "A1",
write_headers: bool = True,
) -> str:
"""Write data to Excel worksheet."""
"""Write data to Excel worksheet.
The function automatically detects the context and handles headers intelligently:
- Headers are added when writing to a new area
- Headers are not duplicated when writing below existing headers
- Title areas (rows 1-4) are treated specially
- If the first row of data appears to be headers, it will be used accordingly
"""
try:
full_path = get_excel_path(filepath)
result = write_data(full_path, sheet_name, data, start_cell, write_headers)
result = write_data(full_path, sheet_name, data, start_cell)
return result["message"]
except (ValidationError, DataError) as e:
return f"Error: {str(e)}"