diff --git a/.gitignore b/.gitignore index de84547..bec8137 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ wheels/ # venv .venv -.DS_Store \ No newline at end of file +.DS_Store +*.lnk \ No newline at end of file diff --git a/src/xlsx_clean/clean_cells.py b/src/xlsx_clean/clean_cells.py index e2f6c16..17485b5 100644 --- a/src/xlsx_clean/clean_cells.py +++ b/src/xlsx_clean/clean_cells.py @@ -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.") diff --git a/src/xlsx_clean/file_data.csv b/src/xlsx_clean/file_data.csv index 0208ea4..b9dec10 100644 --- a/src/xlsx_clean/file_data.csv +++ b/src/xlsx_clean/file_data.csv @@ -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" \ No newline at end of file +"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" diff --git a/src/xlsx_clean/new_xslx.bat b/src/xlsx_clean/new_xslx.bat new file mode 100644 index 0000000..7776494 --- /dev/null +++ b/src/xlsx_clean/new_xslx.bat @@ -0,0 +1 @@ +python .\clean_cells.py \ No newline at end of file