bugfixes
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ wheels/
|
|||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.lnk
|
*.lnk
|
||||||
|
src/xlsx_clean/temp_workbook.xlsx
|
||||||
|
|||||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.analysis.typeCheckingMode": "basic"
|
||||||
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import os
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import shutil
|
||||||
|
|
||||||
import pandas
|
import pandas
|
||||||
from beaupy import prompt, select
|
from beaupy import prompt, select
|
||||||
|
|
||||||
# from openpyxl import load_workbook
|
# from openpyxl import load_workbook
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
import win32com.client as win32
|
import win32com.client as win32
|
||||||
|
|
||||||
excel = win32.gencache.EnsureDispatch('Excel.Application')
|
excel = win32.gencache.EnsureDispatch("Excel.Application")
|
||||||
|
excel.Visible = True
|
||||||
# import questionary
|
# import questionary
|
||||||
|
|
||||||
|
|
||||||
@@ -71,14 +73,18 @@ def find_last_workbook(files):
|
|||||||
|
|
||||||
def get_workbook_names(files, batch_serial):
|
def get_workbook_names(files, batch_serial):
|
||||||
last_workbook = find_last_workbook(files)
|
last_workbook = find_last_workbook(files)
|
||||||
return last_workbook, path_ / pattern.replace("[SERIAL]", batch_serial.split("/")[0])
|
return last_workbook, path_ / pattern.replace(
|
||||||
|
"[SERIAL]", batch_serial.split("/")[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
ref_workbook_name, new_workbook_name = get_workbook_names(files, batch_serial)
|
ref_workbook_name, new_workbook_name = get_workbook_names(files, batch_serial)
|
||||||
# Selected Excel file
|
# Selected Excel file
|
||||||
console.print(f"Selected: {pathlib.Path(ref_workbook_name).stem}")
|
console.print(f"Selected: {pathlib.Path(ref_workbook_name).stem}")
|
||||||
# workbook = load_workbook(ref_workbook_name)
|
# workbook = load_workbook(ref_workbook_name)
|
||||||
workbook = excel.Workbooks.Open(ref_workbook_name)
|
temp_workbook = str(pathlib.Path.cwd() / "temp_workbook.xlsx")
|
||||||
|
shutil.copyfile(ref_workbook_name, temp_workbook)
|
||||||
|
workbook = excel.Workbooks.Open(temp_workbook)
|
||||||
cells_to_clear = path_df[
|
cells_to_clear = path_df[
|
||||||
(path_df["set_name"] == selected_set) & (path_df["dir"].str.endswith(selected_dir))
|
(path_df["set_name"] == selected_set) & (path_df["dir"].str.endswith(selected_dir))
|
||||||
]["cells_to_clear"].iloc[0]
|
]["cells_to_clear"].iloc[0]
|
||||||
@@ -99,9 +105,7 @@ for workbook_data in serial_cell.split(","):
|
|||||||
cell_range.Value = batch_serial
|
cell_range.Value = batch_serial
|
||||||
if not new_workbook_name.is_file():
|
if not new_workbook_name.is_file():
|
||||||
workbook.SaveAs(str(new_workbook_name))
|
workbook.SaveAs(str(new_workbook_name))
|
||||||
excel.Application.Quit()
|
excel.WindowState = win32.constants.xlMaximized
|
||||||
if os.name == "nt":
|
# excel.Application.Quit()
|
||||||
os.system(f"start excel.exe \"{new_workbook_name}\"")
|
# if os.name == "nt":
|
||||||
else:
|
# os.system(f"start excel.exe \"{new_workbook_name}\"")
|
||||||
console.print("Error: File already exists.")
|
|
||||||
os.system(f"start excel.exe \"{new_workbook_name}\"")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user