Fix formatting errors
This commit is contained in:
@@ -39,7 +39,7 @@ const App: React.FC<AppProps> = () => {
|
|||||||
colorNew: "#d4edda", // light green
|
colorNew: "#d4edda", // light green
|
||||||
colorChanged: "#fff3cd", // light yellow/orange
|
colorChanged: "#fff3cd", // light yellow/orange
|
||||||
colorDeleted: "#f8d7da", // light red
|
colorDeleted: "#f8d7da", // light red
|
||||||
colorDuplicate: "#ff0000ff", // light orange for duplicates
|
colorDuplicate: "#ffe6cc", // light orange for duplicates
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -150,6 +150,14 @@ const ColumnMapper: React.FC<ColumnMapperProps> = ({
|
|||||||
style={{ width: "60px", padding: "0", cursor: "pointer", height: "30px", border: "none" }}
|
style={{ width: "60px", padding: "0", cursor: "pointer", height: "30px", border: "none" }}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
<Field label="Duplikate">
|
||||||
|
<input
|
||||||
|
type="color"
|
||||||
|
value={settings.colorDuplicate}
|
||||||
|
onChange={(e) => onSettingsChange({ ...settings, colorDuplicate: e.target.value })}
|
||||||
|
style={{ width: "60px", padding: "0", cursor: "pointer", height: "30px", border: "none" }}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -242,7 +242,8 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
|
|||||||
if (listExists) {
|
if (listExists) {
|
||||||
try {
|
try {
|
||||||
// Existierende Liste aktualisieren
|
// Existierende Liste aktualisieren
|
||||||
const table = targetSheet.tables.getItem("KonsolidierteKabel");
|
// Wir nutzen getItemAt(0) statt eines festen Namens, da der Name "KonsolidierteKabel" bei umbenannten Sicherungskopien blockiert sein kann.
|
||||||
|
const table = targetSheet.tables.getItemAt(0);
|
||||||
const bodyRange = table.getDataBodyRange();
|
const bodyRange = table.getDataBodyRange();
|
||||||
bodyRange.load("values, rowCount, columnCount");
|
bodyRange.load("values, rowCount, columnCount");
|
||||||
await context.sync();
|
await context.sync();
|
||||||
@@ -253,11 +254,14 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
|
|||||||
const formatDeletedQueue: number[] = [];
|
const formatDeletedQueue: number[] = [];
|
||||||
const formatDuplicateQueue: number[] = []; // NEU: Queue für Duplikate
|
const formatDuplicateQueue: number[] = []; // NEU: Queue für Duplikate
|
||||||
|
|
||||||
const incomingMap = new Map<string, any[]>();
|
const incomingMap = new Map<string, any[][]>();
|
||||||
for (const row of finalData) {
|
for (const row of finalData) {
|
||||||
const kNr = String(row[0] || "").trim();
|
const kNr = String(row[0] || "").trim();
|
||||||
if (kNr) {
|
if (kNr) {
|
||||||
incomingMap.set(kNr, row);
|
if (!incomingMap.has(kNr)) {
|
||||||
|
incomingMap.set(kNr, []);
|
||||||
|
}
|
||||||
|
incomingMap.get(kNr)!.push(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,8 +275,10 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
|
|||||||
if (!kNr) continue;
|
if (!kNr) continue;
|
||||||
|
|
||||||
if (incomingMap.has(kNr)) {
|
if (incomingMap.has(kNr)) {
|
||||||
|
const inValsArray = incomingMap.get(kNr)!;
|
||||||
|
if (inValsArray.length > 0) {
|
||||||
|
const inVals = inValsArray.shift()!; // pop the first one
|
||||||
// Geändert prüfen
|
// Geändert prüfen
|
||||||
const inVals = incomingMap.get(kNr)!;
|
|
||||||
for (let c = 0; c < TARGET_COLUMNS.length; c++) {
|
for (let c = 0; c < TARGET_COLUMNS.length; c++) {
|
||||||
const oldVal = String(row[c] || "").trim();
|
const oldVal = String(row[c] || "").trim();
|
||||||
const newVal = String(inVals[c] || "").trim();
|
const newVal = String(inVals[c] || "").trim();
|
||||||
@@ -291,18 +297,25 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
|
|||||||
formatDuplicateQueue.push(r);
|
formatDuplicateQueue.push(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inValsArray.length === 0) {
|
||||||
incomingMap.delete(kNr);
|
incomingMap.delete(kNr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Should theoretically not happen if we delete when 0, but safe fallback
|
||||||
|
formatDeletedQueue.push(r);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Entfallen
|
// Entfallen
|
||||||
// Optional die Zeile einfärben
|
|
||||||
formatDeletedQueue.push(r);
|
formatDeletedQueue.push(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verbleibend = Neue Kabel
|
// Verbleibend = Neue Kabel (und überschüssige Duplikate)
|
||||||
incomingMap.forEach((newRow) => {
|
incomingMap.forEach((newRowsArray) => {
|
||||||
|
newRowsArray.forEach((newRow) => {
|
||||||
newRows.push(newRow);
|
newRows.push(newRow);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Werte in die bestehende Tabelle zurückschreiben
|
// Werte in die bestehende Tabelle zurückschreiben
|
||||||
if (existingValues.length > 0) {
|
if (existingValues.length > 0) {
|
||||||
@@ -320,6 +333,10 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
|
|||||||
// Formate anwenden
|
// Formate anwenden
|
||||||
const currentBody = table.getDataBodyRange();
|
const currentBody = table.getDataBodyRange();
|
||||||
|
|
||||||
|
// Alte Formatierungen zurücksetzen, damit behobene Konflikte wieder normal aussehen
|
||||||
|
currentBody.format.fill.clear();
|
||||||
|
currentBody.format.font.strikethrough = false;
|
||||||
|
|
||||||
// Geänderte Zellen markieren
|
// Geänderte Zellen markieren
|
||||||
for (const cell of formatChangedQueue) {
|
for (const cell of formatChangedQueue) {
|
||||||
currentBody.getCell(cell.row, cell.col).format.fill.color = settings.colorChanged;
|
currentBody.getCell(cell.row, cell.col).format.fill.color = settings.colorChanged;
|
||||||
@@ -380,11 +397,11 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
|
|||||||
await context.sync();
|
await context.sync();
|
||||||
|
|
||||||
const table = targetSheet.tables.add(targetRange, true /* hasHeaders */);
|
const table = targetSheet.tables.add(targetRange, true /* hasHeaders */);
|
||||||
table.name = "KonsolidierteKabel";
|
|
||||||
table.style = "TableStyleLight9";
|
table.style = "TableStyleLight9";
|
||||||
table.showFilterButton = true;
|
table.showFilterButton = true;
|
||||||
|
|
||||||
// Markiere komplett neu entfernt auf Userwunsch
|
// WICHTIG: Excel überschreibt manuelle Formate, wenn wir den TableStyle nicht zuerst synchronisieren!
|
||||||
|
await context.sync();
|
||||||
|
|
||||||
// Duplikate beim Neu-Erstellen einfärben:
|
// Duplikate beim Neu-Erstellen einfärben:
|
||||||
const bodyRange = table.getDataBodyRange();
|
const bodyRange = table.getDataBodyRange();
|
||||||
@@ -402,7 +419,7 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
|
|||||||
return rowsConsolidated;
|
return rowsConsolidated;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Fehler beim Erstellen der Kabelliste:", error);
|
console.error("Fehler beim Erstellen der Kabelliste:", error);
|
||||||
throw new Error("Fehler beim Erstellen der 'Kabelliste'. Möglicherweise ist die Arbeitsmappe schreibgeschützt.");
|
throw new Error("Fehler beim Erstellen der 'Kabelliste'. Möglicherweise ist die Arbeitsmappe schreibgeschützt.\n" + error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user