ASF Bugzilla – Attachment 30563 Details for
Bug 52186
groupColumn with setColumnWidth not working
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to set column width when grouping columns
poi-52186.patch (text/plain), 3.96 KB, created by
vladk
on 2013-07-07 18:40:51 UTC
(
hide
)
Description:
Patch to set column width when grouping columns
Filename:
MIME Type:
Creator:
vladk
Created:
2013-07-07 18:40:51 UTC
Size:
3.96 KB
patch
obsolete
>Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (revision 1499916) >+++ src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (working copy) >@@ -1218,8 +1218,21 @@ > index=(int)col.getMax(); > } > worksheet.setColsArray(0,ctCols); >+ setColWidthAttribute(ctCols); > setSheetFormatPrOutlineLevelCol(); > } >+ >+ /** >+ * Do not leave the width attribute undefined (see #52186). >+ */ >+ private void setColWidthAttribute(CTCols ctCols) { >+ for (CTCol col : ctCols.getColList()) { >+ if (!col.isSetWidth()) { >+ col.setWidth(getDefaultColumnWidth()); >+ col.setCustomWidth(false); >+ } >+ } >+ } > > /** > * Tie a range of cell together so that they can be collapsed or expanded >@@ -1249,11 +1262,10 @@ > } > > >- @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support > private short getMaxOutlineLevelCols() { > CTCols ctCols = worksheet.getColsArray(0); > short outlineLevel = 0; >- for (CTCol col : ctCols.getColArray()) { >+ for (CTCol col : ctCols.getColList()) { > outlineLevel = col.getOutlineLevel() > outlineLevel ? col.getOutlineLevel() : outlineLevel; > } > return outlineLevel; >Index: src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (revision 1499916) >+++ src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (working copy) >@@ -53,6 +53,7 @@ > import org.apache.poi.xssf.XSSFTestDataSamples; > import org.apache.poi.xssf.model.CalculationChain; > import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; >+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; > >@@ -1356,4 +1357,26 @@ > } > workbook.getCreationHelper().createFormulaEvaluator().evaluateAll(); > } >+ >+ /** >+ * Tests that POI doesn't produce "col" elements without "width" attribute. >+ */ >+ public void test52186() { >+ XSSFWorkbook wb = new XSSFWorkbook(); >+ XSSFSheet sheet = wb.createSheet("test"); >+ >+ sheet.setColumnWidth(4, 5000); >+ sheet.setColumnWidth(5, 5000); >+ >+ sheet.groupColumn((short) 4, (short) 7); >+ sheet.groupColumn((short) 9, (short) 12); >+ >+ wb = XSSFTestDataSamples.writeOutAndReadBack(wb); >+ sheet = wb.getSheet("test"); >+ >+ CTCols cols = sheet.getCTWorksheet().getColsArray(0); >+ for (CTCol col : cols.getColList()) { >+ assertTrue("Col width attribute is unset: " + col.toString(), col.isSetWidth()); >+ } >+ } > } >Index: src/examples/src/org/apache/poi/xssf/usermodel/examples/Outlining.java >=================================================================== >--- src/examples/src/org/apache/poi/xssf/usermodel/examples/Outlining.java (revision 1499916) >+++ src/examples/src/org/apache/poi/xssf/usermodel/examples/Outlining.java (working copy) >@@ -27,10 +27,23 @@ > > public static void main(String[]args) throws Exception{ > Outlining o=new Outlining(); >+ o.groupColumn(); > o.groupRowColumn(); > o.collapseExpandRowColumn(); > } > >+ private void groupColumn() throws Exception{ >+ Workbook wb = new XSSFWorkbook(); >+ Sheet sheet1 = wb.createSheet("new sheet"); >+ >+ sheet1.setColumnWidth(4, 20*256); >+ sheet1.groupColumn( (short)4, (short)7 ); >+ >+ FileOutputStream fileOut = new FileOutputStream("outlining-columns.xlsx"); >+ wb.write(fileOut); >+ fileOut.close(); >+ >+ } > > private void groupRowColumn() throws Exception{ > Workbook wb = new XSSFWorkbook();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 52186
:
27938
| 30563