Fix formatting errors

This commit is contained in:
2026-03-02 08:17:30 +01:00
parent 63cff880a5
commit 3a9140bc37
3 changed files with 55 additions and 30 deletions

View File

@@ -39,7 +39,7 @@ const App: React.FC<AppProps> = () => {
colorNew: "#d4edda", // light green
colorChanged: "#fff3cd", // light yellow/orange
colorDeleted: "#f8d7da", // light red
colorDuplicate: "#ff0000ff", // light orange for duplicates
colorDuplicate: "#ffe6cc", // light orange for duplicates
});
useEffect(() => {

View File

@@ -150,6 +150,14 @@ const ColumnMapper: React.FC<ColumnMapperProps> = ({
style={{ width: "60px", padding: "0", cursor: "pointer", height: "30px", border: "none" }}
/>
</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>

View File

@@ -242,7 +242,8 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
if (listExists) {
try {
// 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();
bodyRange.load("values, rowCount, columnCount");
await context.sync();
@@ -253,11 +254,14 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
const formatDeletedQueue: number[] = [];
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) {
const kNr = String(row[0] || "").trim();
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 (incomingMap.has(kNr)) {
const inValsArray = incomingMap.get(kNr)!;
if (inValsArray.length > 0) {
const inVals = inValsArray.shift()!; // pop the first one
// Geändert prüfen
const inVals = incomingMap.get(kNr)!;
for (let c = 0; c < TARGET_COLUMNS.length; c++) {
const oldVal = String(row[c] || "").trim();
const newVal = String(inVals[c] || "").trim();
@@ -291,18 +297,25 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
formatDuplicateQueue.push(r);
}
if (inValsArray.length === 0) {
incomingMap.delete(kNr);
}
} else {
// Should theoretically not happen if we delete when 0, but safe fallback
formatDeletedQueue.push(r);
}
} else {
// Entfallen
// Optional die Zeile einfärben
formatDeletedQueue.push(r);
}
}
// Verbleibend = Neue Kabel
incomingMap.forEach((newRow) => {
// Verbleibend = Neue Kabel (und überschüssige Duplikate)
incomingMap.forEach((newRowsArray) => {
newRowsArray.forEach((newRow) => {
newRows.push(newRow);
});
});
// Werte in die bestehende Tabelle zurückschreiben
if (existingValues.length > 0) {
@@ -320,6 +333,10 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
// Formate anwenden
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
for (const cell of formatChangedQueue) {
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();
const table = targetSheet.tables.add(targetRange, true /* hasHeaders */);
table.name = "KonsolidierteKabel";
table.style = "TableStyleLight9";
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:
const bodyRange = table.getDataBodyRange();
@@ -402,7 +419,7 @@ export async function consolidateData(mappings: SheetMappingStatus[], settings:
return rowsConsolidated;
} catch (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);
}
}
});