简体   繁体   English

如何在使用jxl读取excel文件时检查单元格是否为空

[英]How to check if a cell is blank while using jxl to read excel files

I checked the jxl api to check what the getContent() method returns for an empty cell , but it doesn't explicitly indicate what happens ! 我检查了jxl api以检查getContent()方法为空单元格返回的内容,但它没有明确指出会发生什么!

ref # : http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/Cell.html#getContents%28%29 ref#: http//jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/Cell.html#getContents%28%29

Can anyone indicate what happens when getContent() is called on a cell which is empty ? 任何人都可以指出在空单元格上调用getContent()时会发生什么?

It returns a String of length 0. This is easily tested on a row like so 它返回一个长度为0的String。这很容易在一行上测试

Cell[] cells = sheet.getRow(10) // selecting row 10 from the current sheet
for (Cell cell : cells) {
   String contents = cell.getContents();
   if (contents == null) {
      System.out.println("Will not print");
   } else if (contents.length() == 0) {
      System.out.println("This will print for a blank cell");
   } else {
      System.out.println("This cell is not empty");
   }
}

如果以上不起作用,请尝试以下命令:

string.isEmpty();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM