Skip to content

Commit

Permalink
feat(bigheading): merged Big Heading is fully Supported now
Browse files Browse the repository at this point in the history
  • Loading branch information
susanta96 committed Jun 14, 2023
1 parent e70237d commit 8db1c9a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 39 deletions.
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
/src-js
/examples
node_modules
CONTRIBUTING.md
.gitignore
.eslintrc
.eslintignore

55 changes: 39 additions & 16 deletions dist/ExcelPlugin/utils/DataUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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'
};
Expand All @@ -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;
Expand Down
32 changes: 21 additions & 11 deletions src-js/ExcelPlugin/utils/DataUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 23 additions & 12 deletions src/ExcelPlugin/utils/DataUtil.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 ;

Expand Down

0 comments on commit 8db1c9a

Please sign in to comment.