From 0fb2655eea41fe181bd29ce0b7e73471ec34646a Mon Sep 17 00:00:00 2001 From: va1is Date: Tue, 28 Oct 2025 11:10:08 +0300 Subject: [PATCH] UI xlsx import api --- API-UI/history.json | 3 +++ API-UI/main.py | 61 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/API-UI/history.json b/API-UI/history.json index e69de29..6db1b0a 100644 --- a/API-UI/history.json +++ b/API-UI/history.json @@ -0,0 +1,3 @@ +[ + "http://localhost:3005" +] \ No newline at end of file diff --git a/API-UI/main.py b/API-UI/main.py index 1ee5d8e..4c4a1c4 100644 --- a/API-UI/main.py +++ b/API-UI/main.py @@ -272,16 +272,37 @@ class ImportApp(QMainWindow): if not path: return try: - wb = openpyxl.load_workbook(path) + wb = openpyxl.load_workbook(path, data_only=True) sheet = wb.active - self.display_sheet(sheet) + # === читаем ВСЕ строки для обработки === + all_data = [list(r) for r in sheet.iter_rows(values_only=True)] + if not all_data: + self.log("⚠️ Файл пуст.") + return + + self.headers = [str(h) if h else "" for h in all_data[0]] + self.loaded_data = all_data # ВСЁ содержимое для дальнейшей работы + + # === только первые 50 строк показываем в таблице === + preview_data = all_data[:51] + self.table.clear() + self.table.setRowCount(0) + self.table.setColumnCount(len(self.headers)) + self.table.setHorizontalHeaderLabels(self.headers) + + for r_idx, row in enumerate(preview_data[1:], start=0): + self.table.insertRow(r_idx) + for c_idx, value in enumerate(row): + self.table.setItem(r_idx, c_idx, QTableWidgetItem("" if value is None else str(value))) + self.log(f"📄 Загружен файл: {os.path.basename(path)} ({sheet.max_row} строк)") - # обновим список заголовков в таблице сопоставления self.populate_map_table() + except Exception as e: self.log(f"❌ Ошибка при чтении файла: {e}") + def display_sheet(self, sheet): self.table.clear() self.table.setRowCount(0) @@ -358,14 +379,40 @@ class ImportApp(QMainWindow): origin_col = mapping.get("originPath", "") path_col = mapping.get("path", "") result = [] + seen_origins = set() + idx_origin = self.headers.index(origin_col) if origin_col in self.headers else -1 idx_path = self.headers.index(path_col) if path_col in self.headers else -1 for r in rows: - origin_val = (str(r[idx_origin]).strip() if idx_origin >= 0 and idx_origin < len(r) and r[idx_origin] else "") - path_val = (str(r[idx_path]).strip() if idx_path >= 0 and idx_path < len(r) and r[idx_path] else "") - if origin_val or path_val: - result.append({"originPath": origin_val, "path": path_val}) + origin_val = ( + str(r[idx_origin]).strip() + if idx_origin >= 0 and idx_origin < len(r) and r[idx_origin] + else "" + ) + path_val = ( + str(r[idx_path]).strip() + if idx_path >= 0 and idx_path < len(r) and r[idx_path] + else "" + ) + + # пропускаем полностью пустые строки + if not origin_val and not path_val: + continue + + # если originPath уже был, пропускаем (оставляем только первое вхождение) + if origin_val in seen_origins: + continue + + seen_origins.add(origin_val) + + # нормализуем разделители (чисто косметически) + path_val = " > ".join([p.strip() for p in path_val.split(">")]) + + result.append({"originPath": origin_val, "path": path_val}) + + self.log(f"🧩 Найдено уникальных originPath: {len(result)}") + # ===== PRODUCTS ===== else: