Uploaded image for project: 'ZK Spreadsheet'
  1. ZK Spreadsheet
  2. ZSS-1132

ExcelXlsxExporter always exports columns as custom width

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • 3.8.2
    • 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.

        1. cssRuleOverflow.png
          cssRuleOverflow.png
          12 kB
        2. customWidth2007.xlsx
          8 kB
        3. customWidth2011.xlsx
          27 kB
        4. ie9RenderingIssue.png
          ie9RenderingIssue.png
          17 kB

            henrichen henrichen
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: