|
@@ -43,7 +43,7 @@ function convertType(value: any, type: any) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const ExcelWriter = {
|
|
const ExcelWriter = {
|
|
- async getColumnNames() {
|
|
|
|
|
|
+ getColumnNames() {
|
|
return columnNames;
|
|
return columnNames;
|
|
},
|
|
},
|
|
async outputExcel(headerConfig: Array<any>, data: Array<any>, options: Options) {
|
|
async outputExcel(headerConfig: Array<any>, data: Array<any>, options: Options) {
|
|
@@ -77,6 +77,77 @@ const ExcelWriter = {
|
|
//excelData = [excelDataHeader, ...excelDataBody];
|
|
//excelData = [excelDataHeader, ...excelDataBody];
|
|
await this._output(excelData, options);
|
|
await this._output(excelData, options);
|
|
},
|
|
},
|
|
|
|
+
|
|
|
|
+ async outputExcelByData(data: Array<any>, options: Options) {
|
|
|
|
+ let columnArray = this.getColumnNames(); //await ExcelWriter.getColumnNames();
|
|
|
|
+ console.log("#debug#🚀 ~ file: test.vue:36 ~ testOne2Two ~ columnArray:", columnArray);
|
|
|
|
+ //rowSpan span
|
|
|
|
+ let arrayOrg = data;
|
|
|
|
+ console.log("#debug#🚀 ~ file: test.vue:42 ~ testOne2Two ~ arrayOrg:", JSON.stringify(arrayOrg));
|
|
|
|
+ let maxRow = 0;
|
|
|
|
+ let maxColumn = 0;
|
|
|
|
+ arrayOrg.forEach((item) => {
|
|
|
|
+ let letters = item.poi.replace(/[^a-z]/gi, "").toUpperCase();
|
|
|
|
+ let num = item.poi.replace(/\D/g, "");
|
|
|
|
+ let row = columnArray.indexOf(letters);
|
|
|
|
+ if (row > maxRow) {
|
|
|
|
+ maxRow = row;
|
|
|
|
+ }
|
|
|
|
+ let column = num;
|
|
|
|
+ if (column > maxColumn) {
|
|
|
|
+ maxColumn = column;
|
|
|
|
+ }
|
|
|
|
+ console.log("#debug#🚀 ~ file: test.vue:47 ~ arrayOrg.forEach ~ num:", num);
|
|
|
|
+ console.log("#debug#🚀 ~ file: test.vue:46 ~ testOne2Two ~ letters:", letters, columnArray.indexOf(letters));
|
|
|
|
+ });
|
|
|
|
+ let excelData = [] as any;
|
|
|
|
+ console.log("#debug#🚀 ~ file: test.vue:67 ~ testOne2Two ~ maxRow:", maxRow);
|
|
|
|
+ console.log("#debug#🚀 ~ file: test.vue:70 ~ testOne2Two ~ maxColumn:", maxColumn);
|
|
|
|
+ for (let i = 0; i < maxColumn; i++) {
|
|
|
|
+ excelData[i] = [];
|
|
|
|
+ for (let j = 0; j <= maxRow; j++) {
|
|
|
|
+ excelData[i][j] = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ console.log("#debug#🚀 ~ file: test.vue:75 ~ arrayOrg.forEach ~ excelData:", excelData);
|
|
|
|
+ arrayOrg.forEach((item) => {
|
|
|
|
+ let letters = item.poi.replace(/[^a-z]/gi, "").toUpperCase();
|
|
|
|
+ let num = item.poi.replace(/\D/g, "");
|
|
|
|
+ let row = columnArray.indexOf(letters);
|
|
|
|
+ excelData[num - 1][row] = item;
|
|
|
|
+ });
|
|
|
|
+ console.log("#debug#🚀 ~ file: test.vue:75 ~ arrayOrg.forEach ~ excelData:", excelData);
|
|
|
|
+
|
|
|
|
+ console.log("#debug#🚀 ~ file: ExcelWriter.ts:82 ~ outputExcelByData ~ options:", options);
|
|
|
|
+ if (options?.border) {
|
|
|
|
+ //如果有边框
|
|
|
|
+ excelData.forEach((row: any, rowIndex: number) => {
|
|
|
|
+ console.log("#debug#🚀 ~ file: ExcelWriter.ts:87 ~ data.forEach ~ row:", row);
|
|
|
|
+ row.forEach((cell: any, cellIndex: number) => {
|
|
|
|
+ console.log("#debug#🚀 ~ file: ExcelWriter.ts:87 ~ data.forEach ~ cell:", cell);
|
|
|
|
+ let borderColor = "#000000";
|
|
|
|
+ if (cell) {
|
|
|
|
+ if (options?.borderColor) {
|
|
|
|
+ borderColor = options?.borderColor;
|
|
|
|
+ }
|
|
|
|
+ if (cell?.borderColor) {
|
|
|
|
+ borderColor = cell?.borderColor;
|
|
|
|
+ }
|
|
|
|
+ cell.borderColor = borderColor;
|
|
|
|
+ // cell.borderColor = options?.borderColor ?? "#000000";
|
|
|
|
+ console.log("#debug#🚀 ~ file: ExcelWriter.ts:87 ~ data.forEach ~ cell.borderColor:", cell.borderColor);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ console.log("#debug#🚀 ~ file: ExcelWriter.ts:90 ~ data.forEach ~ data:", data);
|
|
|
|
+ }
|
|
|
|
+ if (!options.hasOwnProperty("fileName")) {
|
|
|
|
+ // 对象 options 上没有名为 "fileName" 的属性
|
|
|
|
+ options.fileName = "导出.xlsx";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ await writeXlsxFile(excelData, options);
|
|
|
|
+ },
|
|
//==================私有方法============================
|
|
//==================私有方法============================
|
|
|
|
|
|
/**
|
|
/**
|