From: Yegor Kozlov Date: Wed, 25 Feb 2009 19:12:53 +0000 (+0000) Subject: fixed bug #46715 - Column width from original xlsx file is discarded X-Git-Tag: REL_3_5_BETA6~98 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=039ca2fa6588a81102be953157100e6346c5d79f;p=poi.git fixed bug #46715 - Column width from original xlsx file is discarded git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@747895 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index c461c0c5bb..7e6538a435 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,12 +37,14 @@ + 46719 - fixed XSSFSheet.shiftRows to correctly preserve row heights + 46715 - preserve custom column widths across re-serialization of XSSFWorkbook 46703 - added setDisplayZeros / isDisplayZeros to common interface org.apache.poi.ss.usermodel.Sheet 46708 - added getMergedRegion(int) to common interface org.apache.poi.ss.usermodel.Sheet fixed Sheet.autoSizeColumn() to use cached formula values when processing formula cells Fixed formula parser to handle names with backslashes 46660 - added Workbook getHidden() and setHidden(boolean) - 46693 - Fixed bugs serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX + 46693 - Fixed serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX 46627 - Fixed offset of added images if Pictures stream contains pictures with zero length diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b85e04df0c..f47785ddfd 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,8 @@ + 46719 - fixed XSSFSheet.shiftRows to correctly preserve row heights + 46715 - preserve custom column widths across re-serialization of XSSFWorkbook 46703 - added setDisplayZeros / isDisplayZeros to common interface org.apache.poi.ss.usermodel.Sheet 46708 - added getMergedRegion(int) to common interface org.apache.poi.ss.usermodel.Sheet fixed Sheet.autoSizeColumn() to use cached formula values when processing formula cells diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java index 7c8ff976a1..0b55e52b7c 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java @@ -425,54 +425,4 @@ public class XSSFRow implements Row, Comparable { } setRowNum(rownum); } - - protected void updateFormulasAfterCellShift(FormulaShifter shifter) { - for(Cell c : this){ - XSSFCell cell = (XSSFCell)c; - - CTCell ctCell = cell.getCTCell(); - if(ctCell.isSetF()){ - CTCellFormula f = ctCell.getF(); - String formula = f.getStringValue(); - if(formula.length() > 0) { - String shiftedFormula = shiftFormula(formula, shifter); - if (shiftedFormula != null) { - f.setStringValue(shiftedFormula); - } - } - - if(f.isSetRef()){ //Range of cells which the formula applies to. - String ref = f.getRef(); - String shiftedRef = shiftFormula(ref, shifter); - if(shiftedRef != null) f.setRef(shiftedRef); - } - } - - } - } - - /** - * Shift a formula by the specified number of rows - *

- * Example: shiftFormula("A1+B1+C1", 3) will return "A4+B4+C4" - *

- * - * @param formula the formula to shift - * @param shifter the FormulaShifter object that operates on the parsed formula tokens - * @return the shifted formula if the formula was changed, - * null if the formula wasn't modified - */ - private String shiftFormula(String formula, FormulaShifter shifter){ - XSSFSheet sheet = getSheet(); - XSSFWorkbook wb = sheet.getWorkbook(); - int sheetIndex = wb.getSheetIndex(sheet); - XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb); - Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex); - String shiftedFmla = null; - if (shifter.adjustFormula(ptgs, sheetIndex)) { - shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs); - } - return shiftedFmla; - } - } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java index 30da5efd42..d4e4456c61 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java @@ -219,13 +219,14 @@ public class ColumnHelper { } public void setColumnAttributes(CTCol fromCol, CTCol toCol) { - toCol.setWidth(fromCol.getWidth()); - toCol.setHidden(fromCol.getHidden()); - toCol.setBestFit(fromCol.getBestFit()); - toCol.setStyle(fromCol.getStyle()); - if(fromCol.getOutlineLevel()!=0){ - toCol.setOutlineLevel(fromCol.getOutlineLevel()); - } + if(fromCol.isSetBestFit()) toCol.setBestFit(fromCol.getBestFit()); + if(fromCol.isSetCustomWidth()) toCol.setCustomWidth(fromCol.getCustomWidth()); + if(fromCol.isSetHidden()) toCol.setHidden(fromCol.getHidden()); + if(fromCol.isSetStyle()) toCol.setStyle(fromCol.getStyle()); + if(fromCol.isSetWidth()) toCol.setWidth(fromCol.getWidth()); + if(fromCol.isSetCollapsed()) toCol.setCollapsed(fromCol.getCollapsed()); + if(fromCol.isSetPhonetic()) toCol.setPhonetic(fromCol.getPhonetic()); + if(fromCol.isSetOutlineLevel()) toCol.setOutlineLevel(fromCol.getOutlineLevel()); } public void setColBestFit(long index, boolean bestFit) {