|
1 | | -import type { ExcelCellData, ExcelSheetCol, ExcelSheetData, ExcelValue } from "react-xlsx-wrapper"; |
| 1 | +import type { ExcelCellData, ExcelSheetCol, ExcelSheetData, ExcelStyle, ExcelValue } from "react-xlsx-wrapper"; |
2 | 2 | import { utils, SSF } from "xlsx-js-style"; |
3 | 3 | import type { CellObject, WorkSheet, ColInfo, Range } from "xlsx-js-style"; |
4 | 4 |
|
@@ -78,15 +78,15 @@ const excelSheetFromDataSet = (dataSet: ExcelSheetData[], bigHeading?: ExcelShee |
78 | 78 |
|
79 | 79 | rowCount += ySteps; |
80 | 80 |
|
81 | | - if(bigHeading?.title) { |
82 | | - let mergedRange: Range = { s: { c: xSteps, r: 0 }, e: { c: dataSetItem.columns.length - 1, r: 0 } }; |
| 81 | + if(bigHeading?.title && columns.length >= 0) { |
| 82 | + columns.forEach((_, index) => { |
| 83 | + const cellRef = utils.encode_cell({ c: xSteps + index, r: rowCount }); |
| 84 | + fixRange(range, 0, 0, rowCount, xSteps, ySteps); |
| 85 | + getHeaderCell(bigHeading, cellRef, ws, true, index); |
| 86 | + }); |
| 87 | + |
| 88 | + const mergedRange: Range = { s: { c: xSteps, r: rowCount }, e: { c: xSteps + dataSetItem.columns.length - 1, r: rowCount } }; |
83 | 89 | ws['!merges'] = [mergedRange]; |
84 | | - let cell: CellObject = { |
85 | | - t: 's', |
86 | | - v: bigHeading.title, |
87 | | - s: bigHeading.style ? bigHeading.style : { font: { bold: true } }, |
88 | | - }; |
89 | | - ws['A1'] = cell; |
90 | 90 | rowCount += 1; |
91 | 91 | } |
92 | 92 |
|
@@ -126,17 +126,28 @@ const excelSheetFromDataSet = (dataSet: ExcelSheetData[], bigHeading?: ExcelShee |
126 | 126 | return ws; |
127 | 127 | }; |
128 | 128 |
|
129 | | -function getHeaderCell(v: ExcelSheetCol, cellRef: string, ws: WorkSheet): void { |
130 | | - let cell: CellObject = { |
| 129 | +function getHeaderCell(v: ExcelSheetCol, cellRef: string, ws: WorkSheet,isHeader?: boolean,index?: number): void { |
| 130 | + const bigHeadingDefualtStyle: ExcelStyle = { |
| 131 | + font: { bold: true, name: "Archive", sz: 24, color: { rgb: "333" } }, |
| 132 | + fill: { patternType: "solid", fgColor: { rgb: "FFFFFF" } }, |
| 133 | + alignment: { vertical: "center", horizontal: "center" }, |
| 134 | + }; |
| 135 | + const cell: CellObject = { |
131 | 136 | t: 's', |
132 | 137 | }; |
133 | 138 | let headerCellStyle = v.style ? v.style : { font: { bold: true } }; //if style is then use it |
134 | | - cell.v = v.title; |
| 139 | + if(isHeader) { |
| 140 | + cell.v = index === 0 ? v.title: ''; |
| 141 | + headerCellStyle = v.style ? v.style : bigHeadingDefualtStyle; |
| 142 | + }else { |
| 143 | + cell.v = v.title; |
| 144 | + } |
135 | 145 | cell.t = 's'; |
136 | 146 | cell.s = headerCellStyle; |
137 | 147 | ws[cellRef] = cell; |
138 | 148 | } |
139 | 149 |
|
| 150 | + |
140 | 151 | function getCell(v: ExcelCellData, cellRef: string, ws: WorkSheet): void { |
141 | 152 | const isDate = v instanceof Date ; |
142 | 153 |
|
|
0 commit comments