Oá, tudo bom ?
Estou tendo o seguinte problema: Tenho um sistema web que faz a leitura e apresentação de vários arquivos em Excel. As apresentações estão todas funcionando perfeitamente (leituras), entretanto um módulo terá de atualizar uma célula arquivo. Fiz dezenas de teste sempre com o mesmo resultado, o servlet me retorna erro e arquivo .xls é corrompido.
Segue código para avaliação:
try{
FileInputStream arquivo = new FileInputStream(new File(caminho));
HSSFWorkbook workbook = new HSSFWorkbook(arquivo);
HSSFSheet sheet = workbook.getSheetAt(0);
Cell cell = null;
cell = sheet.getRow(1).getCell(1);
cell.setCellValue("OverRide existing value");
arquivo.close();
//int lastRow = sheet.getLastRowNum();
//Row row = sheet.createRow(lastRow+1);
//Cell cell = row.createCell(1);
//cell.setCellValue("Arreia");
arquivo.close();
FileOutputStream fos = new FileOutputStream(new File(caminho));
workbook.write(fos);
fos.close();
}
Erro que o Tomcat me retorna:
# HTTP Status 500 - Servlet execution threw an exception
**type** Exception report
**message** Servlet execution threw an exception
**description** The server encountered an internal error that prevented it from fulfilling this request.
**exception**
javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
**root cause**
java.lang.NoClassDefFoundError: org/apache/commons/collections4/bidimap/TreeBidiMap org.apache.poi.hpsf.Section.<init>(Section.java:182) org.apache.poi.hpsf.PropertySet.init(PropertySet.java:497) org.apache.poi.hpsf.PropertySet.<init>(PropertySet.java:195) org.apache.poi.hpsf.DocumentSummaryInformation.<init>(DocumentSummaryInformation.java:111) org.apache.poi.hpsf.PropertySetFactory.create(PropertySetFactory.java:115) org.apache.poi.POIDocument.getPropertySet(POIDocument.java:226) org.apache.poi.POIDocument.getPropertySet(POIDocument.java:185) org.apache.poi.POIDocument.readPropertySet(POIDocument.java:160) org.apache.poi.POIDocument.readProperties(POIDocument.java:143) org.apache.poi.hssf.usermodel.HSSFWorkbook.updateEncryptionInfo(HSSFWorkbook.java:2243) org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:1465) org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1387) org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1375) psb_classes.Cadastrar.processRequest(Cadastrar.java:82) psb_classes.Cadastrar.doGet(Cadastrar.java:101) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
**root cause**
java.lang.ClassNotFoundException: org.apache.commons.collections4.bidimap.TreeBidiMap org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) org.apache.poi.hpsf.Section.<init>(Section.java:182) org.apache.poi.hpsf.PropertySet.init(PropertySet.java:497) org.apache.poi.hpsf.PropertySet.<init>(PropertySet.java:195) org.apache.poi.hpsf.DocumentSummaryInformation.<init>(DocumentSummaryInformation.java:111) org.apache.poi.hpsf.PropertySetFactory.create(PropertySetFactory.java:115) org.apache.poi.POIDocument.getPropertySet(POIDocument.java:226) org.apache.poi.POIDocument.getPropertySet(POIDocument.java:185) org.apache.poi.POIDocument.readPropertySet(POIDocument.java:160) org.apache.poi.POIDocument.readProperties(POIDocument.java:143) org.apache.poi.hssf.usermodel.HSSFWorkbook.updateEncryptionInfo(HSSFWorkbook.java:2243) org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:1465) org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1387) org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1375) psb_classes.Cadastrar.processRequest(Cadastrar.java:82) psb_classes.Cadastrar.doGet(Cadastrar.java:101) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
Provavelmente por isso: classe não encontrada
java.lang.ClassNotFoundException: org.apache.commons.collections4.bidimap.TreeBidiMap
Parece que é um erro gerado pela última atualização do Apache POI, rodei alguns fóruns gringos e eles deixaram essa classe “faltando” no jar.
Vou testar quando chegar em casa, mas ao que parece é isso!
1 curtida