-
Bug
-
Resolution: Fixed
-
Critical
-
3.8.1
-
None
-
Security Level: Jean
-
None
-
Sprint 1
Problem description
please check attached images.
Root Cause
protected void exportColumnArray(SSheet sheet, Sheet poiSheet, SColumnArray columnArr) { XSSFSheet xssfSheet = (XSSFSheet) poiSheet; ... col.setCustomWidth(true); ... }
Debug info
- By checking columWidth2007.xlsx, columnWidth2011.xlsx, only custom width column has
Workaround
public class PatchedExcelXlsxExporter extends ExcelXlsxExporter{ @Override protected void exportColumnArray(SSheet sheet, Sheet poiSheet, SColumnArray columnArr) { XSSFSheet xssfSheet = (XSSFSheet) poiSheet; CTWorksheet ctSheet = xssfSheet.getCTWorksheet(); if(xssfSheet.getCTWorksheet().sizeOfColsArray() == 0) { xssfSheet.getCTWorksheet().addNewCols(); } CTCol col = ctSheet.getColsArray(0).addNewCol(); col.setMin(columnArr.getIndex()+1); col.setMax(columnArr.getLastIndex()+1); col.setStyle(toPOICellStyle(columnArr.getCellStyle()).getIndex()); col.setCustomWidth(sheet.getDefaultColumnWidth() != columnArr.getWidth()); //patch col.setWidth(UnitUtil.pxToCTChar(columnArr.getWidth(), AbstractExcelImporter.CHRACTER_WIDTH)); col.setHidden(columnArr.isHidden()); } }
But for actual solution, we would consider custom width flag like:
col.setCustomWidth(columnArr.isCustomWidth() || sheet.getDefaultColumnWidth() != columnArr.getWidth());
Because users may adjust the width to equal to default width.