diff --git a/.~lock.LogAB(20).joined.csv# b/.~lock.LogAB(20).joined.csv# new file mode 100644 index 0000000..38b71a4 --- /dev/null +++ b/.~lock.LogAB(20).joined.csv# @@ -0,0 +1 @@ +,DESKTOP-M40GG9U/Thad,DESKTOP-M40GG9U,09.10.2025 08:10,file:///C:/Users/Thad/AppData/Roaming/LibreOffice/4; \ No newline at end of file diff --git a/.~lock.LogAB(20).xls# b/.~lock.LogAB(20).xls# new file mode 100644 index 0000000..ed05703 --- /dev/null +++ b/.~lock.LogAB(20).xls# @@ -0,0 +1 @@ +,DESKTOP-M40GG9U/Thad,DESKTOP-M40GG9U,09.10.2025 08:40,file:///C:/Users/Thad/AppData/Roaming/LibreOffice/4; \ No newline at end of file diff --git a/LogAB(20).xls b/LogAB(20).xls new file mode 100644 index 0000000..73b24c3 Binary files /dev/null and b/LogAB(20).xls differ diff --git a/LogAB(20).xlsx b/LogAB(20).xlsx new file mode 100644 index 0000000..bc0743c Binary files /dev/null and b/LogAB(20).xlsx differ diff --git a/main.py b/main.py index 10afe23..11a368f 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,12 @@ from tkinter import filedialog, messagebox import subprocess import os from datetime import datetime +import shutil +try: + from openpyxl import load_workbook + XLSX_AVAILABLE = True +except ImportError: + XLSX_AVAILABLE = False def parse_logs(log_text): lines = log_text.splitlines() @@ -72,6 +78,42 @@ def write_csv2(pairs, filename): gross_weight, gross_units, gross_time = pairs[-1] writer.writerow([gross_weight, '', '', gross_time, '', gross_units, '', '']) +def write_xlsx(pairs, output_filename, template_path='template.xlsx'): + """Write sequential data to XLSX file using template""" + if not XLSX_AVAILABLE: + raise ImportError("openpyxl is required for XLSX export. Install with: pip install openpyxl") + + if not os.path.exists(template_path): + raise FileNotFoundError(f"Template file not found: {template_path}") + + # Load the template workbook (data_only=False preserves formulas) + wb = load_workbook(template_path, data_only=False) + + # Check if SEQUENTIAL sheet exists + if 'SEQUENTIAL' not in wb.sheetnames: + raise ValueError("Template does not contain a 'SEQUENTIAL' sheet") + + # Get the SEQUENTIAL sheet + ws = wb['SEQUENTIAL'] + + # Clear existing data (starting from row 2, assuming row 1 has headers) + # First, delete all rows below the header + if ws.max_row > 1: + ws.delete_rows(2, ws.max_row - 1) + + # Write new data starting from row 2 + for row_idx, (weight, units, timestamp) in enumerate(pairs, start=2): + ws.cell(row=row_idx, column=1, value=weight) + ws.cell(row=row_idx, column=2, value=units) + ws.cell(row=row_idx, column=3, value=timestamp) + + # Set COMBINED as the active sheet (default sheet when opened) + if 'COMBINED' in wb.sheetnames: + wb.active = wb.sheetnames.index('COMBINED') + + # Save to new filename (never overwrite template) + wb.save(output_filename) + def run_update_script(): try: # Run update.sh script @@ -101,6 +143,7 @@ def process_files(): base = os.path.splitext(input_file)[0] output_file1 = f"{base}.sequential.csv" output_file2 = f"{base}.joined.csv" + output_xlsx = f"{base}.xlsx" try: with open(input_file, 'r') as f: @@ -108,7 +151,18 @@ def process_files(): pairs = parse_logs(log_text) write_csv1(pairs, output_file1) write_csv2(pairs, output_file2) - messagebox.showinfo("Success", f"CSV files generated:\n{output_file1}\n{output_file2}") + + # Try to write XLSX file + xlsx_msg = "" + try: + write_xlsx(pairs, output_xlsx) + xlsx_msg = f"\n{output_xlsx}" + except ImportError as e: + xlsx_msg = f"\n\nXLSX export skipped: {str(e)}" + except Exception as e: + xlsx_msg = f"\n\nXLSX export failed: {str(e)}" + + messagebox.showinfo("Success", f"Files generated:\n{output_file1}\n{output_file2}{xlsx_msg}") except Exception as e: messagebox.showerror("Error", f"An error occurred: {str(e)}") diff --git a/template.xlsx b/template.xlsx new file mode 100644 index 0000000..6ca4829 Binary files /dev/null and b/template.xlsx differ