Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaODFDOM:如何从ODF表中获取整数值_Java_Odf_Odfdom - Fatal编程技术网

JavaODFDOM:如何从ODF表中获取整数值

JavaODFDOM:如何从ODF表中获取整数值,java,odf,odfdom,Java,Odf,Odfdom,我使用此代码从ODF中的工作表中获取最大行数 public int getRowCount(String sheetName) throws XPathExpressionException, Exception { //reset rowCount to zero rowCount=0; //xpath to reach Nodes of cell in first row int parameterCount=getColumnCount(sheet

我使用此代码从ODF中的工作表中获取最大行数

public int getRowCount(String sheetName) throws XPathExpressionException, Exception

{

//reset rowCount to zero

        rowCount=0;

//xpath to reach Nodes of cell in first row

        int parameterCount=getColumnCount(sheetName);
        //System.out.println("Debug:ParameterCount="+parameterCount);
        for (int i=1;i<=parameterCount;i++)
        {
            String xpathStr="//table:table[@table:name='"+sheetName+"']/table:table-row/table:table-cell["+i+"][@office:value-type='void']";
            DTMNodeList nodeList = (DTMNodeList) xpath.evaluate(xpathStr, spreadSheet.getContentDom(), XPathConstants.NODESET);
            //System.out.println("Debug:RowsFoundWithData="+nodeList.getLength());
            System.out.println(nodeList.getLength());
            for(int j=0 ; j<nodeList.getLength();j++)
            {
                System.out.println("Debug:RowValue="+nodeList.item(j).getTextContent());
            }
            if(nodeList.getLength()-1>rowCount)
            {
                rowCount=nodeList.getLength()-1;
            }

    }

return rowCount;

    }
public int getRowCount(String sheetName)抛出XPathExpressionException,异常
{
//将行计数重置为零
行数=0;
//xpath以到达第一行单元格的节点
int参数count=getColumnCount(sheetName);
//System.out.println(“调试:ParameterCount=“+ParameterCount”);

对于(int i=1;i虽然我认为你自己已经找到了答案,但我一直在努力解决一个类似的问题。很难为这个伟大的工具找到合适的例子。 这是您在电子表格中应该看到的:

OdfSpreadsheetDocument ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
OdfTable table = SpreadsheetHandling.setNewTable(ods, "names");
System.out.println("Number of rows: " + table.getRowCount());
不幸的是,情况更为复杂。当您在电子表格中浏览将行添加到工作表的代码时,此方法是否会返回准确的行数。然而,当加载文档并读取行数时,它将返回可能的最大行数,因此:1048576

但是,可以使用表的row类型的节点数

OdfSpreadsheetDocument ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
OdfTable table = SpreadsheetHandling.setNewTable(ods, "rowCount");
TableTableElement tte = table.getOdfElement();
NodeList nl = tte.getElementsByTagName("table:table-row");
System.out.println("Number of nodeelements: " + nl.getLength());
致以亲切的问候

勒克