datainout
Version:
Import and reports data
134 lines (132 loc) • 5.04 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/helpers/exceljs-exporter-helper.ts
var exceljs_exporter_helper_exports = {};
__export(exceljs_exporter_helper_exports, {
ExceljsExporterHelper: () => ExceljsExporterHelper
});
module.exports = __toCommonJS(exceljs_exporter_helper_exports);
var ExceljsExporterHelper = class {
constructor(templateManager, useStyle) {
this.templateManager = templateManager;
this.useStyle = useStyle != null ? useStyle : false;
}
filterGroupCellDesc(opts, sheetIndex) {
return this.templateManager.GroupCells[opts];
}
getSheetInformation() {
return this.templateManager.SheetInformation;
}
setCell(rowData, cellOpt, cell) {
cell.style = cellOpt.style;
if (cellOpt.formula) {
cell.value = {
formula: cellOpt.formula
};
} else {
let value = cellOpt.isVariable ? rowData[cellOpt.value.fieldName] : cellOpt.value.hardValue;
if (cellOpt.formatValue) value = cellOpt.formatValue(value);
cell.value = value;
}
return cell;
}
setTitleTable(cellsOpts, workSheet) {
const groupTitles = cellsOpts.sort((a, b) => b.fullAddress.row - a.fullAddress.row).reduce((acc, value) => {
const row = value.fullAddress.row;
acc[row] = acc[row] ? [...acc[row], value] : [value];
return acc;
}, {});
const titelTables = [];
for (const [rowIndex, footers] of Object.entries(groupTitles)) {
const row = workSheet.addRow([]);
footers.forEach((footer) => this.setCell({}, footer, row.getCell(footer.fullAddress.col)));
titelTables.push(row);
}
return titelTables;
}
addRow(value, cellsOpts, workSheet) {
const row = workSheet.addRow([]);
for (let i = 0; i < cellsOpts.length; i++) {
const cellsOpt = cellsOpts[i];
const cell = row.getCell(cellsOpt.fullAddress.col);
this.setCell(value, cellsOpt, cell);
}
return row;
}
addRows(values, cellsOpts, workSheet) {
const rows = values.map((value) => {
const row = workSheet.addRow([]);
for (let i = 0; i < cellsOpts.length; i++) {
const cellsOpt = cellsOpts[i];
const cell = row.getCell(cellsOpt.fullAddress.col);
this.setCell(value, cellsOpt, cell);
}
if (!this.useStyle) row.commit();
return row;
});
return rows;
}
setHeader(header, cellsOpts, beginTableAt, workSheet) {
const rowHeaders = [];
for (let i = 1; i <= beginTableAt; i++) {
const row = workSheet.addRow([]);
const formats = cellsOpts.filter((e) => e.fullAddress.row === i);
formats.forEach((format) => this.setCell(header != null ? header : {}, format, row.getCell(format.fullAddress.col)));
rowHeaders.push(row);
}
return rowHeaders;
}
setFooter(value, cellsOpts, workSheet) {
const groupFooter = cellsOpts.sort((a, b) => b.fullAddress.row - a.fullAddress.row).reduce((acc, value2) => {
const row = value2.fullAddress.row;
acc[row] = acc[row] ? [...acc[row], value2] : [value2];
return acc;
}, {});
const _footers = [];
for (const [rowIndex, footers] of Object.entries(groupFooter)) {
const row = workSheet.addRow([]);
footers.forEach((footer) => this.setCell(value != null ? value : {}, footer, row.getCell(footer.fullAddress.col)));
_footers.push(row);
}
return _footers;
}
mergeCells(sheet, sheetFormat) {
if (sheetFormat.merges) {
const merges = sheetFormat.merges;
Object.keys(sheetFormat.merges).forEach((masterCell) => {
const { top, left, right, bottom } = merges[masterCell].model;
sheet.mergeCells(top, left, bottom, right);
});
}
}
setWidthsAndHeights(sheet, sheetFormat) {
var _a;
(_a = sheetFormat.columnWidths) == null ? void 0 : _a.forEach((colW, i) => {
if ((sheet == null ? void 0 : sheet.columns) && (sheet == null ? void 0 : sheet.columns[i]) && colW) sheet.columns[i].width = colW;
});
const rowHeights = sheetFormat.rowHeights;
Object.keys(rowHeights).forEach((rowIndex, i) => {
if (rowHeights[rowIndex]) sheet.getRow(rowHeights[i]).height = rowHeights[rowIndex];
});
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ExceljsExporterHelper
});