Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -302,56 +302,35 @@ def drop_missing_rows(df, columns):
|
|
| 302 |
# workbook.remove(workbook["Sheet"])
|
| 303 |
# workbook.save('Log.xlsx')
|
| 304 |
|
| 305 |
-
import openpyxl
|
| 306 |
-
from openpyxl.styles import Font, PatternFill
|
| 307 |
-
|
| 308 |
def write_log(sheet_data_dict):
|
| 309 |
workbook = openpyxl.Workbook()
|
|
|
|
| 310 |
for sheet_name, data_dict in sheet_data_dict.items():
|
| 311 |
-
|
| 312 |
sheet = workbook.create_sheet(title=sheet_name)
|
|
|
|
| 313 |
for title, data in data_dict.items():
|
| 314 |
# Write the title
|
| 315 |
sheet.append([title])
|
| 316 |
title_cell = sheet.cell(row=sheet.max_row, column=1)
|
| 317 |
title_cell.font = Font(size=14, bold=True) # Set the font size and bold
|
| 318 |
-
|
| 319 |
-
# Write the list values
|
| 320 |
-
lst = data[0]
|
| 321 |
|
| 322 |
-
|
| 323 |
-
if len(data) > 1
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
if isinstance(sub_list, list):
|
| 329 |
-
sheet.append(sub_list) # If sub_list is list, append as it is
|
| 330 |
-
else:
|
| 331 |
-
sheet.append([sub_list]) # If sub_list is a string, wrap it in a list
|
| 332 |
-
|
| 333 |
-
# Fill color if provided
|
| 334 |
-
if color:
|
| 335 |
-
fill = PatternFill(start_color=color, end_color=color, fill_type="solid")
|
| 336 |
-
row_to_color = sheet[sheet.max_row]
|
| 337 |
-
for cell in row_to_color:
|
| 338 |
-
cell.fill = fill
|
| 339 |
-
else:
|
| 340 |
-
sheet.append(lst) # If lst[0] is not a list, write lst in a new row as before
|
| 341 |
-
|
| 342 |
-
# Fill color if provided
|
| 343 |
if color:
|
| 344 |
fill = PatternFill(start_color=color, end_color=color, fill_type="solid")
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
# Remove the default sheet created and save the workbook
|
| 350 |
if workbook.active.title == "Sheet":
|
| 351 |
workbook.remove(workbook.active)
|
|
|
|
| 352 |
workbook.save('Log.xlsx')
|
| 353 |
|
| 354 |
-
|
| 355 |
warnings = []
|
| 356 |
def is_found(c,text):
|
| 357 |
global warnings
|
|
|
|
| 302 |
# workbook.remove(workbook["Sheet"])
|
| 303 |
# workbook.save('Log.xlsx')
|
| 304 |
|
|
|
|
|
|
|
|
|
|
| 305 |
def write_log(sheet_data_dict):
|
| 306 |
workbook = openpyxl.Workbook()
|
| 307 |
+
|
| 308 |
for sheet_name, data_dict in sheet_data_dict.items():
|
|
|
|
| 309 |
sheet = workbook.create_sheet(title=sheet_name)
|
| 310 |
+
|
| 311 |
for title, data in data_dict.items():
|
| 312 |
# Write the title
|
| 313 |
sheet.append([title])
|
| 314 |
title_cell = sheet.cell(row=sheet.max_row, column=1)
|
| 315 |
title_cell.font = Font(size=14, bold=True) # Set the font size and bold
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
+
# Extract the list values and color
|
| 318 |
+
lst, color = data[0], data[1] if len(data) > 1 else None
|
| 319 |
+
|
| 320 |
+
# Write each item of the list in a new row and apply the color if provided
|
| 321 |
+
for item in lst:
|
| 322 |
+
sheet.append([item])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
if color:
|
| 324 |
fill = PatternFill(start_color=color, end_color=color, fill_type="solid")
|
| 325 |
+
cell = sheet.cell(row=sheet.max_row, column=1)
|
| 326 |
+
cell.fill = fill
|
| 327 |
+
|
|
|
|
| 328 |
# Remove the default sheet created and save the workbook
|
| 329 |
if workbook.active.title == "Sheet":
|
| 330 |
workbook.remove(workbook.active)
|
| 331 |
+
|
| 332 |
workbook.save('Log.xlsx')
|
| 333 |
|
|
|
|
| 334 |
warnings = []
|
| 335 |
def is_found(c,text):
|
| 336 |
global warnings
|