Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion dist/ExcelPlugin/utils/DataUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,26 @@ var excelSheetFromDataSet = function excelSheetFromDataSet(dataSet) {

rowCount += ySteps;

var columnsWidth = [];
if (columns.length >= 0) {
columns.forEach(function (col, index) {
var cellRef = _xlsx2.default.utils.encode_cell({ c: xSteps + index, r: rowCount });
fixRange(range, 0, 0, rowCount, xSteps, ySteps);
getHeaderCell(col, cellRef, ws);
var colTitle = col;
if ((typeof col === 'undefined' ? 'undefined' : _typeof(col)) === 'object') {
colTitle = col.title;
columnsWidth.push(col.width || { wpx: 80 }); /* wch (chars), wpx (pixels) - e.g. [{wch:6},{wpx:50}] */
}
getHeaderCell(colTitle, cellRef, ws);
});

rowCount += 1;
}

if (columnsWidth.length > 0) {
ws['!cols'] = columnsWidth;
}

for (var R = 0; R != data.length; ++R, rowCount++) {
for (var C = 0; C != data[R].length; ++C) {
var cellRef = _xlsx2.default.utils.encode_cell({ c: C + xSteps, r: rowCount });
Expand Down
6 changes: 5 additions & 1 deletion examples/styled_excel_sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ const ExcelSheet = ReactExport.ExcelFile.ExcelSheet;

const multiDataSet = [
{
columns: ["Headings", "Text Style", "Colors"],
columns: [
{title: "Headings", width: {wpx: 80}},//pixels width
{title: "Text Style", width: {wch: 40}},//char width
{title: "Colors", width: {wpx: 90}},
],
data: [
[
{value: "H1", style: {font: {sz: "24", bold: true}}},
Expand Down
12 changes: 11 additions & 1 deletion src/ExcelPlugin/utils/DataUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,26 @@ const excelSheetFromDataSet = (dataSet) => {

rowCount += ySteps;

var columnsWidth = []
if (columns.length >= 0) {
columns.forEach((col, index) => {
var cellRef = XLSX.utils.encode_cell({c: xSteps + index, r: rowCount});
fixRange(range, 0, 0, rowCount, xSteps, ySteps);
getHeaderCell(col, cellRef, ws);
var colTitle = col;
if (typeof col === 'object'){
colTitle = col.title;
columnsWidth.push(col.width || {wpx:80}); /* wch (chars), wpx (pixels) - e.g. [{wch:6},{wpx:50}] */
}
getHeaderCell(colTitle, cellRef, ws);
});

rowCount += 1;
}

if (columnsWidth.length > 0){
ws['!cols'] = columnsWidth;
}

for (var R = 0; R != data.length; ++R, rowCount++) {
for (var C = 0; C != data[R].length; ++C) {
var cellRef = XLSX.utils.encode_cell({c: C + xSteps, r: rowCount});
Expand Down