繁体   English   中英

Apache OFBiz中的Apache POI异常

[英]Apache POI exception in Apache OFBiz

我在一个项目工作。它的服务器端应用程序是在ofbiz.I想要读取,编辑,更新等excel表。但在正常的Java程序中它的工作。我使用apache poi API.But当放入ofbiz然后运行应用程序。然后有时会出现一些异常。以下是

"
     [java] java.lang.IllegalStateException: Cannot get a text value from a nume
ric formula cell
     [java]     at org.apache.poi.hssf.usermodel.HSSFCell.typeMismatch(HSSFCell.
java:637)
     [java]     at org.apache.poi.hssf.usermodel.HSSFCell.checkFormulaCachedValu
eType(HSSFCell.java:642)
     [java]     at org.apache.poi.hssf.usermodel.HSSFCell.getRichStringCellValue
(HSSFCell.java:719)
     [java]
     [java]     at org.apache.poi.hssf.usermodel.HSSFCell.getStringCellValue(HSS
FCell.java:697)
     [java]     at org.ofbiz.productionmgntSystem.setTargetPlan.getRequiredData(
setTargetPlan.java:764)
     [java]     *****
     [java]     at org.ofbiz.productionmgntSystem.setTargetPlan.setTask(setTarge
tPlan.java:201)
     [java]     at org.ofbiz.productionmgntSystem.ThreadProcess.run(ThreadProces
s.java:113)

"

这里我在普通的java和ofbiz中使用相同的apache poi API。

读取整数事务编号时,我遇到了同样的问题。 解决此问题的自然方法是使用:

if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC) {
   String.valueOf(cell.getNumericCellValue());
}

由于12345转换为12345.0,因此无法使用

获取与excel文档中显示的字符串值完全相同的解决方法是:

cell.setCellType(Cell.CELL_TYPE_STRING);
String cellValue=cell.getStringCellValue();

Excel通常会将仅包含数字的单元格存储为数字单元格,而不是字符串单元格。 你可能认为它不是一个数字单元格,但它是......

你可能想要这样的东西:

DataFormatter formatter = new DataFormatter(Locale.US);

....

for(Cell cell : row) {
  String val;
  if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC) {
     // Format the number to look like it does in excel
     val = formatter.formatCellValue(cell);
  }
  if(cell.getCellType()==Cell.CELL_TYPE_STRING) {
     // Just get the string as-is
     val = cell.getRichStringCellValue().getString();
  }
}

查看POI 快速指南以及如何开始使用POI。

暂无
暂无

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

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