ASF Bugzilla – Attachment 31403 Details for
Bug 56274
SXSSF produces corrupt xlsx file from valid xlsx template
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for fixing the bug (and other minor optimizations)
fix_for_bug_#56274_(and_other_minor_optimizations).patch (text/plain), 24.67 KB, created by
Yaniv Kunda
on 2014-03-19 09:26:59 UTC
(
hide
)
Description:
Patch for fixing the bug (and other minor optimizations)
Filename:
MIME Type:
Creator:
Yaniv Kunda
Created:
2014-03-19 09:26:59 UTC
Size:
24.67 KB
patch
obsolete
>Index: ../../repository/SupportingLibraries/poi-3.10-wc/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP ><+>/* ====================================================================\r\n Licensed to the Apache Software Foundation (ASF) under one or more\r\n contributor license agreements. See the NOTICE file distributed with\r\n this work for additional information regarding copyright ownership.\r\n The ASF licenses this file to You under the Apache License, Version 2.0\r\n (the \"License\"); you may not use this file except in compliance with\r\n the License. You may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\n Unless required by applicable law or agreed to in writing, software\r\n distributed under the License is distributed on an \"AS IS\" BASIS,\r\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n See the License for the specific language governing permissions and\r\n limitations under the License.\r\n==================================================================== */\r\n\r\npackage org.apache.poi.xssf.usermodel;\r\n\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.OutputStream;\r\nimport java.util.Arrays;\r\nimport java.util.List;\r\nimport java.util.Vector;\r\n\r\nimport org.apache.poi.POIXMLDocumentPart;\r\nimport org.apache.poi.openxml4j.opc.PackagePart;\r\nimport org.apache.poi.openxml4j.opc.PackageRelationship;\r\nimport org.apache.poi.ss.util.CellReference;\r\nimport org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;\r\nimport org.apache.xmlbeans.XmlException;\r\nimport org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable;\r\nimport org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn;\r\nimport org.openxmlformats.schemas.spreadsheetml.x2006.main.TableDocument;\r\n\r\n/**\r\n * \r\n * This class implements the Table Part (Open Office XML Part 4:\r\n * chapter 3.5.1)\r\n * \r\n * This implementation works under the assumption that a table contains mappings to a subtree of an XML.\r\n * The root element of this subtree an occur multiple times (one for each row of the table). The child nodes\r\n * of the root element can be only attributes or element with maxOccurs=1 property set\r\n * \r\n *\r\n * @author Roberto Manicardi\r\n */\r\npublic class XSSFTable extends POIXMLDocumentPart {\r\n\r\n\tprivate CTTable ctTable;\r\n\tprivate List<XSSFXmlColumnPr> xmlColumnPr;\r\n\tprivate CellReference startCellReference;\r\n\tprivate CellReference endCellReference;\t\r\n\tprivate String commonXPath; \r\n\t\r\n\t\r\n\tpublic XSSFTable() {\r\n\t\tsuper();\r\n\t\tctTable = CTTable.Factory.newInstance();\r\n\r\n\t}\r\n\r\n\tpublic XSSFTable(PackagePart part, PackageRelationship rel)\r\n\t\t\tthrows IOException {\r\n\t\tsuper(part, rel);\r\n\t\treadFrom(part.getInputStream());\r\n\t}\r\n\r\n\tpublic void readFrom(InputStream is) throws IOException {\r\n\t\ttry {\r\n\t\t\tTableDocument doc = TableDocument.Factory.parse(is);\r\n\t\t\tctTable = doc.getTable();\r\n\t\t} catch (XmlException e) {\r\n\t\t\tthrow new IOException(e.getLocalizedMessage());\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic XSSFSheet getXSSFSheet(){\r\n\t\treturn (XSSFSheet) getParent();\r\n\t}\r\n\r\n\tpublic void writeTo(OutputStream out) throws IOException {\r\n updateHeaders();\r\n\r\n TableDocument doc = TableDocument.Factory.newInstance();\r\n\t\tdoc.setTable(ctTable);\r\n\t\tdoc.save(out, DEFAULT_XML_OPTIONS);\r\n\t}\r\n\r\n\t@Override\r\n\tprotected void commit() throws IOException {\r\n\t\tPackagePart part = getPackagePart();\r\n\t\tOutputStream out = part.getOutputStream();\r\n\t\twriteTo(out);\r\n\t\tout.close();\r\n\t}\r\n\t\r\n\tpublic CTTable getCTTable(){\r\n\t\treturn ctTable;\r\n\t}\r\n\t\r\n\t/**\r\n\t * Checks if this Table element contains even a single mapping to the map identified by id\r\n\t * @param id the XSSFMap ID\r\n\t * @return true if the Table element contain mappings\r\n\t */\r\n\tpublic boolean mapsTo(long id){\r\n\t\tboolean maps =false;\r\n\t\t\r\n\t\tList<XSSFXmlColumnPr> pointers = getXmlColumnPrs();\r\n\t\t\r\n\t\tfor(XSSFXmlColumnPr pointer: pointers){\r\n\t\t\tif(pointer.getMapId()==id){\r\n\t\t\t\tmaps=true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\treturn maps;\r\n\t}\r\n\r\n\t\r\n\t/**\r\n\t * \r\n\t * Calculates the xpath of the root element for the table. This will be the common part\r\n\t * of all the mapping's xpaths\r\n\t * \r\n\t * @return the xpath of the table's root element\r\n\t */\r\n\tpublic String getCommonXpath() {\r\n\t\t\r\n\t\tif(commonXPath == null){\r\n\t\t\r\n\t\tString[] commonTokens ={};\r\n\t\t\r\n\t\tfor(CTTableColumn column :ctTable.getTableColumns().getTableColumnList()){\r\n\t\t\tif(column.getXmlColumnPr()!=null){\r\n\t\t\t\tString xpath = column.getXmlColumnPr().getXpath();\r\n\t\t\t\tString[] tokens = xpath.split(\"/\");\r\n\t\t\t\tif(commonTokens.length==0){\r\n\t\t\t\t\tcommonTokens = tokens;\r\n\t\t\t\t\t\r\n\t\t\t\t}else{\r\n\t\t\t\t\tint maxLenght = commonTokens.length>tokens.length? tokens.length:commonTokens.length;\r\n\t\t\t\t\tfor(int i =0; i<maxLenght;i++){\r\n\t\t\t\t\t\tif(!commonTokens[i].equals(tokens[i])){\r\n\t\t\t\t\t\t List<String> subCommonTokens = Arrays.asList(commonTokens).subList(0, i);\r\n\t\t\t\t\t\t \r\n\t\t\t\t\t\t String[] container = {};\r\n\t\t\t\t\t\t \r\n\t\t\t\t\t\t commonTokens = subCommonTokens.toArray(container);\r\n\t\t\t\t\t\t break;\r\n\t\t\t\t\t\t \r\n\t\t\t\t\t\t \r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tcommonXPath =\"\";\r\n\t\t\r\n\t\tfor(int i = 1 ; i< commonTokens.length;i++){\r\n\t\t\tcommonXPath +=\"/\"+commonTokens[i];\r\n\t\t\r\n\t\t}\r\n\t\t}\r\n\t\t\r\n\t\treturn commonXPath;\r\n\t}\r\n\r\n\t\r\n\tpublic List<XSSFXmlColumnPr> getXmlColumnPrs() {\r\n\t\t\r\n\t\tif(xmlColumnPr==null){\r\n\t\t\txmlColumnPr = new Vector<XSSFXmlColumnPr>();\r\n\t\t\tfor(CTTableColumn column:ctTable.getTableColumns().getTableColumnList()){\r\n\t\t\t\tif(column.getXmlColumnPr()!=null){\r\n\t\t\t\t\tXSSFXmlColumnPr columnPr = new XSSFXmlColumnPr(this,column,column.getXmlColumnPr());\r\n\t\t\t\t\txmlColumnPr.add(columnPr);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn xmlColumnPr;\r\n\t}\r\n\t\r\n\t/**\r\n\t * @return the name of the Table, if set\r\n\t */\r\n\tpublic String getName() {\r\n\t return ctTable.getName();\r\n\t}\r\n\t\r\n\t/**\r\n\t * Changes the name of the Table\r\n\t */\r\n\tpublic void setName(String name) {\r\n\t if(name == null) {\r\n\t ctTable.unsetName();\r\n\t return;\r\n\t }\r\n\t ctTable.setName(name);\r\n\t}\r\n\r\n /**\r\n * @return the display name of the Table, if set\r\n */\r\n public String getDisplayName() {\r\n return ctTable.getDisplayName();\r\n }\r\n\r\n /**\r\n * Changes the display name of the Table\r\n */\r\n public void setDisplayName(String name) {\r\n ctTable.setDisplayName(name);\r\n }\r\n\r\n\t/**\r\n\t * @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4)\r\n\t */\r\n\tpublic long getNumerOfMappedColumns(){\r\n\t\treturn ctTable.getTableColumns().getCount();\r\n\t}\r\n\t\r\n\t\r\n\t/**\r\n\t * @return The reference for the cell in the top-left part of the table\r\n\t * (see Open Office XML Part 4: chapter 3.5.1.2, attribute ref) \r\n\t *\r\n\t */\r\n\tpublic CellReference getStartCellReference() {\r\n\t\t\r\n\t\tif(startCellReference==null){\t\t\t\r\n\t\t\t\tString ref = ctTable.getRef();\r\n if(ref != null) {\r\n String[] boundaries = ref.split(\":\");\r\n String from = boundaries[0];\r\n startCellReference = new CellReference(from);\r\n }\r\n\t\t}\r\n\t\treturn startCellReference;\r\n\t}\r\n\t\r\n\t/**\r\n\t * @return The reference for the cell in the bottom-right part of the table\r\n\t * (see Open Office XML Part 4: chapter 3.5.1.2, attribute ref)\r\n\t *\r\n\t */\r\n\tpublic CellReference getEndCellReference() {\r\n\t\t\r\n\t\tif(endCellReference==null){\r\n\t\t\t\r\n\t\t\t\tString ref = ctTable.getRef();\r\n\t\t\t\tString[] boundaries = ref.split(\":\");\r\n\t\t\t\tString from = boundaries[1];\r\n\t\t\t\tendCellReference = new CellReference(from);\r\n\t\t}\r\n\t\treturn endCellReference;\r\n\t}\r\n\t\r\n\t\r\n\t/**\r\n\t * @return the total number of rows in the selection. (Note: in this version autofiltering is ignored)\r\n\t *\r\n\t */\r\n\tpublic int getRowCount(){\r\n\t\t\r\n\t\t\r\n\t\tCellReference from = getStartCellReference();\r\n\t\tCellReference to = getEndCellReference();\r\n\t\t\r\n\t\tint rowCount = -1;\r\n\t\tif (from!=null && to!=null){\r\n\t\t rowCount = to.getRow()-from.getRow();\r\n\t\t}\r\n\t\treturn rowCount;\r\n\t}\r\n\r\n /**\r\n * Synchronize table headers with cell values in the parent sheet.\r\n * Headers <em>must</em> be in sync, otherwise Excel will display a\r\n * \"Found unreadable content\" message on startup.\r\n */\r\n public void updateHeaders(){\r\n XSSFSheet sheet = (XSSFSheet)getParent();\r\n CellReference ref = getStartCellReference();\r\n if(ref == null) return;\r\n\r\n int headerRow = ref.getRow();\r\n int firstHeaderColumn = ref.getCol();\r\n XSSFRow row = sheet.getRow(headerRow);\r\n\r\n if(row != null) for(CTTableColumn col : getCTTable().getTableColumns().getTableColumnList()){\r\n int colIdx = (int)col.getId() - 1 + firstHeaderColumn;\r\n XSSFCell cell = row.getCell(colIdx);\r\n if(cell != null) {\r\n col.setName(cell.getStringCellValue());\r\n }\r\n }\r\n\r\n }\r\n}\r\n >=================================================================== >--- ../../repository/SupportingLibraries/poi-3.10-wc/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java (revision 1) >+++ ../../repository/SupportingLibraries/poi-3.10-wc/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java (revision ) >@@ -17,13 +17,6 @@ > > package org.apache.poi.xssf.usermodel; > >-import java.io.IOException; >-import java.io.InputStream; >-import java.io.OutputStream; >-import java.util.Arrays; >-import java.util.List; >-import java.util.Vector; >- > import org.apache.poi.POIXMLDocumentPart; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackageRelationship; >@@ -34,273 +27,248 @@ > import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.TableDocument; > >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.OutputStream; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; >+ > /** >- * >- * This class implements the Table Part (Open Office XML Part 4: >- * chapter 3.5.1) >- * >+ * This class implements the Table Part (Open Office XML Part 4: chapter 3.5.1) >+ * <p/> > * This implementation works under the assumption that a table contains mappings to a subtree of an XML. > * The root element of this subtree an occur multiple times (one for each row of the table). The child nodes > * of the root element can be only attributes or element with maxOccurs=1 property set >- * >+ * >- * > * @author Roberto Manicardi > */ > public class XSSFTable extends POIXMLDocumentPart { > >- private CTTable ctTable; >- private List<XSSFXmlColumnPr> xmlColumnPr; >- private CellReference startCellReference; >- private CellReference endCellReference; >- private String commonXPath; >- >+ private CTTable ctTable; >+ private List<XSSFXmlColumnPr> xmlColumnPr; >+ private CellReference startCellReference; >+ private CellReference endCellReference; >+ private String commonXPath; >+ >- >- public XSSFTable() { >+ public XSSFTable() { >- super(); >- ctTable = CTTable.Factory.newInstance(); >+ ctTable = CTTable.Factory.newInstance(); >- >- } >+ } > >- public XSSFTable(PackagePart part, PackageRelationship rel) >- throws IOException { >+ public XSSFTable(PackagePart part, PackageRelationship rel) throws IOException { >- super(part, rel); >- readFrom(part.getInputStream()); >- } >+ super(part, rel); >+ readFrom(part.getInputStream()); >+ } > >- public void readFrom(InputStream is) throws IOException { >- try { >- TableDocument doc = TableDocument.Factory.parse(is); >- ctTable = doc.getTable(); >- } catch (XmlException e) { >- throw new IOException(e.getLocalizedMessage()); >- } >- } >- >+ public void readFrom(InputStream is) throws IOException { >+ try { >+ TableDocument doc = TableDocument.Factory.parse(is); >+ ctTable = doc.getTable(); >+ } catch (XmlException e) { >+ throw new IOException(e.getLocalizedMessage()); >+ } >+ } >+ >- public XSSFSheet getXSSFSheet(){ >+ public XSSFSheet getXSSFSheet() { >- return (XSSFSheet) getParent(); >- } >+ return (XSSFSheet) getParent(); >+ } > >- public void writeTo(OutputStream out) throws IOException { >+ public void writeTo(OutputStream out) throws IOException { > updateHeaders(); > > TableDocument doc = TableDocument.Factory.newInstance(); >- doc.setTable(ctTable); >- doc.save(out, DEFAULT_XML_OPTIONS); >- } >+ doc.setTable(ctTable); >+ doc.save(out, DEFAULT_XML_OPTIONS); >+ } > >- @Override >- protected void commit() throws IOException { >- PackagePart part = getPackagePart(); >- OutputStream out = part.getOutputStream(); >- writeTo(out); >- out.close(); >- } >- >+ @Override >+ protected void commit() throws IOException { >+ PackagePart part = getPackagePart(); >+ OutputStream out = part.getOutputStream(); >+ writeTo(out); >+ out.close(); >+ } >+ >- public CTTable getCTTable(){ >+ public CTTable getCTTable() { >- return ctTable; >- } >- >- /** >- * Checks if this Table element contains even a single mapping to the map identified by id >+ return ctTable; >+ } >+ >+ /** >+ * Checks if this Table element contains even a single mapping to the map identified by id >+ * >- * @param id the XSSFMap ID >- * @return true if the Table element contain mappings >- */ >+ * @param id the XSSFMap ID >+ * @return true if the Table element contain mappings >+ */ >- public boolean mapsTo(long id){ >+ public boolean mapsTo(long id) { >- boolean maps =false; >- >- List<XSSFXmlColumnPr> pointers = getXmlColumnPrs(); >- >- for(XSSFXmlColumnPr pointer: pointers){ >+ for (XSSFXmlColumnPr pointer : getXmlColumnPrs()) { >- if(pointer.getMapId()==id){ >+ if (pointer.getMapId() == id) { >- maps=true; >- break; >+ return true; >- } >- } >- >+ } >+ } >+ >- return maps; >+ return false; >- } >+ } > >- >- /** >+ /** >- * >- * Calculates the xpath of the root element for the table. This will be the common part >- * of all the mapping's xpaths >- * >- * @return the xpath of the table's root element >- */ >- public String getCommonXpath() { >+ * Calculates the xpath of the root element for the table. This will be the common part >+ * of all the mapping's xpaths >+ * >+ * @return the xpath of the table's root element >+ */ >+ public String getCommonXpath() { >- >- if(commonXPath == null){ >+ if (commonXPath == null) { >- >- String[] commonTokens ={}; >+ String[] commonTokens = {}; >- >+ >- for(CTTableColumn column :ctTable.getTableColumns().getTableColumnList()){ >+ for (CTTableColumn column : ctTable.getTableColumns().getTableColumnList()) { >- if(column.getXmlColumnPr()!=null){ >+ if (column.getXmlColumnPr() != null) { >- String xpath = column.getXmlColumnPr().getXpath(); >+ String xpath = column.getXmlColumnPr().getXpath(); >- String[] tokens = xpath.split("/"); >+ String[] tokens = xpath.split("/"); >- if(commonTokens.length==0){ >+ if (commonTokens.length == 0) { >- commonTokens = tokens; >+ commonTokens = tokens; >- >- }else{ >+ } else { >- int maxLenght = commonTokens.length>tokens.length? tokens.length:commonTokens.length; >- for(int i =0; i<maxLenght;i++){ >+ int maxLength = commonTokens.length > tokens.length ? tokens.length : commonTokens.length; >+ for (int i = 0; i < maxLength; i++) { >- if(!commonTokens[i].equals(tokens[i])){ >+ if (!commonTokens[i].equals(tokens[i])) { >- List<String> subCommonTokens = Arrays.asList(commonTokens).subList(0, i); >- >+ List<String> subCommonTokens = Arrays.asList(commonTokens).subList(0, i); >+ >- String[] container = {}; >- >- commonTokens = subCommonTokens.toArray(container); >+ commonTokens = subCommonTokens.toArray(new String[subCommonTokens.size()]); >- break; >+ break; >- >- >- } >- } >- } >+ } >+ } >+ } >- >- } >- } >- >+ } >+ } >+ >- >- commonXPath =""; >- >+ StringBuilder sb = new StringBuilder(); >- for(int i = 1 ; i< commonTokens.length;i++){ >+ for (int i = 1; i < commonTokens.length; i++) { >- commonXPath +="/"+commonTokens[i]; >- >+ sb.append('/').append(commonTokens[i]); >- } >+ } >+ commonXPath = sb.toString(); >- } >- >- return commonXPath; >- } >+ } >+ >+ return commonXPath; >+ } > >- >- public List<XSSFXmlColumnPr> getXmlColumnPrs() { >+ public List<XSSFXmlColumnPr> getXmlColumnPrs() { >- >- if(xmlColumnPr==null){ >+ if (xmlColumnPr == null) { >- xmlColumnPr = new Vector<XSSFXmlColumnPr>(); >+ xmlColumnPr = new ArrayList<XSSFXmlColumnPr>(); >- for(CTTableColumn column:ctTable.getTableColumns().getTableColumnList()){ >+ for (CTTableColumn column : ctTable.getTableColumns().getTableColumnList()) { >- if(column.getXmlColumnPr()!=null){ >+ if (column.getXmlColumnPr() != null) { >- XSSFXmlColumnPr columnPr = new XSSFXmlColumnPr(this,column,column.getXmlColumnPr()); >+ XSSFXmlColumnPr columnPr = new XSSFXmlColumnPr(this, column, column.getXmlColumnPr()); >- xmlColumnPr.add(columnPr); >- } >- } >- } >- return xmlColumnPr; >- } >- >- /** >- * @return the name of the Table, if set >- */ >- public String getName() { >- return ctTable.getName(); >- } >- >- /** >- * Changes the name of the Table >- */ >- public void setName(String name) { >+ xmlColumnPr.add(columnPr); >+ } >+ } >+ } >+ return xmlColumnPr; >+ } >+ >+ /** >+ * @return the name of the Table, if set >+ */ >+ public String getName() { >+ return ctTable.getName(); >+ } >+ >+ /** >+ * Changes the name of the Table >+ */ >+ public void setName(String name) { >- if(name == null) { >+ if (name == null) { >- ctTable.unsetName(); >- return; >- } >- ctTable.setName(name); >- } >+ ctTable.unsetName(); >+ return; >+ } >+ ctTable.setName(name); >+ } > >- /** >- * @return the display name of the Table, if set >- */ >- public String getDisplayName() { >- return ctTable.getDisplayName(); >- } >+ /** >+ * @return the display name of the Table, if set >+ */ >+ public String getDisplayName() { >+ return ctTable.getDisplayName(); >+ } > >- /** >- * Changes the display name of the Table >- */ >- public void setDisplayName(String name) { >- ctTable.setDisplayName(name); >- } >+ /** >+ * Changes the display name of the Table >+ */ >+ public void setDisplayName(String name) { >+ ctTable.setDisplayName(name); >+ } > >- /** >+ /** >- * @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4) >+ * @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4) >- */ >+ */ >- public long getNumerOfMappedColumns(){ >+ public long getNumerOfMappedColumns() { >- return ctTable.getTableColumns().getCount(); >- } >- >+ return ctTable.getTableColumns().getCount(); >+ } >+ >- >- /** >- * @return The reference for the cell in the top-left part of the table >- * (see Open Office XML Part 4: chapter 3.5.1.2, attribute ref) >+ /** >+ * @return The reference for the cell in the top-left part of the table >+ * (see Open Office XML Part 4: chapter 3.5.1.2, attribute ref) >- * >- */ >- public CellReference getStartCellReference() { >+ */ >+ public CellReference getStartCellReference() { >- >- if(startCellReference==null){ >+ if (startCellReference == null) { >- String ref = ctTable.getRef(); >- if(ref != null) { >- String[] boundaries = ref.split(":"); >- String from = boundaries[0]; >- startCellReference = new CellReference(from); >+ initCellReferences(); >- } >+ } >- } >- return startCellReference; >- } >- >- /** >- * @return The reference for the cell in the bottom-right part of the table >- * (see Open Office XML Part 4: chapter 3.5.1.2, attribute ref) >+ return startCellReference; >+ } >+ >+ /** >+ * @return The reference for the cell in the bottom-right part of the table >+ * (see Open Office XML Part 4: chapter 3.5.1.2, attribute ref) >- * >- */ >- public CellReference getEndCellReference() { >+ */ >+ public CellReference getEndCellReference() { >- >- if(endCellReference==null){ >+ if (endCellReference == null) { >+ initCellReferences(); >+ } >+ return endCellReference; >+ } >- >+ >+ private void initCellReferences() { >- String ref = ctTable.getRef(); >+ String ref = ctTable.getRef(); >- String[] boundaries = ref.split(":"); >- String from = boundaries[1]; >- endCellReference = new CellReference(from); >+ if (ref != null) { >+ int indexOfColon = ref.indexOf(':'); >+ startCellReference = new CellReference(ref.substring(0, indexOfColon)); >+ endCellReference = new CellReference(ref.substring(indexOfColon + 1)); >- } >+ } >- return endCellReference; >- } >- >+ } >+ >- >- /** >+ /** >- * @return the total number of rows in the selection. (Note: in this version autofiltering is ignored) >+ * @return the total number of rows in the selection. (Note: in this version autofiltering is ignored) >- * >- */ >+ */ >- public int getRowCount(){ >+ public int getRowCount() { >- >- >- CellReference from = getStartCellReference(); >- CellReference to = getEndCellReference(); >- >- int rowCount = -1; >+ CellReference from = getStartCellReference(); >+ CellReference to = getEndCellReference(); >+ >+ int rowCount = -1; >- if (from!=null && to!=null){ >+ if (from != null && to != null) { >- rowCount = to.getRow()-from.getRow(); >+ rowCount = to.getRow() - from.getRow(); >- } >- return rowCount; >- } >+ } >+ return rowCount; >+ } > > /** > * Synchronize table headers with cell values in the parent sheet. > * Headers <em>must</em> be in sync, otherwise Excel will display a > * "Found unreadable content" message on startup. > */ >- public void updateHeaders(){ >+ public void updateHeaders() { >- XSSFSheet sheet = (XSSFSheet)getParent(); >+ XSSFSheet sheet = (XSSFSheet) getParent(); > CellReference ref = getStartCellReference(); >- if(ref == null) return; >+ if (ref == null) return; > > int headerRow = ref.getRow(); > int firstHeaderColumn = ref.getCol(); > XSSFRow row = sheet.getRow(headerRow); > >- if(row != null) for(CTTableColumn col : getCTTable().getTableColumns().getTableColumnList()){ >- int colIdx = (int)col.getId() - 1 + firstHeaderColumn; >- XSSFCell cell = row.getCell(colIdx); >+ if (row != null) { >+ int cellnum = firstHeaderColumn; >+ for (CTTableColumn col : getCTTable().getTableColumns().getTableColumnList()) { >+ XSSFCell cell = row.getCell(cellnum); >- if(cell != null) { >+ if (cell != null) { >- col.setName(cell.getStringCellValue()); >- } >+ col.setName(cell.getStringCellValue()); >+ } >+ cellnum++; >- } >+ } >- >+ } > } > }
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 56274
:
31393
|
31403
|
31564
|
31605
|
31606