我正在使用此代码从 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;
}
但是此代码仅返回非整数值计数,如果工作表中列的任何行包含整数值,则它会跳过它并且此函数返回的行计数无效
它只计算字母数字值行
有什么方法可以让我获得正确的行数
JAR 使用 odfdom-java-0.8.7-jar-with-dependencies