diff --git a/public/datasheets/products/h1z2z2-k-de.xlsx b/public/datasheets/products/h1z2z2-k-de.xlsx index a1228858..923da477 100644 Binary files a/public/datasheets/products/h1z2z2-k-de.xlsx and b/public/datasheets/products/h1z2z2-k-de.xlsx differ diff --git a/public/datasheets/products/h1z2z2-k-en.xlsx b/public/datasheets/products/h1z2z2-k-en.xlsx index 1d1ddd7c..908f0e25 100644 Binary files a/public/datasheets/products/h1z2z2-k-en.xlsx and b/public/datasheets/products/h1z2z2-k-en.xlsx differ diff --git a/public/datasheets/products/n2x2y-de.xlsx b/public/datasheets/products/n2x2y-de.xlsx index 4d0b7ec7..c054d0aa 100644 Binary files a/public/datasheets/products/n2x2y-de.xlsx and b/public/datasheets/products/n2x2y-de.xlsx differ diff --git a/public/datasheets/products/n2x2y-en.xlsx b/public/datasheets/products/n2x2y-en.xlsx index 438bf925..7cc1bc4a 100644 Binary files a/public/datasheets/products/n2x2y-en.xlsx and b/public/datasheets/products/n2x2y-en.xlsx differ diff --git a/public/datasheets/products/n2xs2y-de.xlsx b/public/datasheets/products/n2xs2y-de.xlsx index 6d8ff636..e1c2696e 100644 Binary files a/public/datasheets/products/n2xs2y-de.xlsx and b/public/datasheets/products/n2xs2y-de.xlsx differ diff --git a/public/datasheets/products/n2xs2y-en.xlsx b/public/datasheets/products/n2xs2y-en.xlsx index 476e525b..a54f245e 100644 Binary files a/public/datasheets/products/n2xs2y-en.xlsx and b/public/datasheets/products/n2xs2y-en.xlsx differ diff --git a/public/datasheets/products/n2xsf2y-de.xlsx b/public/datasheets/products/n2xsf2y-de.xlsx index 800f290d..205903c4 100644 Binary files a/public/datasheets/products/n2xsf2y-de.xlsx and b/public/datasheets/products/n2xsf2y-de.xlsx differ diff --git a/public/datasheets/products/n2xsf2y-en.xlsx b/public/datasheets/products/n2xsf2y-en.xlsx index 3603ad33..91553309 100644 Binary files a/public/datasheets/products/n2xsf2y-en.xlsx and b/public/datasheets/products/n2xsf2y-en.xlsx differ diff --git a/public/datasheets/products/n2xsfl2y-hv-de.xlsx b/public/datasheets/products/n2xsfl2y-hv-de.xlsx index ce872a63..f5f669bd 100644 Binary files a/public/datasheets/products/n2xsfl2y-hv-de.xlsx and b/public/datasheets/products/n2xsfl2y-hv-de.xlsx differ diff --git a/public/datasheets/products/n2xsfl2y-hv-en.xlsx b/public/datasheets/products/n2xsfl2y-hv-en.xlsx index 680e00e1..e7bf20c3 100644 Binary files a/public/datasheets/products/n2xsfl2y-hv-en.xlsx and b/public/datasheets/products/n2xsfl2y-hv-en.xlsx differ diff --git a/public/datasheets/products/n2xsfl2y-mv-de.xlsx b/public/datasheets/products/n2xsfl2y-mv-de.xlsx index ce872a63..0786b8fb 100644 Binary files a/public/datasheets/products/n2xsfl2y-mv-de.xlsx and b/public/datasheets/products/n2xsfl2y-mv-de.xlsx differ diff --git a/public/datasheets/products/n2xsfl2y-mv-en.xlsx b/public/datasheets/products/n2xsfl2y-mv-en.xlsx index 680e00e1..eb642593 100644 Binary files a/public/datasheets/products/n2xsfl2y-mv-en.xlsx and b/public/datasheets/products/n2xsfl2y-mv-en.xlsx differ diff --git a/public/datasheets/products/n2xsy-de.xlsx b/public/datasheets/products/n2xsy-de.xlsx index 91ae2e5f..61bf8345 100644 Binary files a/public/datasheets/products/n2xsy-de.xlsx and b/public/datasheets/products/n2xsy-de.xlsx differ diff --git a/public/datasheets/products/n2xsy-en.xlsx b/public/datasheets/products/n2xsy-en.xlsx index 61823413..b6e9c7de 100644 Binary files a/public/datasheets/products/n2xsy-en.xlsx and b/public/datasheets/products/n2xsy-en.xlsx differ diff --git a/public/datasheets/products/n2xy-de.xlsx b/public/datasheets/products/n2xy-de.xlsx index c02a622f..081de7db 100644 Binary files a/public/datasheets/products/n2xy-de.xlsx and b/public/datasheets/products/n2xy-de.xlsx differ diff --git a/public/datasheets/products/n2xy-en.xlsx b/public/datasheets/products/n2xy-en.xlsx index 4298dae9..73525b8b 100644 Binary files a/public/datasheets/products/n2xy-en.xlsx and b/public/datasheets/products/n2xy-en.xlsx differ diff --git a/public/datasheets/products/na2x2y-de.xlsx b/public/datasheets/products/na2x2y-de.xlsx index d7be09a4..615057d8 100644 Binary files a/public/datasheets/products/na2x2y-de.xlsx and b/public/datasheets/products/na2x2y-de.xlsx differ diff --git a/public/datasheets/products/na2x2y-en.xlsx b/public/datasheets/products/na2x2y-en.xlsx index 20d53de7..468a30ce 100644 Binary files a/public/datasheets/products/na2x2y-en.xlsx and b/public/datasheets/products/na2x2y-en.xlsx differ diff --git a/public/datasheets/products/na2xs2y-de.xlsx b/public/datasheets/products/na2xs2y-de.xlsx index 02a4536f..a30a63ed 100644 Binary files a/public/datasheets/products/na2xs2y-de.xlsx and b/public/datasheets/products/na2xs2y-de.xlsx differ diff --git a/public/datasheets/products/na2xs2y-en.xlsx b/public/datasheets/products/na2xs2y-en.xlsx index ac729689..be5c392c 100644 Binary files a/public/datasheets/products/na2xs2y-en.xlsx and b/public/datasheets/products/na2xs2y-en.xlsx differ diff --git a/public/datasheets/products/na2xsf2y-de.xlsx b/public/datasheets/products/na2xsf2y-de.xlsx index c2dab6a7..b9cde62e 100644 Binary files a/public/datasheets/products/na2xsf2y-de.xlsx and b/public/datasheets/products/na2xsf2y-de.xlsx differ diff --git a/public/datasheets/products/na2xsf2y-en.xlsx b/public/datasheets/products/na2xsf2y-en.xlsx index 5a99d648..e5eaa7e7 100644 Binary files a/public/datasheets/products/na2xsf2y-en.xlsx and b/public/datasheets/products/na2xsf2y-en.xlsx differ diff --git a/public/datasheets/products/na2xsfl2y-hv-de.xlsx b/public/datasheets/products/na2xsfl2y-hv-de.xlsx index df7c500b..40c40505 100644 Binary files a/public/datasheets/products/na2xsfl2y-hv-de.xlsx and b/public/datasheets/products/na2xsfl2y-hv-de.xlsx differ diff --git a/public/datasheets/products/na2xsfl2y-hv-en.xlsx b/public/datasheets/products/na2xsfl2y-hv-en.xlsx index e378add0..56a4a360 100644 Binary files a/public/datasheets/products/na2xsfl2y-hv-en.xlsx and b/public/datasheets/products/na2xsfl2y-hv-en.xlsx differ diff --git a/public/datasheets/products/na2xsfl2y-mv-de.xlsx b/public/datasheets/products/na2xsfl2y-mv-de.xlsx index df7c500b..b4006a8b 100644 Binary files a/public/datasheets/products/na2xsfl2y-mv-de.xlsx and b/public/datasheets/products/na2xsfl2y-mv-de.xlsx differ diff --git a/public/datasheets/products/na2xsfl2y-mv-en.xlsx b/public/datasheets/products/na2xsfl2y-mv-en.xlsx index e378add0..12614995 100644 Binary files a/public/datasheets/products/na2xsfl2y-mv-en.xlsx and b/public/datasheets/products/na2xsfl2y-mv-en.xlsx differ diff --git a/public/datasheets/products/na2xsy-de.xlsx b/public/datasheets/products/na2xsy-de.xlsx index a73c6042..2d685af0 100644 Binary files a/public/datasheets/products/na2xsy-de.xlsx and b/public/datasheets/products/na2xsy-de.xlsx differ diff --git a/public/datasheets/products/na2xsy-en.xlsx b/public/datasheets/products/na2xsy-en.xlsx index bccde935..dfe973e6 100644 Binary files a/public/datasheets/products/na2xsy-en.xlsx and b/public/datasheets/products/na2xsy-en.xlsx differ diff --git a/public/datasheets/products/na2xy-de.xlsx b/public/datasheets/products/na2xy-de.xlsx index bb28fcb8..8ce305fe 100644 Binary files a/public/datasheets/products/na2xy-de.xlsx and b/public/datasheets/products/na2xy-de.xlsx differ diff --git a/public/datasheets/products/na2xy-en.xlsx b/public/datasheets/products/na2xy-en.xlsx index 07dad760..efdb6200 100644 Binary files a/public/datasheets/products/na2xy-en.xlsx and b/public/datasheets/products/na2xy-en.xlsx differ diff --git a/public/datasheets/products/nay2y-de.xlsx b/public/datasheets/products/nay2y-de.xlsx index 084e742b..92809d9c 100644 Binary files a/public/datasheets/products/nay2y-de.xlsx and b/public/datasheets/products/nay2y-de.xlsx differ diff --git a/public/datasheets/products/nay2y-en.xlsx b/public/datasheets/products/nay2y-en.xlsx index 673c8b11..cb673a7c 100644 Binary files a/public/datasheets/products/nay2y-en.xlsx and b/public/datasheets/products/nay2y-en.xlsx differ diff --git a/public/datasheets/products/naycwy-de.xlsx b/public/datasheets/products/naycwy-de.xlsx index 5210d4cc..d2df52d7 100644 Binary files a/public/datasheets/products/naycwy-de.xlsx and b/public/datasheets/products/naycwy-de.xlsx differ diff --git a/public/datasheets/products/naycwy-en.xlsx b/public/datasheets/products/naycwy-en.xlsx index d9e0a5af..7cc5bc49 100644 Binary files a/public/datasheets/products/naycwy-en.xlsx and b/public/datasheets/products/naycwy-en.xlsx differ diff --git a/public/datasheets/products/nayy-de.xlsx b/public/datasheets/products/nayy-de.xlsx index 7d372e7b..bc3e081e 100644 Binary files a/public/datasheets/products/nayy-de.xlsx and b/public/datasheets/products/nayy-de.xlsx differ diff --git a/public/datasheets/products/nayy-en.xlsx b/public/datasheets/products/nayy-en.xlsx index 66a3a90d..6b19957d 100644 Binary files a/public/datasheets/products/nayy-en.xlsx and b/public/datasheets/products/nayy-en.xlsx differ diff --git a/public/datasheets/products/ny2y-de.xlsx b/public/datasheets/products/ny2y-de.xlsx index 6e3fee2c..d20d82f9 100644 Binary files a/public/datasheets/products/ny2y-de.xlsx and b/public/datasheets/products/ny2y-de.xlsx differ diff --git a/public/datasheets/products/ny2y-en.xlsx b/public/datasheets/products/ny2y-en.xlsx index 82dd4797..6bbf686d 100644 Binary files a/public/datasheets/products/ny2y-en.xlsx and b/public/datasheets/products/ny2y-en.xlsx differ diff --git a/public/datasheets/products/nycwy-de.xlsx b/public/datasheets/products/nycwy-de.xlsx index 17d8d992..ee854af7 100644 Binary files a/public/datasheets/products/nycwy-de.xlsx and b/public/datasheets/products/nycwy-de.xlsx differ diff --git a/public/datasheets/products/nycwy-en.xlsx b/public/datasheets/products/nycwy-en.xlsx index df38f67b..89d388c0 100644 Binary files a/public/datasheets/products/nycwy-en.xlsx and b/public/datasheets/products/nycwy-en.xlsx differ diff --git a/public/datasheets/products/nyy-de.xlsx b/public/datasheets/products/nyy-de.xlsx index 019f57f0..00fca5f6 100644 Binary files a/public/datasheets/products/nyy-de.xlsx and b/public/datasheets/products/nyy-de.xlsx differ diff --git a/public/datasheets/products/nyy-en.xlsx b/public/datasheets/products/nyy-en.xlsx index 373c4a42..00c2c6d1 100644 Binary files a/public/datasheets/products/nyy-en.xlsx and b/public/datasheets/products/nyy-en.xlsx differ diff --git a/scripts/generate-excel-datasheets.ts b/scripts/generate-excel-datasheets.ts index e3573fff..cdeb315e 100644 --- a/scripts/generate-excel-datasheets.ts +++ b/scripts/generate-excel-datasheets.ts @@ -15,178 +15,208 @@ import configPromise from '@payload-config'; import { buildExcelModel, ProductData as ExcelProductData } from './lib/excel-data-parser'; const CONFIG = { - outputDir: path.join(process.cwd(), 'public/datasheets'), + outputDir: path.join(process.cwd(), 'public/datasheets'), } as const; // ─── Types ────────────────────────────────────────────────────────────────────── interface ProductData { - title: string; - slug: string; - sku: string; - locale: string; - categories: string[]; - description: string; - technicalItems: Array<{ label: string; value: string; unit?: string }>; - voltageTables: Array<{ - voltageLabel: string; - metaItems: Array<{ label: string; value: string; unit?: string }>; - columns: Array<{ key: string; label: string; get: (rowIndex: number) => string }>; - crossSections: string[]; - }>; + title: string; + slug: string; + sku: string; + locale: string; + categories: string[]; + description: string; + technicalItems: Array<{ label: string; value: string; unit?: string }>; + voltageTables: Array<{ + voltageLabel: string; + metaItems: Array<{ label: string; value: string; unit?: string }>; + columns: Array<{ key: string; label: string; get: (rowIndex: number) => string }>; + crossSections: string[]; + }>; } // ─── Helpers ──────────────────────────────────────────────────────────────────── function stripHtml(html: string): string { - if (!html) return ''; - return html.replace(/<[^>]*>/g, '').trim(); + if (!html) return ''; + return html.replace(/<[^>]*>/g, '').trim(); } function ensureOutputDir(): void { - if (!fs.existsSync(CONFIG.outputDir)) { - fs.mkdirSync(CONFIG.outputDir, { recursive: true }); - } + if (!fs.existsSync(CONFIG.outputDir)) { + fs.mkdirSync(CONFIG.outputDir, { recursive: true }); + } } // ─── CMS Product Loading ──────────────────────────────────────────────────────── async function fetchProductsFromCMS(locale: 'en' | 'de'): Promise { - const products: ProductData[] = []; - try { - const payload = await getPayload({ config: configPromise }); - const isDev = process.env.NODE_ENV === 'development'; + const products: ProductData[] = []; + try { + const payload = await getPayload({ config: configPromise }); + const isDev = process.env.NODE_ENV === 'development'; - const result = await payload.find({ - collection: 'products', - where: { - ...(!isDev ? { _status: { equals: 'published' } } : {}), - }, - locale: locale as any, - pagination: false, - }); + const result = await payload.find({ + collection: 'products', + where: { + ...(!isDev ? { _status: { equals: 'published' } } : {}), + }, + locale: locale as any, + pagination: false, + }); - for (const doc of result.docs) { - if (!doc.title || !doc.slug) continue; + for (const doc of result.docs) { + if (!doc.title || !doc.slug) continue; - const excelProductData: ExcelProductData = { - name: String(doc.title), - slug: String(doc.slug), - sku: String(doc.sku || ''), - locale, - }; + const excelProductData: ExcelProductData = { + name: String(doc.title), + slug: String(doc.slug), + sku: String(doc.sku || ''), + locale, + }; - const parsedModel = buildExcelModel({ product: excelProductData, locale }); + const parsedModel = buildExcelModel({ product: excelProductData, locale }); - products.push({ - title: String(doc.title), - slug: String(doc.slug), - sku: String(doc.sku || ''), - locale, - categories: Array.isArray(doc.categories) - ? doc.categories.map((c: any) => String(c.category || c)).filter(Boolean) - : [], - description: stripHtml(String(doc.description || '')), - technicalItems: parsedModel.ok ? parsedModel.technicalItems : [], - voltageTables: parsedModel.ok ? parsedModel.voltageTables : [], - }); - } - } catch (error) { - console.error(`[Payload] Failed to fetch products (${locale}):`, error); + products.push({ + title: String(doc.title), + slug: String(doc.slug), + sku: String(doc.sku || ''), + locale, + categories: Array.isArray(doc.categories) + ? doc.categories.map((c: any) => String(c.category || c)).filter(Boolean) + : [], + description: stripHtml(String(doc.description || '')), + technicalItems: parsedModel.ok ? parsedModel.technicalItems : [], + voltageTables: parsedModel.ok ? parsedModel.voltageTables : [], + }); } + } catch (error) { + console.error(`[Payload] Failed to fetch products (${locale}):`, error); + } - return products; + return products; } // ─── Excel Generation ─────────────────────────────────────────────────────────── function generateExcelForProduct(product: ProductData): Buffer { - const workbook = XLSX.utils.book_new(); - const l = product.locale === 'de'; + const workbook = XLSX.utils.book_new(); + const l = product.locale === 'de'; - // Single sheet: all cross-sections from all voltage tables combined - const hasMultipleVoltages = product.voltageTables.length > 1; - const allRows: string[][] = []; + const allRows: any[][] = []; - // Build unified header row - // Use columns from the first voltage table (they're the same across tables) - const refTable = product.voltageTables[0]; - if (!refTable) { - // No voltage tables — create a minimal info sheet - const ws = XLSX.utils.aoa_to_sheet([ - [product.title], - [l ? 'Keine Querschnittsdaten verfügbar' : 'No cross-section data available'], - ]); - ws['!cols'] = [{ wch: 40 }]; - XLSX.utils.book_append_sheet(workbook, ws, product.title.substring(0, 31)); - return Buffer.from(XLSX.write(workbook, { type: 'buffer', bookType: 'xlsx' })); + // --- 1. Product Meta Data --- + allRows.push([product.title]); + const categoriesLine = product.categories.join(' • '); + if (categoriesLine) { + allRows.push([l ? 'Kategorien:' : 'Categories:', categoriesLine]); + } + if (product.sku) { + allRows.push([l ? 'Artikelnummer:' : 'SKU:', product.sku]); + } + allRows.push([]); // blank row + + // --- 2. Application / Description --- + if (product.description) { + allRows.push([l ? 'ANWENDUNG' : 'APPLICATION']); + allRows.push([product.description]); + allRows.push([]); // blank row + } + + // --- 3. Technical Specifications --- + if (product.technicalItems && product.technicalItems.length > 0) { + allRows.push([l ? 'TECHNISCHE DATEN' : 'TECHNICAL DATA']); + for (const item of product.technicalItems) { + const val = item.unit ? `${item.value} ${item.unit}` : item.value; + allRows.push([item.label, val]); } + allRows.push([]); // blank row + } + // --- 4. Cross-section Configurations --- + const hasMultipleVoltages = product.voltageTables.length > 1; + if (product.voltageTables.length > 0) { + allRows.push([l ? 'KONFIGURATIONEN' : 'CONFIGURATIONS']); + + const refTable = product.voltageTables[0]; const headers: string[] = [ - l ? 'Querschnitt' : 'Cross-section', - ...(hasMultipleVoltages ? [l ? 'Spannung' : 'Voltage'] : []), - ...refTable.columns.map(c => c.label), + l ? 'Querschnitt' : 'Cross-section', + ...(hasMultipleVoltages ? [l ? 'Spannung' : 'Voltage'] : []), + ...refTable.columns.map((c) => c.label), ]; allRows.push(headers); - // Merge rows from all voltage tables for (const table of product.voltageTables) { - for (let rowIdx = 0; rowIdx < table.crossSections.length; rowIdx++) { - const row: string[] = [ - table.crossSections[rowIdx], - ...(hasMultipleVoltages ? [table.voltageLabel] : []), - ...table.columns.map(c => c.get(rowIdx) || '-'), - ]; - allRows.push(row); - } + for (let rowIdx = 0; rowIdx < table.crossSections.length; rowIdx++) { + const row: string[] = [ + table.crossSections[rowIdx], + ...(hasMultipleVoltages ? [table.voltageLabel] : []), + ...table.columns.map((c) => c.get(rowIdx) || '-'), + ]; + allRows.push(row); + } } + } else { + allRows.push([l ? 'Keine Querschnittsdaten verfügbar' : 'No cross-section data available']); + } - const ws = XLSX.utils.aoa_to_sheet(allRows); - // Auto-width: first col wider for cross-section labels - ws['!cols'] = headers.map((_, i) => ({ wch: i === 0 ? 30 : 18 })); + const ws = XLSX.utils.aoa_to_sheet(allRows); - const sheetName = product.title.substring(0, 31); - XLSX.utils.book_append_sheet(workbook, ws, sheetName); + // Auto-width: Col 0 wide for description, headers. + ws['!cols'] = [ + { wch: 45 }, + { wch: 20 }, + { wch: 15 }, + { wch: 15 }, + { wch: 15 }, + { wch: 15 }, + { wch: 15 }, + { wch: 15 }, + ]; - const buffer = XLSX.write(workbook, { type: 'buffer', bookType: 'xlsx' }); - return Buffer.from(buffer); + const sheetName = product.title.substring(0, 31); + XLSX.utils.book_append_sheet(workbook, ws, sheetName); + + const buffer = XLSX.write(workbook, { type: 'buffer', bookType: 'xlsx' }); + return Buffer.from(buffer); } // ─── Main ─────────────────────────────────────────────────────────────────────── async function main(): Promise { - const start = Date.now(); - console.log('Starting Excel datasheet generation (Legacy Excel Source)'); - ensureOutputDir(); + const start = Date.now(); + console.log('Starting Excel datasheet generation (Legacy Excel Source)'); + ensureOutputDir(); - const locales: Array<'en' | 'de'> = ['en', 'de']; - let generated = 0; + const locales: Array<'en' | 'de'> = ['en', 'de']; + let generated = 0; - for (const locale of locales) { - console.log(`\n[${locale.toUpperCase()}] Fetching products...`); - const products = await fetchProductsFromCMS(locale); - console.log(`Found ${products.length} products.`); + for (const locale of locales) { + console.log(`\n[${locale.toUpperCase()}] Fetching products...`); + const products = await fetchProductsFromCMS(locale); + console.log(`Found ${products.length} products.`); - for (const product of products) { - try { - const buffer = generateExcelForProduct(product); - const fileName = `${product.slug}-${locale}.xlsx`; + for (const product of products) { + try { + const buffer = generateExcelForProduct(product); + const fileName = `${product.slug}-${locale}.xlsx`; - const subfolder = path.join(CONFIG.outputDir, 'products'); - if (!fs.existsSync(subfolder)) fs.mkdirSync(subfolder, { recursive: true }); + const subfolder = path.join(CONFIG.outputDir, 'products'); + if (!fs.existsSync(subfolder)) fs.mkdirSync(subfolder, { recursive: true }); - fs.writeFileSync(path.join(subfolder, fileName), buffer); - console.log(`✓ Generated: ${fileName}`); - generated++; - } catch (error) { - console.error(`✗ Failed for ${product.title}:`, error); - } - } + fs.writeFileSync(path.join(subfolder, fileName), buffer); + console.log(`✓ Generated: ${fileName}`); + generated++; + } catch (error) { + console.error(`✗ Failed for ${product.title}:`, error); + } } + } - console.log(`\n✅ Done! Generated ${generated} files.`); - console.log(`Output: ${CONFIG.outputDir}`); - console.log(`Time: ${((Date.now() - start) / 1000).toFixed(2)}s`); + console.log(`\n✅ Done! Generated ${generated} files.`); + console.log(`Output: ${CONFIG.outputDir}`); + console.log(`Time: ${((Date.now() - start) / 1000).toFixed(2)}s`); } main().catch(console.error);