@shival99/z-ui 2.0.34 → 2.0.36

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.
@@ -594,8 +594,7 @@ class ZExcelService {
594
594
  header: headerText,
595
595
  accessorKey: col.accessorKey,
596
596
  accessorFn: col.accessorFn ? (row) => col.accessorFn(row) : undefined,
597
- width: col.size,
598
- autoFit: !col.size,
597
+ autoFit: true,
599
598
  align: headerConfig.align,
600
599
  visible: typeof col.visible === 'boolean' ? col.visible : true,
601
600
  };
@@ -813,7 +812,8 @@ class ZExcelService {
813
812
  sheet.eachRow((row) => {
814
813
  const cell = row.getCell(colNumber);
815
814
  if (cell.value) {
816
- const cellWidth = ZExcelService._calculateCellWidth(cell, String(cell.value));
815
+ const cellWidth = ZExcelService._calculateCellWidth(cell, String(cell.value)) /
816
+ ZExcelService._getMergedColumnSpan(sheet, row, cell);
817
817
  maxWidth = Math.max(maxWidth, cellWidth);
818
818
  }
819
819
  });
@@ -830,7 +830,8 @@ class ZExcelService {
830
830
  sheet.eachRow((row) => {
831
831
  const cell = row.getCell(colNumber);
832
832
  if (cell.value) {
833
- const cellWidth = ZExcelService._calculateCellWidth(cell, String(cell.value));
833
+ const cellWidth = ZExcelService._calculateCellWidth(cell, String(cell.value)) /
834
+ ZExcelService._getMergedColumnSpan(sheet, row, cell);
834
835
  maxWidth = Math.max(maxWidth, cellWidth);
835
836
  }
836
837
  });
@@ -838,6 +839,19 @@ class ZExcelService {
838
839
  column.width = calculatedWidth;
839
840
  }
840
841
  }
842
+ static _getMergedColumnSpan(sheet, row, cell) {
843
+ if (!cell.isMerged) {
844
+ return 1;
845
+ }
846
+ let colSpan = 0;
847
+ for (let colNumber = 1; colNumber <= sheet.columnCount; colNumber++) {
848
+ const mergedCell = row.getCell(colNumber);
849
+ if (mergedCell.address === cell.master.address || mergedCell.isMergedTo(cell.master)) {
850
+ colSpan++;
851
+ }
852
+ }
853
+ return Math.max(1, colSpan);
854
+ }
841
855
  static _calculateCellWidth(cell, text) {
842
856
  const font = cell.font || {};
843
857
  const fontSize = font.size || Z_EXCEL_DEFAULT_CONFIG.font.size;