如何使用apache poi

时间:2016-07-13 12:17:59

标签: java apache-poi

有人可以发布所需的Java代码,演示如何使用Apache poi在Java中读取所有单元格,包括空值单元格。我想在最终输出中用值“空白”替换任何空单元格。

示例Excel:

FirstName SecondName LastName

  1. Deepak Kumar Pradhan
  2. John Miller
  3. Bhagat Panigrahy
  4. 示例输出:

    FirstName SecondName LastName

    1. Deepak Kumar Pradhan
    2. John Blank Miller
    3. Bhagat Panigrahy Blank
    4. 提前致谢

1 个答案:

答案 0 :(得分:1)

您需要在代码中指定缺少的单元格策略,可以是整个工作簿,也可以是使用getCell(int,Row.MissingCellPolicy)从一行获取单个Cell时。请参阅Apache POI API文档:

https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Workbook.html#setMissingCellPolicy(org.apache.poi.ss.usermodel.Row.MissingCellPolicy)

https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Row.html#getCell(int,%20org.apache.poi.ss.usermodel.Row.MissingCellPolicy)