POI 错误: 处理 OLE2 格式数据 - 使用 HSSF 模块
The error message suggests that the data you are trying to process is in the OLE2 format, which is the binary file format used by older versions of Microsoft Office. However, you are currently using POI's OOXML module, which is designed to handle the newer Office Open XML format. \n\nTo resolve this issue, you need to switch to using a different part of POI that can handle the OLE2 format. In this case, you should use the HSSF module instead of XSSF. \n\nHere's an example of how you can modify your code to use HSSF: \n\njava \n// Import the necessary POI classes for HSSF \nimport org.apache.poi.hssf.usermodel.HSSFWorkbook; \nimport org.apache.poi.hssf.usermodel.HSSFSheet; \nimport org.apache.poi.hssf.usermodel.HSSFRow; \nimport org.apache.poi.hssf.usermodel.HSSFCell; \n\n// Create a new HSSFWorkbook object to work with the OLE2 data \nHSSFWorkbook workbook = new HSSFWorkbook(inputStream); \n\n// Get the first sheet from the workbook \nHSSFSheet sheet = workbook.getSheetAt(0); \n\n// Iterate over the rows and cells of the sheet \nfor (Row row : sheet) { \n for (Cell cell : row) { \n // Process each cell as needed \n // ... \n } \n} \n\n// Don't forget to close the workbook and input stream when you're done \nworkbook.close(); \ninputStream.close(); \n \n\nBy using the HSSF classes, you can process the OLE2 data successfully.'}
原文地址: https://www.cveoy.top/t/topic/pArX 著作权归作者所有。请勿转载和采集!