XPMaster commited on
Commit
b50b758
·
1 Parent(s): 7330837

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -2
app.py CHANGED
@@ -302,6 +302,36 @@ def drop_missing_rows(df, columns):
302
  # workbook.remove(workbook["Sheet"])
303
  # workbook.save('Log.xlsx')
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  def write_log(sheet_data_dict):
306
  workbook = openpyxl.Workbook()
307
 
@@ -313,7 +343,7 @@ def write_log(sheet_data_dict):
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 = data[0] # Extract the list of items to write
319
  color = data[1] if len(data) > 1 else None # Extract the color if it exists
@@ -325,6 +355,19 @@ def write_log(sheet_data_dict):
325
  fill = PatternFill(start_color=color, end_color=color, fill_type="solid")
326
  cell = sheet.cell(row=sheet.max_row, column=1)
327
  cell.fill = fill
 
 
 
 
 
 
 
 
 
 
 
 
 
328
 
329
  # Remove the default sheet created and save the workbook
330
  if "Sheet" in workbook.sheetnames:
@@ -568,7 +611,7 @@ def process(files,button):
568
  if len(warnings) > 0:
569
  sheetwarnings = [warnings,'FFA500']
570
  sheet_data[name] = {
571
- "Before columns": [old_olds],
572
  "After columns": [columns, '00FF00'],
573
  'Filled quarters':[filled_warn],
574
  "Warnings": sheetwarnings
 
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 = data[0] # Extract the list of items to write
319
+ # color = data[1] if len(data) > 1 else None # Extract the color if it exists
320
+
321
+ # # Write each item of the list in a new row and apply the color if provided
322
+ # for item in lst:
323
+ # sheet.append([item]) # Write item in a new row
324
+ # if color: # If color is provided, apply it to the row
325
+ # fill = PatternFill(start_color=color, end_color=color, fill_type="solid")
326
+ # cell = sheet.cell(row=sheet.max_row, column=1)
327
+ # cell.fill = fill
328
+
329
+ # # Remove the default sheet created and save the workbook
330
+ # if "Sheet" in workbook.sheetnames:
331
+ # workbook.remove(workbook["Sheet"])
332
+
333
+ # workbook.save('Log.xlsx')
334
+
335
  def write_log(sheet_data_dict):
336
  workbook = openpyxl.Workbook()
337
 
 
343
  sheet.append([title])
344
  title_cell = sheet.cell(row=sheet.max_row, column=1)
345
  title_cell.font = Font(size=14, bold=True) # Set the font size and bold
346
+
347
  # Extract the list values and color
348
  lst = data[0] # Extract the list of items to write
349
  color = data[1] if len(data) > 1 else None # Extract the color if it exists
 
355
  fill = PatternFill(start_color=color, end_color=color, fill_type="solid")
356
  cell = sheet.cell(row=sheet.max_row, column=1)
357
  cell.fill = fill
358
+
359
+ # Adjust the column width
360
+ for column in sheet.columns:
361
+ max_length = 0
362
+ column = [cell for cell in column]
363
+ for cell in column:
364
+ try: # Necessary to avoid error on empty cells
365
+ if len(str(cell.value)) > max_length:
366
+ max_length = len(cell.value)
367
+ except:
368
+ pass
369
+ adjusted_width = (max_length + 2)
370
+ sheet.column_dimensions[column[0].column_letter].width = adjusted_width
371
 
372
  # Remove the default sheet created and save the workbook
373
  if "Sheet" in workbook.sheetnames:
 
611
  if len(warnings) > 0:
612
  sheetwarnings = [warnings,'FFA500']
613
  sheet_data[name] = {
614
+ "Before columns": [old_olds,'FFDA29'],
615
  "After columns": [columns, '00FF00'],
616
  'Filled quarters':[filled_warn],
617
  "Warnings": sheetwarnings