Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.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
Java 使用XSSF的Excel工作表中空单元格的结果地址_Java_Excel_Selenium Webdriver_Apache Poi_Xssf - Fatal编程技术网

Java 使用XSSF的Excel工作表中空单元格的结果地址

Java 使用XSSF的Excel工作表中空单元格的结果地址,java,excel,selenium-webdriver,apache-poi,xssf,Java,Excel,Selenium Webdriver,Apache Poi,Xssf,我正在使用POI的XSSF阅读Excel表格。Excel表格中有数千行用户信息,如用户名、地址、年龄、部门等 我可以成功地读写Excel工作表,但我想找到空/空单元格的地址,并将其打印到另一张工作表中 示例结果我想要的是: Empty cell : C5 Empty cell : E7 Empty cell : H8 感谢并感谢您的讨论和回复。就我正确理解您的问题而言,这应该可以做到: XSSFCell cell = (XSSFCell) row.getCell( index ); if

我正在使用POI的XSSF阅读Excel表格。Excel表格中有数千行用户信息,如用户名、地址、年龄、部门等

我可以成功地读写Excel工作表,但我想找到空/空单元格的地址,并将其打印到另一张工作表中

示例结果我想要的是:

Empty cell  : C5
Empty cell  : E7
Empty cell  : H8

感谢并感谢您的讨论和回复。

就我正确理解您的问题而言,这应该可以做到:

XSSFCell cell = (XSSFCell) row.getCell( index );
if( cell == null )
{
  cell = (XSSFCell) row.createCell( index );
}
if( cell.getStringCellValue().trim().isEmpty() )
{
  String cellRef = CellReference.convertNumToColString( cell.getColumnIndex() );
  System.err.println( "Empty cell found: " + cellRef
          + Integer.toString( row.getRowNum() ) );
}

您需要检查空单元格和空白单元格。空单元格是从未使用过的单元格,空白单元格是以某种方式使用过的单元格或样式,Excel决定将其保留在文件中

控制此抓取的最简单方法是使用。然后,您的代码可以是:

Row r = getRow(); // Logic here to get the row of interest

// Iterate over all cells in the row, up to at least the 10th column
int lastColumn = Math.max(r.getLastCellNum(), 10);

for (int cn = 0; cn < lastColumn; cn++) {
      Cell c = r.getCell(cn, Row.RETURN_BLANK_AS_NULL);
      if (c == null) {
         // The spreadsheet is empty in this cell
      } else {
         // Do something useful with the cell's contents
         // eg...
         System.out.println("There is data in cell " + (new CellReference(c)).formatAsString());
      }
}
Row r=getRow();//这里的逻辑是获取感兴趣的行
//迭代行中的所有单元格,至少迭代到第10列
int lastColumn=Math.max(r.getLastCellNum(),10);
for(int cn=0;cn

你可以在详细模式下找到更多信息,谢谢你的快速回复。是的,这是一个很好的技巧,但显示第一个空单元格,这对你有用吗?我是的,别忘了接受答案。如果没有,请随时向我发帖。详细回答是的,这个技巧对我实现geart的结果非常有帮助。谢谢你的回复,我想打印空单元格地址,甚至遍历所有单元格切换到
行。返回\u NULL \u作为\u BLANK
,然后打开空白单元格类型,然后就应该完成了!。如何获取空白单元格的地址一切正常。请帮助我使用
CellReference
,它会为您转换,请参阅我的编辑以获取示例作为详细模式答案我在cell.setCellValue中使用了“CellReference”,但如果下一个单元格为空,则将异常显示为空指针