Fixed on windows

This commit is contained in:
diaco soltanpour
2024-04-14 14:20:24 +03:30
parent bc4da930ff
commit 73326b86d0
4 changed files with 16 additions and 11 deletions

3
.gitignore vendored
View File

@@ -9,4 +9,5 @@ wheels/
# venv
.venv
.DS_Store
.DS_Store
*.lnk

View File

@@ -11,7 +11,7 @@ from rich.console import Console
NEW_VALUE = ""
# load questions from text file
with open("src/xlsx_clean/strings.txt") as f:
with open("strings.txt") as f:
content = f.readlines()
# remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content]
@@ -19,7 +19,7 @@ q1 = content[0]
q2 = content[1]
q3 = content[2]
path_df = pandas.read_csv("src/xlsx_clean/file_data.csv")
path_df = pandas.read_csv("file_data.csv")
path_df["set_dir"] = [pathlib.Path(path).parent.parent for path in path_df["dir"]]
path_list = [pathlib.Path(path) for path in path_df["dir"]]
parent_path = list(
@@ -69,7 +69,7 @@ def find_last_workbook(files):
def get_workbook_names(files, batch_serial):
last_workbook = find_last_workbook(files)
return last_workbook, path_ / pattern.replace("[SERIAL]", batch_serial)
return last_workbook, path_ / pattern.replace("[SERIAL]", batch_serial.split("/")[0])
ref_workbook_name, new_workbook_name = get_workbook_names(files, batch_serial)
@@ -86,9 +86,10 @@ for workbook_data in cells_to_clear.split(","):
if is_range:
cell_range = worksheet[worksheet_data[1]]
# Assign singular value to all cells
for cell in cell_range:
# Writes a new value PRESERVING cell styles.
cell[0].value = NEW_VALUE
for cell_row in cell_range:
for cell in cell_row:
# Writes a new value PRESERVING cell styles.
cell.value = NEW_VALUE
else:
worksheet[worksheet_data[1]].value = NEW_VALUE
@@ -102,6 +103,6 @@ for workbook_data in serial_cell.split(","):
if not new_workbook_name.is_file():
workbook.save(new_workbook_name)
if os.name == "nt":
os.system("start excel.exe new_workbook_name")
os.system(f"start excel.exe \"{new_workbook_name}\"")
else:
console.print("Error: File already exists.")

View File

@@ -1,4 +1,6 @@
dir,pattern,set_name,cells_to_clear,serial_cell
"/Users/diaco/Downloads/inco/Quality control data sheet/2024/ICJ407 Brown",ICJ_407 op. [SERIAL].xlsx","inco",""
"/Users/diaco/Downloads/Kimia Razi/1403/KRBR1200T Brown","ICJ308[SERIAL].xlsx","Kimia Razi","Milling!C3,Milling!C10:C12,Milling!C15,Milling!F8:J8,Milling!F11:J12,Batch!C14,Batch!C18:C19,Batch!G11,Batch!G14,Batch!G18,Batch!I11,Batch!I14,Batch!I18,Batch!K11:M11,Batch!K14:M14,Batch!K18:M18,Batch!B20,'KW & Temp'!A8:I8","Batch!C2"
"/Users/diaco/Downloads/Kimia Razi/1403/KRCY1100T Blue","KRCY1100T Blue S. [SERIAL].xlsx","Kimia Razi","Milling!C3,Milling!C10:C12,Milling!C15,Milling!F8:J8,Milling!F11:J12,Batch!C14,Batch!C18:C19,Batch!G11,Batch!G14,Batch!G18,Batch!I11,Batch!I14,Batch!I18,Batch!K11:M11,Batch!K14:M14,Batch!K18:M18,Batch!B20,'KW & Temp'!A8:I8","Batch!C2"
"D:\Kimia Razi\Production\QC Datasheet\1403\KRCY1100T Blue","KRCY1100T Blue [SERIAL].xlsx","Kimia Razi","Batch!C14,Batch!C18:C19,Batch!B20,Batch!C3,Batch!G11,Batch!G14,Batch!G18,Batch!I11,Batch!I14,Batch!I18,Batch!K11:M11,Batch!K14:M14,Batch!K18:M18,Batch!B20,Milling!F8:J8,Milling!F11:J12,Milling!F15:J15,Milling!C15,Milling!C12,Milling!C11,'KW & Temp'!A8:G8,'KW & Temp'!I8","Batch!C2"
"D:\Kimia Razi\Production\QC Datasheet\1403\KRBK1300T Black","KRBK1300T Black [SERIAL].xlsx","Kimia Razi","Batch!C14,Batch!C18:C19,Batch!B20,Batch!C3,Batch!G11,Batch!G14,Batch!G18,Batch!I11,Batch!I14,Batch!I18,Batch!K11:M11,Batch!K14:M14,Batch!K18:M18,Batch!B20,Milling!F8:J8,Milling!F11:J12,Milling!F15:J15,Milling!C15,Milling!C12,Milling!C11,'KW & Temp'!A8:G8,'KW & Temp'!I8","Batch!C2"
"D:\Kimia Razi\Production\QC Datasheet\1403\KRBR1200T Brown","KRBR1200T Brown [SERIAL].xlsx","Kimia Razi","Batch!C14,Batch!C18:C19,Batch!B20,Batch!C3,Batch!G11,Batch!G14,Batch!G18,Batch!I11,Batch!I14,Batch!I18,Batch!K11:M11,Batch!K14:M14,Batch!K18:M18,Batch!B20,Milling!F8:J8,Milling!F11:J12,Milling!F15:J15,Milling!C15,Milling!C12,Milling!C11,'KW & Temp'!A8:G8,'KW & Temp'!I8","Batch!C2"
"D:\Kimia Razi\Production\QC Datasheet\1403\KRYL1400T Yellow","KRYL1400T Yellow [SERIAL].xlsx","Kimia Razi","Batch!G14,Batch!G11,Batch!I11,Batch!I14,Batch!I20,Batch!G20,Batch!K11:M11,Batch!K14:M14,Batch!K20:M20,Batch!C14,Batch!C20:C21,Batch!C3,Batch!B22,'KW & Temp'!A8:G8,'KW & Temp'!I8,Milling!F8:J8,Milling!F10:J11,Milling!F14:J14,Milling!C14,Milling!C11","Batch!C2"
"D:\inco\Quality control data sheet\2024\ICJ108 Beige",ICJ_108 op. [SERIAL].xlsx","inco","Batch!C15:C18,Batch!C20:C21,Batch!C3,Batch!H9,Batch!H12,Batch!H20,Batch!J9:K9,Batch!J12:K12,Batch!J20:K20,Milling!D8,Milling!C9:C11,Milling!C15,Milling!F8:J11,Milling!F15:J15","Batch!C2"
Can't render this file because it contains an unexpected character in line 2 and column 101.

View File

@@ -0,0 +1 @@
python .\clean_cells.py