Spaces:
Sleeping
Sleeping
update xls
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
print(f"Excel 97-2003 νμ(.xls)μΌλ‘ νμΌ μ μ₯ μλ£: {output_path}")
|
| 89 |
except Exception as e:
|
| 90 |
-
print(f"
|
| 91 |
-
# μ€λ₯ λ°μ μ
|
| 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 |
|