leadingbridge commited on
Commit
2f518f0
·
verified ·
1 Parent(s): f91c350

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -1,4 +1,3 @@
1
- ###ORDER###
2
  import gradio as gr
3
  import pandas as pd
4
  from datetime import datetime
@@ -47,6 +46,25 @@ def order_csv(file, supplier, order_number):
47
 
48
  # Save filtered DataFrame as Excel file
49
  download_df.to_excel(output_file, index=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  return df, output_file
51
 
52
  # Define the main block for the interface
@@ -77,4 +95,4 @@ with gr.Blocks() as demo:
77
  )
78
 
79
  # Run the interface
80
- demo.launch()
 
 
1
  import gradio as gr
2
  import pandas as pd
3
  from datetime import datetime
 
46
 
47
  # Save filtered DataFrame as Excel file
48
  download_df.to_excel(output_file, index=False)
49
+
50
+ # Adjust column widths using openpyxl
51
+ from openpyxl import load_workbook
52
+ wb = load_workbook(output_file)
53
+ ws = wb.active
54
+
55
+ for column_cells in ws.columns:
56
+ max_length = 0
57
+ # Get the column letter (e.g. 'A', 'B', etc.)
58
+ column_letter = column_cells[0].column_letter
59
+ for cell in column_cells:
60
+ if cell.value is not None:
61
+ cell_length = len(str(cell.value))
62
+ if cell_length > max_length:
63
+ max_length = cell_length
64
+ adjusted_width = max_length + 2 # Add a little extra space
65
+ ws.column_dimensions[column_letter].width = adjusted_width
66
+
67
+ wb.save(output_file)
68
  return df, output_file
69
 
70
  # Define the main block for the interface
 
95
  )
96
 
97
  # Run the interface
98
+ demo.launch()