[ 
https://issues.apache.org/jira/browse/ODFTOOLKIT-378?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14578617#comment-14578617
 ] 

Rubén Suárez Alvarez commented on ODFTOOLKIT-378:
-------------------------------------------------

I had to modify getRowCount method (1048576 is huge amount to iterate over) in 
org.odftoolkit.odfdom.doc.table.OdfTable and org.odftoolkit.simple.table.Table 
to discard empty repeated rows (if they are at the end of the sheet), and 
thinking on doing it in getColumnCount (but not much problem with default 1024).

Seems I can't attach files so I include affected fragments below:

{code:title=org.odftoolkit.odfdom.doc.table.OdfTable.java|borderStyle=solid}
        public int getRowCount() {
                int result = 0;
                int numberRowsRepeated = 0;
                int repeatedRowsToIgnore = 0;

                for (Node n : new DomNodeList(mTableElement.getChildNodes())) {
                        if (n instanceof TableTableHeaderRowsElement) {
                                result += 
getHeaderRowCount((TableTableHeaderRowsElement) n);
                        }
                        if (n instanceof TableTableRowElement) {
                                numberRowsRepeated = ((TableTableRowElement) 
n).getTableNumberRowsRepeatedAttribute();
                                result += numberRowsRepeated;
                                NodeList nodeList = ((TableTableRowElement) 
n).getChildNodes();
                                if (nodeList.getLength() == 1) {
                                        Node child = nodeList.item(0);
                                        if (child instanceof 
TableTableCellElement && ((TableTableCellElement) 
child).getChildNodes().getLength() == 0) {
                                                repeatedRowsToIgnore += 
numberRowsRepeated;
                                        }
                                } else {
                                        repeatedRowsToIgnore = 0;
                                }
                        }
                }
                return result - repeatedRowsToIgnore;
        }
{code}

{code:title=org.odftoolkit.simple.table.Table.java|borderStyle=solid}
        public int getRowCount() {
                int result = 0;
                int numberRowsRepeated = 0;
                int repeatedRowsToIgnore = 0;
                for (Node n : new DomNodeList(mTableElement.getChildNodes())) {
                        if (n instanceof TableTableHeaderRowsElement) {
                                result += 
getHeaderRowCount((TableTableHeaderRowsElement) n);
                        }
                        if (n instanceof TableTableRowElement) {
                                numberRowsRepeated =  ((TableTableRowElement) 
n).getTableNumberRowsRepeatedAttribute();
                                result += numberRowsRepeated;
                                NodeList nodeList = ((TableTableRowElement) 
n).getChildNodes();
                                if (nodeList.getLength() == 1) {
                                        Node child = nodeList.item(0);
                                        if (child instanceof 
TableTableCellElement && ((TableTableCellElement) 
child).getChildNodes().getLength() == 0) {
                                                repeatedRowsToIgnore += 
numberRowsRepeated;
                                        }
                                } else {
                                        repeatedRowsToIgnore = 0;
                                }
                        }
                        if (n instanceof TableTableRowsElement) {
                                for (Node nn : new 
DomNodeList(n.getChildNodes())) {
                                        if (nn instanceof TableTableRowElement) 
{
                                                numberRowsRepeated =  
((TableTableRowElement) nn).getTableNumberRowsRepeatedAttribute();
                                                result += numberRowsRepeated;
                                                NodeList nodeList = 
((TableTableRowElement) nn).getChildNodes();
                                                if (nodeList.getLength() == 1) {
                                                        Node child = 
nodeList.item(0);
                                                        if (child instanceof 
TableTableCellElement && ((TableTableCellElement) 
child).getChildNodes().getLength() == 0) {
                                                                
repeatedRowsToIgnore += numberRowsRepeated;
                                                        }
                                                } else {
                                                        repeatedRowsToIgnore = 
0;
                                                }
                                        }
                                }
                        }
                }
                return result - repeatedRowsToIgnore;
        }
{code}

> table.getColumnCount() wrong return value
> -----------------------------------------
>
>                 Key: ODFTOOLKIT-378
>                 URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-378
>             Project: ODF Toolkit
>          Issue Type: Bug
>          Components: simple api
>    Affects Versions: 0.6-incubating
>         Environment: Windows 7 64bit, Microsoft Excel 2013 64bit
>            Reporter: Andreas Glueck
>            Priority: Minor
>
> After saving an existing odf-file in ms excel,
> the getColumnCount() method returns the wrong values.
> New colCount = 16384.
> Before i saved the file = 4 columns.
> Same problem with getRowCount():
> New rowCount =  1048576.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to