@mcurros2/microm 1.1.121-0 → 1.1.123-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2977,14 +2977,81 @@ function $5be4b35862a9dc4d$export$a04f965200623e61(data, notExportableColumns, s
2977
2977
  const workbook = new (0, ($parcel$interopDefault($b4te3$exceljs))).Workbook();
2978
2978
  data.forEach((result, index)=>{
2979
2979
  const worksheet = workbook.addWorksheet(sheetNames ? sheetNames[index] : `Data ${index + 1}`);
2980
- const columns = result.Header.map((header, index)=>(notExportableColumns === null || notExportableColumns === void 0 ? void 0 : notExportableColumns.includes(index)) ? null : {
2980
+ const exportableColumnsConfig = [];
2981
+ result.Header.forEach((header, colIndex)=>{
2982
+ if (notExportableColumns === null || notExportableColumns === void 0 ? void 0 : notExportableColumns.includes(colIndex)) exportableColumnsConfig.push({
2981
2983
  header: header,
2982
- key: header
2983
- }).filter((column)=>column !== null);
2984
- worksheet.columns = columns;
2984
+ key: header,
2985
+ originalIndex: colIndex
2986
+ });
2987
+ });
2988
+ worksheet.columns = exportableColumnsConfig.map((col)=>({
2989
+ header: col.header,
2990
+ key: col.key
2991
+ }));
2992
+ exportableColumnsConfig.forEach((colInfo)=>{
2993
+ const originalColIndex = colInfo.originalIndex;
2994
+ const columnType = result.typeInfo[originalColIndex];
2995
+ const column = worksheet.getColumn(colInfo.key);
2996
+ if (column) switch(columnType){
2997
+ case "tinyint":
2998
+ case "smallint":
2999
+ case "int":
3000
+ case "bigint":
3001
+ column.numFmt = "0";
3002
+ break;
3003
+ case "float":
3004
+ case "decimal":
3005
+ case "real":
3006
+ column.numFmt = "#,##0.00";
3007
+ break;
3008
+ case "money":
3009
+ column.numFmt = "$#,##0.00";
3010
+ break;
3011
+ case "bit":
3012
+ column.numFmt = "0";
3013
+ break;
3014
+ case "date":
3015
+ column.numFmt = "yyyy-mm-dd";
3016
+ break;
3017
+ case "datetime":
3018
+ case "datetime2":
3019
+ case "smalldatetime":
3020
+ column.numFmt = "yyyy-mm-dd hh:mm:ss";
3021
+ break;
3022
+ case "time":
3023
+ column.numFmt = "hh:mm:ss";
3024
+ break;
3025
+ }
3026
+ });
2985
3027
  result.records.forEach((row)=>{
2986
- const filteredRow = row.filter((_, index)=>!(notExportableColumns === null || notExportableColumns === void 0 ? void 0 : notExportableColumns.includes(index)));
2987
- worksheet.addRow(filteredRow);
3028
+ const rowForExcel = {};
3029
+ exportableColumnsConfig.forEach((colInfo)=>{
3030
+ const originalValue = row[colInfo.originalIndex];
3031
+ let processedValue = originalValue;
3032
+ const columnType = result.typeInfo[colInfo.originalIndex];
3033
+ if (processedValue !== null) switch(columnType){
3034
+ case "date":
3035
+ case "datetime":
3036
+ case "datetime2":
3037
+ case "smalldatetime":
3038
+ case "time":
3039
+ if (typeof processedValue === "string") try {
3040
+ const dateObj = new Date(processedValue);
3041
+ if (!isNaN(dateObj.getTime())) processedValue = dateObj;
3042
+ else console.warn(`Invalid date string "${processedValue}" for column "${colInfo.header}". Keeping as string.`);
3043
+ } catch (e) {
3044
+ console.error(`Error parsing date string "${processedValue}" for column "${colInfo.header}":`, e);
3045
+ }
3046
+ break;
3047
+ case "bit":
3048
+ if (processedValue === 0) processedValue = false;
3049
+ else if (processedValue === 1) processedValue = true;
3050
+ break;
3051
+ }
3052
+ rowForExcel[colInfo.key] = processedValue;
3053
+ });
3054
+ worksheet.addRow(rowForExcel);
2988
3055
  });
2989
3056
  });
2990
3057
  const buffer = yield workbook.xlsx.writeBuffer();