英文:
Getting values from Excel using OpenNTF POI, but row.getCellType() no longer working
问题
我正在使用来自OpenNTF的最新POI版本,在Domino 10服务器上使用UpdateSite。
https://poi4xpages.openntf.org/
我的代码读取Excel中的单元格值。
由于某种原因,方法rowdata.getCell(0).getCellType()不再起作用,并且在运行时生成错误,因此我无法检查单元格包含的值的类型。
方法getStringCellValue()和getNumericCellValue()仅在Excel单元格中的值为该类型时起作用,即如果我有一个包含100的单元格,它总是一个数字。
在我的列中,既有100又有100a,如果我使用100a和getNumericCellValue(),它会生成一个错误。
hsCurrent.put("FILE", inputFile);
Workbook wb = ioAction.run(null, hsCurrent);
worksheet = wb.getSheetAt(0);
rowdata = worksheet.getRow(1);
kod = rowdata.getCell(0).getStringCellValue();
price = rowdata.getCell(3).getNumericCellValue();
由于**getCellType()**不起作用,我需要找到另一种处理我得到的错误的方法,我该如何在Java中做到这一点。
此外,如果您对**getCellType()**出现问题的原因有任何想法,请告诉我。
还要注意,所有这些方法都检查Excel中单元格的值,而不是单元格的类型。
如果需要提供更多信息,请告诉我。
javax.servlet.ServletException: java.lang.NoSuchMethodError: org/apache/poi/ss/usermodel/Cell.getCellType()Lorg/apache/poi/ss/usermodel/CellType;(从文件加载:/D:/Lotus/Domino/Data/domino/workspace/.config/org.eclipse.osgi/42/0/.cp/lib-maven/poi.jar by org.eclipse.osgi.internal.loader.EquinoxClassLoader@ab93247a[biz.webgate.dominoext.poi.library:1.3.1.201703140726(id=42)]) 被类com.consili.ImportExcel调用(从xspnsf://server:0/web.nsf/WEB-INF/classes/ by com.ibm.domino.xsp.module.nsf.ModuleClassLoader$DynamicClassLoader@9b55621b加载)。在com.ibm.xsp.webapp.FacesServlet.handleError(FacesServlet.java:690) at com.ibm.xsp.webapp.FacesServlet.renderErrorPage(FacesServlet.java:512) at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:186) at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138) at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103) </values>
英文:
I am using latest POI version from OpenNTF on a Domino 10 server using the UpdateSite
https://poi4xpages.openntf.org/
My code reads cell values in Excel
for some reason the method rowdata.getCell(0).getCellType() no longer works and generate errors when running so I can't check what type of value the cell contain.
The methods getStringCellValue() and getNumericCellValue() only works if the value in the Excel cells is of that type, i.e if I have a cell containing 100 it is always a number.
in my columns I have both 100 and 100a and if I use 100a with getNumericCellValue() it generates an error.
hsCurrent.put("FILE", inputFile);
Workbook wb = ioAction.run(null, hsCurrent);
worksheet = wb.getSheetAt(0);
rowdata = worksheet.getRow(1);
kod = rowdata.getCell(0).getStringCellValue();
price = rowdata.getCell(3).getNumericCellValue();
as the getCellType() is not working I need to find another way to deal with the errors I get, How can I do that in java.
also, if you have any idea why there is a problem with getCellType(), let me know.
also note that all these methods check the value of the cell in excel, not what typ of cell it is
let me know if I need to provide more information
javax.servlet.ServletException: java.lang.NoSuchMethodError: org/apache/poi/ss/usermodel/Cell.getCellType()Lorg/apache/poi/ss/usermodel/CellType; (loaded from file:/D:/Lotus/Domino/Data/domino/workspace/.config/org.eclipse.osgi/42/0/.cp/lib-maven/poi.jar by org.eclipse.osgi.internal.loader.EquinoxClassLoader@ab93247a[biz.webgate.dominoext.poi.library:1.3.1.201703140726(id=42)]) called from class com.consili.ImportExcel (loaded from xspnsf://server:0/web.nsf/WEB-INF/classes/ by com.ibm.domino.xsp.module.nsf.ModuleClassLoader$DynamicClassLoader@9b55621b). at com.ibm.xsp.webapp.FacesServlet.handleError(FacesServlet.java:690) at com.ibm.xsp.webapp.FacesServlet.renderErrorPage(FacesServlet.java:512) at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:186) at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138) at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103) </values>
<values>at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:600) at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1352) at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:877) at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:820) at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:589) at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1336) at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662) at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482) at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:357) at com.ibm.designer.runtime.domino.adapter</values>
<values>.LCDEnvironment.service(LCDEnvironment.java:313) at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272) Caused by: java.lang.NoSuchMethodError: org/apache/poi/ss/usermodel/Cell.getCellType()Lorg/apache/poi/ss/usermodel/CellType; (loaded from file:/D:/Lotus/Domino/Data/domino/workspace/.config/org.eclipse.osgi/42/0/.cp/lib-maven/poi.jar by org.eclipse.osgi.internal.loader.EquinoxClassLoader@ab93247a[biz.webgate.dominoext.poi.library:1.3.1.201703140726(id=42)]) called from class com.consili.ImportExcel (loaded from xspnsf://server:sweb.nsf/WEB-INF/classes/ by com.ibm.domino.xsp.module.nsf.ModuleClassLoader$DynamicClassLoader@9b55621b). at com.consili.ImportExcel.getImportedData(ImportExcel.java:98) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90) at sun.reflect.DelegatingMethodAccessorImpl.i</values>
<values>nvoke(DelegatingMethodAccessorImpl.java:55) at java.lang.reflect.Method.invoke(Method.java:508) at com.ibm.jscript.types.JavaAccessObject.call(JavaAccessObject.java:322) at com.ibm.jscript.types.FBSObject.call(FBSObject.java:161) at com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:197) at com.ibm.jscript.ASTTree.ASTVariableDecl.interpret(ASTVariableDecl.java:82) at com.ibm.jscript.ASTTree.ASTBlock.interpret(ASTBlock.java:100) at com.ibm.jscript.ASTTree.ASTIf.interpret(ASTIf.java:90) at com.ibm.jscript.ASTTree.ASTBlock.interpret(ASTBlock.java:100) at com.ibm.jscript.ASTTree.ASTTry.interpret(ASTTry.java:109) at com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119) at com.ibm.jscript.ASTTree.ASTProgram.interpretEx(ASTProgram.java:139) at com.ibm.jscript.JSExpression._interpretExpression(JSExpression.java:435) at com.</values>
<values>ibm.jscript.JSExpression.access$1(JSExpression.java:424) at com.ibm.jscript.JSExpression$2.run(JSExpression.java:414) at java.security.AccessController.doPrivileged(AccessController.java:732) at com.ibm.jscript.JSExpression.interpretExpression(JSExpression.java:410) at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:251) at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:234) at com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:222) at com.ibm.xsp.binding.javascript.JavaScriptMethodBinding.invoke(JavaScriptMethodBinding.java:111) at com.ibm.xsp.application.ActionListenerImpl.processAction(ActionListenerImpl.java:60) at javax.faces.component.UICommand.broadcast(UICommand.java:324) at com.ibm.xsp.component.UIEventHandler.broadcast(UIEventHandler.java:366) at com.ibm.xsp.component.UIDataPanelBase.broadcas</values>
<values>t(UIDataPanelBase.java:400) at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400) at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400) at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400) at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400) at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400) at com.ibm.xsp.component.UIViewRootEx.broadcast(UIViewRootEx.java:1669) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:307) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:428) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:94) at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96) </values>
<values> at com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:256) at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:231) at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157) at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:163) ... 13 more
答案1
得分: 0
我这样做,似乎可以工作
try{
year = (int)rowdata.getCell(1).getNumericCellValue();
}catch(Exception e){
year = rowdata.getCell(1).getStringCellValue();
}
英文:
I did this and it seem to work
try{
year = (int)rowdata.getCell(1).getNumericCellValue();
}catch(Exception e){
year = rowdata.getCell(1).getStringCellValue();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论