Skip to content

Commit 8db1c9a

Browse files
committed
feat(bigheading): merged Big Heading is fully Supported now
1 parent e70237d commit 8db1c9a

4 files changed

Lines changed: 87 additions & 39 deletions

File tree

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
/src-js
66
/examples
77
node_modules
8+
CONTRIBUTING.md
9+
.gitignore
10+
.eslintrc
11+
.eslintignore
812

dist/ExcelPlugin/utils/DataUtil.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,26 @@ var excelSheetFromDataSet = function excelSheetFromDataSet(dataSet, bigHeading)
8585
return;
8686
}
8787
rowCount += ySteps;
88-
if (bigHeading !== null && bigHeading !== void 0 && bigHeading.title) {
88+
if (bigHeading !== null && bigHeading !== void 0 && bigHeading.title && columns.length >= 0) {
89+
columns.forEach(function (_, index) {
90+
var cellRef = xlsx_js_style_1.utils.encode_cell({
91+
c: xSteps + index,
92+
r: rowCount
93+
});
94+
fixRange(range, 0, 0, rowCount, xSteps, ySteps);
95+
getHeaderCell(bigHeading, cellRef, ws, true, index);
96+
});
8997
var mergedRange = {
9098
s: {
9199
c: xSteps,
92-
r: 0
100+
r: rowCount
93101
},
94102
e: {
95-
c: dataSetItem.columns.length - 1,
96-
r: 0
103+
c: xSteps + dataSetItem.columns.length - 1,
104+
r: rowCount
97105
}
98106
};
99107
ws['!merges'] = [mergedRange];
100-
var cell = {
101-
t: 's',
102-
v: bigHeading.title,
103-
s: bigHeading.style ? bigHeading.style : {
104-
font: {
105-
bold: true
106-
}
107-
}
108-
};
109-
ws['A1'] = cell;
110108
rowCount += 1;
111109
}
112110
var columnsInfo = [];
@@ -150,7 +148,27 @@ var excelSheetFromDataSet = function excelSheetFromDataSet(dataSet, bigHeading)
150148
return ws;
151149
};
152150
exports.excelSheetFromDataSet = excelSheetFromDataSet;
153-
function getHeaderCell(v, cellRef, ws) {
151+
function getHeaderCell(v, cellRef, ws, isHeader, index) {
152+
var bigHeadingDefualtStyle = {
153+
font: {
154+
bold: true,
155+
name: "Archive",
156+
sz: 24,
157+
color: {
158+
rgb: "333"
159+
}
160+
},
161+
fill: {
162+
patternType: "solid",
163+
fgColor: {
164+
rgb: "FFFFFF"
165+
}
166+
},
167+
alignment: {
168+
vertical: "center",
169+
horizontal: "center"
170+
}
171+
};
154172
var cell = {
155173
t: 's'
156174
};
@@ -159,7 +177,12 @@ function getHeaderCell(v, cellRef, ws) {
159177
bold: true
160178
}
161179
}; //if style is then use it
162-
cell.v = v.title;
180+
if (isHeader) {
181+
cell.v = index === 0 ? v.title : '';
182+
headerCellStyle = v.style ? v.style : bigHeadingDefualtStyle;
183+
} else {
184+
cell.v = v.title;
185+
}
163186
cell.t = 's';
164187
cell.s = headerCellStyle;
165188
ws[cellRef] = cell;

src-js/ExcelPlugin/utils/DataUtil.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,14 @@ const excelSheetFromDataSet = (dataSet, bigHeading) => {
7171
return;
7272
}
7373
rowCount += ySteps;
74-
if (bigHeading?.title) {
75-
let mergedRange = { s: { c: xSteps, r: 0 }, e: { c: dataSetItem.columns.length - 1, r: 0 } };
74+
if (bigHeading?.title && columns.length >= 0) {
75+
columns.forEach((_, index) => {
76+
const cellRef = xlsx_js_style_1.utils.encode_cell({ c: xSteps + index, r: rowCount });
77+
fixRange(range, 0, 0, rowCount, xSteps, ySteps);
78+
getHeaderCell(bigHeading, cellRef, ws, true, index);
79+
});
80+
const mergedRange = { s: { c: xSteps, r: rowCount }, e: { c: xSteps + dataSetItem.columns.length - 1, r: rowCount } };
7681
ws['!merges'] = [mergedRange];
77-
let cell = {
78-
t: 's',
79-
v: bigHeading.title,
80-
s: bigHeading.style ? bigHeading.style : { font: { bold: true } },
81-
};
82-
ws['A1'] = cell;
8382
rowCount += 1;
8483
}
8584
let columnsInfo = [];
@@ -113,12 +112,23 @@ const excelSheetFromDataSet = (dataSet, bigHeading) => {
113112
return ws;
114113
};
115114
exports.excelSheetFromDataSet = excelSheetFromDataSet;
116-
function getHeaderCell(v, cellRef, ws) {
117-
let cell = {
115+
function getHeaderCell(v, cellRef, ws, isHeader, index) {
116+
const bigHeadingDefualtStyle = {
117+
font: { bold: true, name: "Archive", sz: 24, color: { rgb: "333" } },
118+
fill: { patternType: "solid", fgColor: { rgb: "FFFFFF" } },
119+
alignment: { vertical: "center", horizontal: "center" },
120+
};
121+
const cell = {
118122
t: 's',
119123
};
120124
let headerCellStyle = v.style ? v.style : { font: { bold: true } }; //if style is then use it
121-
cell.v = v.title;
125+
if (isHeader) {
126+
cell.v = index === 0 ? v.title : '';
127+
headerCellStyle = v.style ? v.style : bigHeadingDefualtStyle;
128+
}
129+
else {
130+
cell.v = v.title;
131+
}
122132
cell.t = 's';
123133
cell.s = headerCellStyle;
124134
ws[cellRef] = cell;

src/ExcelPlugin/utils/DataUtil.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ExcelCellData, ExcelSheetCol, ExcelSheetData, ExcelValue } from "react-xlsx-wrapper";
1+
import type { ExcelCellData, ExcelSheetCol, ExcelSheetData, ExcelStyle, ExcelValue } from "react-xlsx-wrapper";
22
import { utils, SSF } from "xlsx-js-style";
33
import type { CellObject, WorkSheet, ColInfo, Range } from "xlsx-js-style";
44

@@ -78,15 +78,15 @@ const excelSheetFromDataSet = (dataSet: ExcelSheetData[], bigHeading?: ExcelShee
7878

7979
rowCount += ySteps;
8080

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 } };
8389
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;
9090
rowCount += 1;
9191
}
9292

@@ -126,17 +126,28 @@ const excelSheetFromDataSet = (dataSet: ExcelSheetData[], bigHeading?: ExcelShee
126126
return ws;
127127
};
128128

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 = {
131136
t: 's',
132137
};
133138
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+
}
135145
cell.t = 's';
136146
cell.s = headerCellStyle;
137147
ws[cellRef] = cell;
138148
}
139149

150+
140151
function getCell(v: ExcelCellData, cellRef: string, ws: WorkSheet): void {
141152
const isDate = v instanceof Date ;
142153

0 commit comments

Comments
 (0)