hariqueen commited on
Commit
a0a2c64
Β·
verified Β·
1 Parent(s): b6d08ac

update xls

Browse files
Files changed (1) hide show
  1. main.py +24 -5
main.py CHANGED
@@ -11,6 +11,8 @@ import erp_generator
11
  import file_handler
12
  import reporter
13
  import pandas as pd
 
 
14
 
15
 
16
  def process_rental_company(company_name: str):
@@ -82,17 +84,34 @@ def process_rental_company_with_voucher(uploaded_file_path, voucher_number):
82
 
83
  os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
84
 
85
- # 이제 μ€€λΉ„λœ result_dfλ₯Ό Excel 97-2003 ν˜•μ‹(.xls)으둜 μ €μž₯
86
  try:
87
- result_df.to_excel(output_path, index=False, engine='xlwt')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  print(f"Excel 97-2003 ν˜•μ‹(.xls)으둜 파일 μ €μž₯ μ™„λ£Œ: {output_path}")
89
  except Exception as e:
90
- print(f"μ—‘μ…€ 파일 μ €μž₯ 쀑 였λ₯˜ λ°œμƒ: {e}")
91
- # 였λ₯˜ λ°œμƒ μ‹œ λ°±μ—…μœΌλ‘œ xlsx ν˜•μ‹ μ €μž₯ μ‹œλ„
92
  backup_path = output_path.replace('.xls', '.xlsx')
93
  result_df.to_excel(backup_path, index=False, engine='openpyxl')
94
- print(f"λŒ€μ²΄ ν˜•μ‹(.xlsx)으둜 파일 μ €μž₯ μ™„λ£Œ: {backup_path}")
95
  output_path = backup_path
 
96
 
97
  return output_path
98
 
 
11
  import file_handler
12
  import reporter
13
  import pandas as pd
14
+ from pyexcel_xls import save_data
15
+ from collections import OrderedDict
16
 
17
 
18
  def process_rental_company(company_name: str):
 
84
 
85
  os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
86
 
 
87
  try:
88
+ # pyexcel_xls와 OrderedDict λͺ¨λ“ˆ μž„ν¬νŠΈ
89
+ from pyexcel_xls import save_data
90
+ from collections import OrderedDict
91
+
92
+ # λ°μ΄ν„°ν”„λ ˆμž„μ„ 리슀트둜 λ³€ν™˜
93
+ headers = result_df.columns.tolist()
94
+ data = [headers] # 헀더λ₯Ό 첫 번째 ν–‰μœΌλ‘œ μΆ”κ°€
95
+
96
+ # λ°μ΄ν„°ν”„λ ˆμž„μ˜ 각 행을 리슀트둜 λ³€ν™˜ν•˜μ—¬ data에 μΆ”κ°€
97
+ for _, row in result_df.iterrows():
98
+ data.append(row.tolist())
99
+
100
+ # OrderedDict 생성 (Sheet1μ΄λΌλŠ” μ΄λ¦„μ˜ μ‹œνŠΈμ— 데이터 μ €μž₯)
101
+ data_dict = OrderedDict()
102
+ data_dict["Sheet1"] = data
103
+
104
+ # xls 파일둜 μ €μž₯
105
+ save_data(output_path, data_dict)
106
+
107
  print(f"Excel 97-2003 ν˜•μ‹(.xls)으둜 파일 μ €μž₯ μ™„λ£Œ: {output_path}")
108
  except Exception as e:
109
+ print(f"Excel 97-2003 ν˜•μ‹ μ €μž₯ 쀑 였λ₯˜ λ°œμƒ: {e}")
110
+ # 였λ₯˜ λ°œμƒ μ‹œ κΈ°μ‘΄ λ°©μ‹μœΌλ‘œ μ €μž₯
111
  backup_path = output_path.replace('.xls', '.xlsx')
112
  result_df.to_excel(backup_path, index=False, engine='openpyxl')
 
113
  output_path = backup_path
114
+ print(f"λŒ€μ²΄ ν˜•μ‹(.xlsx)으둜 파일 μ €μž₯ μ™„λ£Œ: {output_path}")
115
 
116
  return output_path
117