diff --git a/.npmignore b/.npmignore index 0b56d83..460710e 100644 --- a/.npmignore +++ b/.npmignore @@ -5,4 +5,8 @@ /src-js /examples node_modules +CONTRIBUTING.md +.gitignore +.eslintrc +.eslintignore diff --git a/dist/ExcelPlugin/utils/DataUtil.js b/dist/ExcelPlugin/utils/DataUtil.js index de56974..65cd1dc 100644 --- a/dist/ExcelPlugin/utils/DataUtil.js +++ b/dist/ExcelPlugin/utils/DataUtil.js @@ -85,28 +85,26 @@ var excelSheetFromDataSet = function excelSheetFromDataSet(dataSet, bigHeading) return; } rowCount += ySteps; - if (bigHeading !== null && bigHeading !== void 0 && bigHeading.title) { + if (bigHeading !== null && bigHeading !== void 0 && bigHeading.title && columns.length >= 0) { + columns.forEach(function (_, index) { + var cellRef = xlsx_js_style_1.utils.encode_cell({ + c: xSteps + index, + r: rowCount + }); + fixRange(range, 0, 0, rowCount, xSteps, ySteps); + getHeaderCell(bigHeading, cellRef, ws, true, index); + }); var mergedRange = { s: { c: xSteps, - r: 0 + r: rowCount }, e: { - c: dataSetItem.columns.length - 1, - r: 0 + c: xSteps + dataSetItem.columns.length - 1, + r: rowCount } }; ws['!merges'] = [mergedRange]; - var cell = { - t: 's', - v: bigHeading.title, - s: bigHeading.style ? bigHeading.style : { - font: { - bold: true - } - } - }; - ws['A1'] = cell; rowCount += 1; } var columnsInfo = []; @@ -150,7 +148,27 @@ var excelSheetFromDataSet = function excelSheetFromDataSet(dataSet, bigHeading) return ws; }; exports.excelSheetFromDataSet = excelSheetFromDataSet; -function getHeaderCell(v, cellRef, ws) { +function getHeaderCell(v, cellRef, ws, isHeader, index) { + var bigHeadingDefualtStyle = { + font: { + bold: true, + name: "Archive", + sz: 24, + color: { + rgb: "333" + } + }, + fill: { + patternType: "solid", + fgColor: { + rgb: "FFFFFF" + } + }, + alignment: { + vertical: "center", + horizontal: "center" + } + }; var cell = { t: 's' }; @@ -159,7 +177,12 @@ function getHeaderCell(v, cellRef, ws) { bold: true } }; //if style is then use it - cell.v = v.title; + if (isHeader) { + cell.v = index === 0 ? v.title : ''; + headerCellStyle = v.style ? v.style : bigHeadingDefualtStyle; + } else { + cell.v = v.title; + } cell.t = 's'; cell.s = headerCellStyle; ws[cellRef] = cell; diff --git a/src-js/ExcelPlugin/utils/DataUtil.js b/src-js/ExcelPlugin/utils/DataUtil.js index a402da6..f9cd35d 100644 --- a/src-js/ExcelPlugin/utils/DataUtil.js +++ b/src-js/ExcelPlugin/utils/DataUtil.js @@ -71,15 +71,14 @@ const excelSheetFromDataSet = (dataSet, bigHeading) => { return; } rowCount += ySteps; - if (bigHeading?.title) { - let mergedRange = { s: { c: xSteps, r: 0 }, e: { c: dataSetItem.columns.length - 1, r: 0 } }; + if (bigHeading?.title && columns.length >= 0) { + columns.forEach((_, index) => { + const cellRef = xlsx_js_style_1.utils.encode_cell({ c: xSteps + index, r: rowCount }); + fixRange(range, 0, 0, rowCount, xSteps, ySteps); + getHeaderCell(bigHeading, cellRef, ws, true, index); + }); + const mergedRange = { s: { c: xSteps, r: rowCount }, e: { c: xSteps + dataSetItem.columns.length - 1, r: rowCount } }; ws['!merges'] = [mergedRange]; - let cell = { - t: 's', - v: bigHeading.title, - s: bigHeading.style ? bigHeading.style : { font: { bold: true } }, - }; - ws['A1'] = cell; rowCount += 1; } let columnsInfo = []; @@ -113,12 +112,23 @@ const excelSheetFromDataSet = (dataSet, bigHeading) => { return ws; }; exports.excelSheetFromDataSet = excelSheetFromDataSet; -function getHeaderCell(v, cellRef, ws) { - let cell = { +function getHeaderCell(v, cellRef, ws, isHeader, index) { + const bigHeadingDefualtStyle = { + font: { bold: true, name: "Archive", sz: 24, color: { rgb: "333" } }, + fill: { patternType: "solid", fgColor: { rgb: "FFFFFF" } }, + alignment: { vertical: "center", horizontal: "center" }, + }; + const cell = { t: 's', }; let headerCellStyle = v.style ? v.style : { font: { bold: true } }; //if style is then use it - cell.v = v.title; + if (isHeader) { + cell.v = index === 0 ? v.title : ''; + headerCellStyle = v.style ? v.style : bigHeadingDefualtStyle; + } + else { + cell.v = v.title; + } cell.t = 's'; cell.s = headerCellStyle; ws[cellRef] = cell; diff --git a/src/ExcelPlugin/utils/DataUtil.ts b/src/ExcelPlugin/utils/DataUtil.ts index b77e1c7..0b342b6 100644 --- a/src/ExcelPlugin/utils/DataUtil.ts +++ b/src/ExcelPlugin/utils/DataUtil.ts @@ -1,4 +1,4 @@ -import type { ExcelCellData, ExcelSheetCol, ExcelSheetData, ExcelValue } from "react-xlsx-wrapper"; +import type { ExcelCellData, ExcelSheetCol, ExcelSheetData, ExcelStyle, ExcelValue } from "react-xlsx-wrapper"; import { utils, SSF } from "xlsx-js-style"; import type { CellObject, WorkSheet, ColInfo, Range } from "xlsx-js-style"; @@ -78,15 +78,15 @@ const excelSheetFromDataSet = (dataSet: ExcelSheetData[], bigHeading?: ExcelShee rowCount += ySteps; - if(bigHeading?.title) { - let mergedRange: Range = { s: { c: xSteps, r: 0 }, e: { c: dataSetItem.columns.length - 1, r: 0 } }; + if(bigHeading?.title && columns.length >= 0) { + columns.forEach((_, index) => { + const cellRef = utils.encode_cell({ c: xSteps + index, r: rowCount }); + fixRange(range, 0, 0, rowCount, xSteps, ySteps); + getHeaderCell(bigHeading, cellRef, ws, true, index); + }); + + const mergedRange: Range = { s: { c: xSteps, r: rowCount }, e: { c: xSteps + dataSetItem.columns.length - 1, r: rowCount } }; ws['!merges'] = [mergedRange]; - let cell: CellObject = { - t: 's', - v: bigHeading.title, - s: bigHeading.style ? bigHeading.style : { font: { bold: true } }, - }; - ws['A1'] = cell; rowCount += 1; } @@ -126,17 +126,28 @@ const excelSheetFromDataSet = (dataSet: ExcelSheetData[], bigHeading?: ExcelShee return ws; }; -function getHeaderCell(v: ExcelSheetCol, cellRef: string, ws: WorkSheet): void { - let cell: CellObject = { +function getHeaderCell(v: ExcelSheetCol, cellRef: string, ws: WorkSheet,isHeader?: boolean,index?: number): void { + const bigHeadingDefualtStyle: ExcelStyle = { + font: { bold: true, name: "Archive", sz: 24, color: { rgb: "333" } }, + fill: { patternType: "solid", fgColor: { rgb: "FFFFFF" } }, + alignment: { vertical: "center", horizontal: "center" }, + }; + const cell: CellObject = { t: 's', }; let headerCellStyle = v.style ? v.style : { font: { bold: true } }; //if style is then use it - cell.v = v.title; + if(isHeader) { + cell.v = index === 0 ? v.title: ''; + headerCellStyle = v.style ? v.style : bigHeadingDefualtStyle; + }else { + cell.v = v.title; + } cell.t = 's'; cell.s = headerCellStyle; ws[cellRef] = cell; } + function getCell(v: ExcelCellData, cellRef: string, ws: WorkSheet): void { const isDate = v instanceof Date ;