Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { saveAs } from 'file-saver';
- import * as ExcelJS from 'exceljs';
- const DATA: any = [
- {
- "createDate": "2024-05-28",
- "proposalType": "Total Exposure > IDR 15 Bio",
- "segment": [
- {
- "segmentId": "7501",
- "segmentName": "SME 1",
- "lcType": [
- {
- "lcParentId": "SME",
- "listLC": [
- {
- "lcParent": "SME",
- "lcId": "LC1_SME",
- "lcName": "LC 1 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- },
- {
- "lcParent": "SME",
- "lcId": "LC2_SME",
- "lcName": "LC 2 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "1",
- "product": [
- {
- "kategoriProduct": "Renewal",
- "noa": "1",
- "listProduct": [
- {
- "applicationId": 3314,
- "applicationType": "Renewal",
- "amountType": "Plafond",
- "amount": "5900000000"
- },
- {
- "applicationId": 3314,
- "applicationType": "Renewal",
- "amountType": "Changes",
- "amount": "0"
- }
- ],
- "summaryAmount": [
- {
- "amountType": "Changes",
- "currencyAmount": [
- {
- "currency": "IDR",
- "amount": "0"
- }
- ]
- }
- ]
- },
- {
- "kategoriProduct": "New (NTB)",
- "noa": "2",
- "listProduct": [
- {
- "applicationId": 3590,
- "applicationType": "New",
- "amountType": "Plafond",
- "amount": "22500000000"
- },
- {
- "applicationId": 3590,
- "applicationType": "New",
- "amountType": "Changes",
- "amount": "0"
- },
- {
- "applicationId": 3597,
- "applicationType": "New",
- "amountType": "Plafond",
- "amount": "20000000000"
- },
- {
- "applicationId": 3597,
- "applicationType": "New",
- "amountType": "Changes",
- "amount": "0"
- }
- ],
- "summaryAmount": [
- {
- "amountType": "Changes",
- "currencyAmount": [
- {
- "currency": "IDR",
- "amount": "0"
- }
- ]
- }
- ]
- }
- ]
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- },
- {
- "lcParent": "SME",
- "lcId": "LC3_SME",
- "lcName": "LC 3 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": [
- {
- "kategoriProduct": "Renewal",
- "noa": "2",
- "listProduct": [
- {
- "applicationId": 3603,
- "applicationType": "Renewal",
- "amountType": "Plafond",
- "amount": "13322927300"
- },
- {
- "applicationId": 3603,
- "applicationType": "Renewal",
- "amountType": "Changes",
- "amount": "0"
- },
- {
- "applicationId": 3603,
- "applicationType": "Renewal",
- "amountType": "Plafond",
- "amount": "25000000000"
- },
- {
- "applicationId": 3603,
- "applicationType": "Renewal",
- "amountType": "Changes",
- "amount": "0"
- }
- ],
- "summaryAmount": [
- {
- "amountType": "Changes",
- "currencyAmount": [
- {
- "currency": "IDR",
- "amount": "0"
- }
- ]
- }
- ]
- }
- ]
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- },
- {
- "lcParent": "SME",
- "lcId": "LC4_SME",
- "lcName": "LC 4 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- }
- ]
- }
- ]
- },
- {
- "segmentId": "7502",
- "segmentName": "SME 2",
- "lcType": [
- {
- "lcParentId": "SME",
- "listLC": [
- {
- "lcParent": "SME",
- "lcId": "LC1_SME",
- "lcName": "LC 1 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- },
- {
- "lcParent": "SME",
- "lcId": "LC2_SME",
- "lcName": "LC 2 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": [
- {
- "kategoriProduct": "New (NTB)",
- "noa": "1",
- "listProduct": [
- {
- "applicationId": 3311,
- "applicationType": "New",
- "amountType": "Plafond",
- "amount": "3500000000"
- },
- {
- "applicationId": 3311,
- "applicationType": "New",
- "amountType": "Changes",
- "amount": "3500000000"
- }
- ],
- "summaryAmount": [
- {
- "amountType": "Changes",
- "currencyAmount": [
- {
- "currency": "IDR",
- "amount": "3500000000"
- }
- ]
- }
- ]
- }
- ]
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- },
- {
- "lcParent": "SME",
- "lcId": "LC3_SME",
- "lcName": "LC 3 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- },
- {
- "lcParent": "SME",
- "lcId": "LC4_SME",
- "lcName": "LC 4 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- }
- ]
- }
- ]
- },
- {
- "segmentId": "7503",
- "segmentName": "SME 3",
- "lcType": [
- {
- "lcParentId": "SME",
- "listLC": [
- {
- "lcParent": "SME",
- "lcId": "LC1_SME",
- "lcName": "LC 1 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- },
- {
- "lcParent": "SME",
- "lcId": "LC2_SME",
- "lcName": "LC 2 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "1",
- "product": [
- {
- "kategoriProduct": "Renewal",
- "noa": "3",
- "listProduct": [
- {
- "applicationId": 3243,
- "applicationType": "Renewal",
- "amountType": "Plafond",
- "amount": "16000000000"
- },
- {
- "applicationId": 3243,
- "applicationType": "Renewal",
- "amountType": "Changes",
- "amount": "0"
- },
- {
- "applicationId": 3243,
- "applicationType": "Renewal",
- "amountType": "Plafond",
- "amount": "12000000000"
- },
- {
- "applicationId": 3243,
- "applicationType": "Renewal",
- "amountType": "Changes",
- "amount": "0"
- },
- {
- "applicationId": 3243,
- "applicationType": "Renewal",
- "amountType": "Plafond",
- "amount": "24000000000"
- },
- {
- "applicationId": 3243,
- "applicationType": "Renewal",
- "amountType": "Changes",
- "amount": "0"
- }
- ],
- "summaryAmount": [
- {
- "amountType": "Changes",
- "currencyAmount": [
- {
- "currency": "IDR",
- "amount": "0"
- }
- ]
- }
- ]
- }
- ]
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- },
- {
- "lcParent": "SME",
- "lcId": "LC3_SME",
- "lcName": "LC 3 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "1",
- "product": [
- {
- "kategoriProduct": "Decrease",
- "noa": "1",
- "listProduct": [
- {
- "applicationId": 3551,
- "applicationType": "Renewal + Decrease",
- "amountType": "Plafond",
- "amount": "20000000000"
- },
- {
- "applicationId": 3551,
- "applicationType": "Renewal + Decrease",
- "amountType": "Changes",
- "amount": "0"
- }
- ],
- "summaryAmount": [
- {
- "amountType": "Changes",
- "currencyAmount": [
- {
- "currency": "IDR",
- "amount": "0"
- }
- ]
- }
- ]
- },
- {
- "kategoriProduct": "Renewal",
- "noa": "1",
- "listProduct": [
- {
- "applicationId": 3551,
- "applicationType": "Renewal",
- "amountType": "Plafond",
- "amount": "14863847100"
- },
- {
- "applicationId": 3551,
- "applicationType": "Renewal",
- "amountType": "Changes",
- "amount": "0"
- }
- ],
- "summaryAmount": [
- {
- "amountType": "Changes",
- "currencyAmount": [
- {
- "currency": "IDR",
- "amount": "0"
- }
- ]
- }
- ]
- }
- ]
- }
- ]
- },
- {
- "lcParent": "SME",
- "lcId": "LC4_SME",
- "lcName": "LC 4 SME",
- "conditionType": [
- {
- "conditionName": "Approved",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Reject",
- "noa": "0",
- "product": []
- },
- {
- "conditionName": "Cancel",
- "noa": "0",
- "product": []
- }
- ]
- }
- ]
- }
- ]
- }
- ]
- },
- // {
- // "createDate": "2024-05-28",
- // "proposalType": "Total Exposure > IDR 15 Bio",
- // "lcType": [
- // {
- // "lcId": "LC2_CORP",
- // "lcParent": "CORPORATE",
- // "lcName": "LC 2 Corporate",
- // "segment": [
- // {
- // "segmentId": "9903",
- // "segmentName": "Corporate Banking",
- // "conditionType": [
- // {
- // "conditionName": "Approved",
- // "noa": "1",
- // "product": [
- // {
- // "kategoriProduct": "Additional (Existing)",
- // "noa": "1",
- // "listProduct": [
- // {
- // "applicationId": 1827,
- // "applicationType": "Additional / Top Up",
- // "amountType": "Plafond",
- // "amount": "1806250.00"
- // },
- // {
- // "applicationId": 1827,
- // "applicationType": "Additional / Top Up",
- // "amountType": "Changes",
- // "amount": "0.00"
- // }
- // ],
- // "summaryAmount": [
- // {
- // "amountType": "Changes",
- // "currencyAmount": [
- // {
- // "currency": "USD",
- // "amount": "0"
- // }
- // ]
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "conditionName": "Reject",
- // "noa": "0",
- // "product": []
- // },
- // {
- // "conditionName": "Cancel",
- // "noa": "0",
- // "product": []
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "lcId": "LC2_SME",
- // "lcParent": "SME",
- // "lcName": "LC 2 SME",
- // "segment": [
- // {
- // "segmentId": "7503",
- // "segmentName": "SME 3",
- // "conditionType": [
- // {
- // "conditionName": "Approved",
- // "noa": "1",
- // "product": [
- // {
- // "kategoriProduct": "Renewal",
- // "noa": "3",
- // "listProduct": [
- // {
- // "applicationId": 3243,
- // "applicationType": "Renewal",
- // "amountType": "Plafond",
- // "amount": "16000000000"
- // },
- // {
- // "applicationId": 3243,
- // "applicationType": "Renewal",
- // "amountType": "Changes",
- // "amount": "0"
- // },
- // {
- // "applicationId": 3243,
- // "applicationType": "Renewal",
- // "amountType": "Plafond",
- // "amount": "12000000000"
- // },
- // {
- // "applicationId": 3243,
- // "applicationType": "Renewal",
- // "amountType": "Changes",
- // "amount": "0"
- // },
- // {
- // "applicationId": 3243,
- // "applicationType": "Renewal",
- // "amountType": "Plafond",
- // "amount": "24000000000"
- // },
- // {
- // "applicationId": 3243,
- // "applicationType": "Renewal",
- // "amountType": "Changes",
- // "amount": "0"
- // }
- // ],
- // "summaryAmount": [
- // {
- // "amountType": "Changes",
- // "currencyAmount": [
- // {
- // "currency": "IDR",
- // "amount": "0"
- // }
- // ]
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "conditionName": "Reject",
- // "noa": "0",
- // "product": []
- // },
- // {
- // "conditionName": "Cancel",
- // "noa": "0",
- // "product": []
- // }
- // ]
- // },
- // {
- // "segmentId": "7502",
- // "segmentName": "SME 2",
- // "conditionType": [
- // {
- // "conditionName": "Approved",
- // "noa": "0",
- // "product": []
- // },
- // {
- // "conditionName": "Reject",
- // "noa": "0",
- // "product": [
- // {
- // "kategoriProduct": "New (NTB)",
- // "noa": "1",
- // "listProduct": [
- // {
- // "applicationId": 3311,
- // "applicationType": "New",
- // "amountType": "Plafond",
- // "amount": "3500000000"
- // },
- // {
- // "applicationId": 3311,
- // "applicationType": "New",
- // "amountType": "Changes",
- // "amount": "3500000000"
- // }
- // ],
- // "summaryAmount": [
- // {
- // "amountType": "Changes",
- // "currencyAmount": [
- // {
- // "currency": "IDR",
- // "amount": "3500000000"
- // }
- // ]
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "conditionName": "Cancel",
- // "noa": "0",
- // "product": []
- // }
- // ]
- // },
- // {
- // "segmentId": "7501",
- // "segmentName": "SME 1",
- // "conditionType": [
- // {
- // "conditionName": "Approved",
- // "noa": "1",
- // "product": [
- // {
- // "kategoriProduct": "Renewal",
- // "noa": "1",
- // "listProduct": [
- // {
- // "applicationId": 3314,
- // "applicationType": "Renewal",
- // "amountType": "Plafond",
- // "amount": "5900000000"
- // },
- // {
- // "applicationId": 3314,
- // "applicationType": "Renewal",
- // "amountType": "Changes",
- // "amount": "0"
- // }
- // ],
- // "summaryAmount": [
- // {
- // "amountType": "Changes",
- // "currencyAmount": [
- // {
- // "currency": "IDR",
- // "amount": "0"
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "kategoriProduct": "New (NTB)",
- // "noa": "2",
- // "listProduct": [
- // {
- // "applicationId": 3590,
- // "applicationType": "New",
- // "amountType": "Plafond",
- // "amount": "22500000000"
- // },
- // {
- // "applicationId": 3590,
- // "applicationType": "New",
- // "amountType": "Changes",
- // "amount": "0"
- // },
- // {
- // "applicationId": 3597,
- // "applicationType": "New",
- // "amountType": "Plafond",
- // "amount": "20000000000"
- // },
- // {
- // "applicationId": 3597,
- // "applicationType": "New",
- // "amountType": "Changes",
- // "amount": "0"
- // }
- // ],
- // "summaryAmount": [
- // {
- // "amountType": "Changes",
- // "currencyAmount": [
- // {
- // "currency": "IDR",
- // "amount": "0"
- // }
- // ]
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "conditionName": "Reject",
- // "noa": "0",
- // "product": []
- // },
- // {
- // "conditionName": "Cancel",
- // "noa": "0",
- // "product": []
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "lcId": "LC3_SME",
- // "lcParent": "SME",
- // "lcName": "LC 3 SME",
- // "segment": [
- // {
- // "segmentId": "7503",
- // "segmentName": "SME 3",
- // "conditionType": [
- // {
- // "conditionName": "Approved",
- // "noa": "0",
- // "product": []
- // },
- // {
- // "conditionName": "Reject",
- // "noa": "0",
- // "product": []
- // },
- // {
- // "conditionName": "Cancel",
- // "noa": "1",
- // "product": [
- // {
- // "kategoriProduct": "Decrease",
- // "noa": "1",
- // "listProduct": [
- // {
- // "applicationId": 3551,
- // "applicationType": "Renewal + Decrease",
- // "amountType": "Plafond",
- // "amount": "20000000000"
- // },
- // {
- // "applicationId": 3551,
- // "applicationType": "Renewal + Decrease",
- // "amountType": "Changes",
- // "amount": "0"
- // }
- // ],
- // "summaryAmount": [
- // {
- // "amountType": "Changes",
- // "currencyAmount": [
- // {
- // "currency": "IDR",
- // "amount": "0"
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "kategoriProduct": "Renewal",
- // "noa": "1",
- // "listProduct": [
- // {
- // "applicationId": 3551,
- // "applicationType": "Renewal",
- // "amountType": "Plafond",
- // "amount": "14863847100"
- // },
- // {
- // "applicationId": 3551,
- // "applicationType": "Renewal",
- // "amountType": "Changes",
- // "amount": "0"
- // }
- // ],
- // "summaryAmount": [
- // {
- // "amountType": "Changes",
- // "currencyAmount": [
- // {
- // "currency": "IDR",
- // "amount": "0"
- // }
- // ]
- // }
- // ]
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "segmentId": "7501",
- // "segmentName": "SME 1",
- // "conditionType": [
- // {
- // "conditionName": "Approved",
- // "noa": "0",
- // "product": [
- // {
- // "kategoriProduct": "Renewal",
- // "noa": "2",
- // "listProduct": [
- // {
- // "applicationId": 3603,
- // "applicationType": "Renewal",
- // "amountType": "Plafond",
- // "amount": "13322927300"
- // },
- // {
- // "applicationId": 3603,
- // "applicationType": "Renewal",
- // "amountType": "Changes",
- // "amount": "0"
- // },
- // {
- // "applicationId": 3603,
- // "applicationType": "Renewal",
- // "amountType": "Plafond",
- // "amount": "25000000000"
- // },
- // {
- // "applicationId": 3603,
- // "applicationType": "Renewal",
- // "amountType": "Changes",
- // "amount": "0"
- // }
- // ],
- // "summaryAmount": [
- // {
- // "amountType": "Changes",
- // "currencyAmount": [
- // {
- // "currency": "IDR",
- // "amount": "0"
- // }
- // ]
- // }
- // ]
- // }
- // ]
- // },
- // {
- // "conditionName": "Reject",
- // "noa": "0",
- // "product": []
- // },
- // {
- // "conditionName": "Cancel",
- // "noa": "0",
- // "product": []
- // }
- // ]
- // }
- // ]
- // }
- // ]
- // }
- ]
- export const exportSummaryApprovalCompare = () => {
- // Create a new Excel workbook
- const workbook = new ExcelJS.Workbook();
- const ws = workbook.addWorksheet('Sheet 1');
- // Create the template
- createTemplate(ws, DATA);
- // Map data to template
- mapDataToTemplate(ws, DATA);
- // Save the Excel file
- workbook.xlsx.writeBuffer().then((buffer) => {
- const blob = new Blob([buffer], {
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- });
- saveAs(blob, `LC_Summary_Simplified_${new Date().toISOString().split('T')[0]}.xlsx`);
- });
- };
- const createTemplate = (ws: ExcelJS.Worksheet, data: any): void => {
- // Add headers
- ws.getCell('A1').value = 'Date Range';
- ws.getCell('A2').value = 'Proposal Type';
- ws.getCell('A3').value = 'Amount Type';
- // Header values
- ws.getCell('B1').value = '2025-07-10 - 2025-07-15';
- ws.getCell('B2').value = 'Total Exposure > IDR 15 Bio';
- ws.getCell('B3').value = 'Plafond';
- // Create dynamic column headers based on data
- createDynamicHeaders(ws, data);
- };
- const createDynamicHeaders = (ws: ExcelJS.Worksheet, data: any): void => {
- let startRow = 5; // Start after the basic info rows
- let currentCol = 1; // Column A
- // Set main headers - merge Conditions header vertically (spans 3 rows now)
- ws.mergeCells(startRow, currentCol, startRow + 2, currentCol);
- const conditionsCell = ws.getCell(startRow, currentCol);
- conditionsCell.value = 'Conditions';
- conditionsCell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFE0E0E0' }
- };
- conditionsCell.font = { bold: true };
- conditionsCell.alignment = { horizontal: 'center', vertical: 'middle' };
- conditionsCell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- currentCol++;
- // Get unique LC types and segments from data
- const lcTypes = new Set<string>();
- const segments = new Set<string>();
- data.forEach((item: any) => {
- if (item.segment) {
- item.segment.forEach((seg: any) => {
- segments.add(seg.segmentName);
- if (seg.lcType) {
- seg.lcType.forEach((lc: any) => {
- if (lc.listLC) {
- lc.listLC.forEach((lcItem: any) => {
- lcTypes.add(lcItem.lcName);
- });
- }
- });
- }
- });
- }
- if (item.lcType) {
- item.lcType.forEach((lc: any) => {
- lcTypes.add(lc.lcName);
- if (lc.segment) {
- lc.segment.forEach((seg: any) => {
- segments.add(seg.segmentName);
- });
- }
- });
- }
- });
- const lcArray = Array.from(lcTypes).sort();
- const segArray = Array.from(segments).sort();
- // Calculate total columns for LC1 SME header
- const smeColumnsCount = segArray.length * 3; // Each SME has 3 sub-columns
- const totalColumnsCount = 3; // TOTAL has 3 sub-columns
- const lc1SmeColumnsCount = smeColumnsCount + totalColumnsCount;
- // Create LC1 SME top-level header (spans all SME segments + TOTAL)
- ws.mergeCells(startRow, currentCol, startRow, currentCol + lc1SmeColumnsCount - 1);
- const lc1SmeCell = ws.getCell(startRow, currentCol);
- lc1SmeCell.value = 'LC1 SME';
- lc1SmeCell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFE0E0E0' }
- };
- lc1SmeCell.font = { bold: true };
- lc1SmeCell.alignment = { horizontal: 'center', vertical: 'middle' };
- lc1SmeCell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- // Create SME segment headers (second level)
- segArray.forEach(seg => {
- ws.mergeCells(startRow + 1, currentCol, startRow + 1, currentCol + 2);
- const segCell = ws.getCell(startRow + 1, currentCol);
- segCell.value = seg;
- segCell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFE0E0E0' }
- };
- segCell.font = { bold: true };
- segCell.alignment = { horizontal: 'center', vertical: 'middle' };
- segCell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- // Add sub-headers for this segment
- const subColumns = ['NOA', 'Amount (IDR)', 'Amount (USD)'];
- subColumns.forEach((subCol, index) => {
- const subCell = ws.getCell(startRow + 2, currentCol + index);
- subCell.value = subCol;
- subCell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFF0F0F0' }
- };
- subCell.font = { bold: true };
- subCell.alignment = { horizontal: 'center', vertical: 'middle' };
- subCell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- });
- currentCol += 3;
- });
- // Add TOTAL header (second level)
- ws.mergeCells(startRow + 1, currentCol, startRow + 1, currentCol + 2);
- const totalCell = ws.getCell(startRow + 1, currentCol);
- totalCell.value = 'TOTAL';
- totalCell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFE0E0E0' }
- };
- totalCell.font = { bold: true };
- totalCell.alignment = { horizontal: 'center', vertical: 'middle' };
- totalCell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- // Add sub-headers for TOTAL
- const totalSubColumns = ['NOA', 'Amount (IDR)', 'Amount (USD)'];
- totalSubColumns.forEach((subCol, index) => {
- const subCell = ws.getCell(startRow + 2, currentCol + index);
- subCell.value = subCol;
- subCell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFF0F0F0' }
- };
- subCell.font = { bold: true };
- subCell.alignment = { horizontal: 'center', vertical: 'middle' };
- subCell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- });
- };
- const styleHeaders = (ws: ExcelJS.Worksheet, startRow: number, endCol: number): void => {
- // Style main headers
- for (let col = 1; col <= endCol; col++) {
- const cell = ws.getCell(startRow, col);
- cell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFE0E0E0' }
- };
- cell.font = { bold: true };
- cell.alignment = { horizontal: 'center', vertical: 'middle' };
- cell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- }
- // Style sub headers
- for (let col = 1; col <= endCol; col++) {
- const cell = ws.getCell(startRow + 1, col);
- cell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFF0F0F0' }
- };
- cell.font = { bold: true };
- cell.alignment = { horizontal: 'center', vertical: 'middle' };
- cell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- }
- };
- const mapDataToTemplate = (ws: ExcelJS.Worksheet, data: any): void => {
- const startRow = 8; // Start after 3-row headers (5, 6, 7)
- let currentRow = startRow;
- const conditions = [
- {
- name: 'Approved',
- categories: [
- 'New',
- 'Additional',
- 'Renewal',
- 'Restructure',
- 'Decrease',
- 'Other'
- ]
- },
- {
- name: 'Reject',
- categories: [
- 'New',
- 'Additional',
- 'Renewal',
- 'Restructure',
- 'Decrease',
- 'Other'
- ]
- },
- {
- name: 'Cancel',
- categories: []
- },
- {
- name: 'Total',
- categories: []
- },
- {
- name: '% Total Approve',
- categories: []
- },
- {
- name: '% Total Reject',
- categories: []
- },
- {
- name: '% Total Cancel',
- categories: []
- }
- ];
- conditions.forEach(condition => {
- // Write main condition
- ws.getCell(currentRow, 1).value = condition.name;
- styleConditionCell(ws, currentRow, 1);
- currentRow++;
- // Write subcategories
- condition.categories.forEach(category => {
- ws.getCell(currentRow, 1).value = ` - ${category}`;
- styleSubConditionCell(ws, currentRow, 1);
- currentRow++;
- });
- });
- // Fill data based on the structure
- fillDataIntoTemplate(ws, data, startRow);
- };
- const styleConditionCell = (ws: ExcelJS.Worksheet, row: number, col: number): void => {
- const cell = ws.getCell(row, col);
- cell.font = { bold: true };
- cell.fill = {
- type: 'pattern',
- pattern: 'solid',
- fgColor: { argb: 'FFE6F3FF' }
- };
- cell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- };
- const styleSubConditionCell = (ws: ExcelJS.Worksheet, row: number, col: number): void => {
- const cell = ws.getCell(row, col);
- cell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- };
- const fillDataIntoTemplate = (ws: ExcelJS.Worksheet, data: any, startRow: number): void => {
- // This function would populate the actual data into the template
- // For now, we'll add placeholder logic
- console.log('Filling data into template...', data);
- // Add borders to all data cells
- const maxRow = ws.rowCount || startRow + 20;
- const maxCol = ws.columnCount || 20;
- for (let row = startRow; row <= maxRow; row++) {
- for (let col = 2; col <= maxCol; col++) {
- const cell = ws.getCell(row, col);
- cell.border = {
- top: { style: 'thin' },
- left: { style: 'thin' },
- bottom: { style: 'thin' },
- right: { style: 'thin' }
- };
- // Add placeholder values
- if (!cell.value) {
- cell.value = 0;
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment