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
This commit is contained in:
Yegor Kozlov 2009-02-25 19:12:53 +00:00
parent 7c6706750f
commit 039ca2fa65
4 changed files with 13 additions and 58 deletions

View File

@ -37,12 +37,14 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta6" date="2009-??-??">
<action dev="POI-DEVELOPERS" type="fix">46719 - fixed XSSFSheet.shiftRows to correctly preserve row heights</action>
<action dev="POI-DEVELOPERS" type="fix">46715 - preserve custom column widths across re-serialization of XSSFWorkbook</action>
<action dev="POI-DEVELOPERS" type="add">46703 - added setDisplayZeros / isDisplayZeros to common interface org.apache.poi.ss.usermodel.Sheet</action>
<action dev="POI-DEVELOPERS" type="add">46708 - added getMergedRegion(int) to common interface org.apache.poi.ss.usermodel.Sheet</action>
<action dev="POI-DEVELOPERS" type="fix">fixed Sheet.autoSizeColumn() to use cached formula values when processing formula cells </action>
<action dev="POI-DEVELOPERS" type="fix">Fixed formula parser to handle names with backslashes</action>
<action dev="POI-DEVELOPERS" type="add">46660 - added Workbook getHidden() and setHidden(boolean)</action>
<action dev="POI-DEVELOPERS" type="fix">46693 - Fixed bugs serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX</action>
<action dev="POI-DEVELOPERS" type="fix">46693 - Fixed serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX</action>
<action dev="POI-DEVELOPERS" type="fix">46627 - Fixed offset of added images if Pictures stream contains pictures with zero length</action>
</release>
<release version="3.5-beta5" date="2009-02-19">

View File

@ -34,6 +34,8 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta6" date="2009-??-??">
<action dev="POI-DEVELOPERS" type="fix">46719 - fixed XSSFSheet.shiftRows to correctly preserve row heights</action>
<action dev="POI-DEVELOPERS" type="fix">46715 - preserve custom column widths across re-serialization of XSSFWorkbook</action>
<action dev="POI-DEVELOPERS" type="add">46703 - added setDisplayZeros / isDisplayZeros to common interface org.apache.poi.ss.usermodel.Sheet</action>
<action dev="POI-DEVELOPERS" type="add">46708 - added getMergedRegion(int) to common interface org.apache.poi.ss.usermodel.Sheet</action>
<action dev="POI-DEVELOPERS" type="fix">fixed Sheet.autoSizeColumn() to use cached formula values when processing formula cells </action>

View File

@ -425,54 +425,4 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
}
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
* <p>
* Example: shiftFormula("A1+B1+C1", 3) will return "A4+B4+C4"
* </p>
*
* @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,
* <code>null</code> 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;
}
}

View File

@ -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) {