on 11-17-2016 5:53 AM
Hello Experts, ( I should say saviors 🙂 )
I am trying to read an XLSX file and convert it to XML using java mapping.I have addded following Apache POI files in classpath:
poi-ooxml-3.9.jar
poi-ooxml-3.10-FINAL-20140208.jar
poi-ooxml-schemas-3.10-FINAL-20140208.jar
stax-api-1.0.1.jar
xmlbeans-2.3.0.jar
poi-3.15-beta2.jar
dom4j-1.6.1-sources.jar
.The code complies but it throws below exception while execution:
Exception in thread "main" java.lang.IllegalAccessError: org/apache/poi/util/POILogger.log(ILjava/lang/Object;)V
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:304)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:156)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:124)
at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:559)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:112)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:83)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:128)
at org.apache.poi.openxml4j.opc.ZipPackagePart.<init>(ZipPackagePart.java:78)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:218)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:662)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:269)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:204)
at com.reader.XlsxReader.main(XlsxReader.java:36).
The below code is currently reading the XLSX:
package com.reader;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; //New imports to read XLSX format
import org.apache.poi.xssf.usermodel.XSSFWorkbook; //New imports to read XLSX format
public class XlsxReader {
public static void main(String[] args) throws IOException {
FileInputStream fin = new FileInputStream("D:\\Test\\Empl.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(fin);
XSSFSheet sheetIn = wb.getSheetAt(0);
int rows = sheetIn.getLastRowNum();
for (int row = 0; row <= rows; row++) {
XSSFRow xcelRow = sheetIn.getRow(row);
int columns = xcelRow.getLastCellNum();
for (int col = 0; col <= columns; col++) {
Cell cell = xcelRow.getCell(col);
String cellVal = null;
System.out.print("ROW[" + row + "] Col[" + col + "]");
if (cell != null) {
if (0 == cell.getCellType()) {
Double dVal = cell.getNumericCellValue();
cellVal = dVal.toString();
} else
cellVal = cell.getStringCellValue();
System.out.println(cellVal);
}
}
}
wb.close();
fin.close();
}
}
Please excuse me for such a long message but I could not find any attachment options Could you please guide me where I am wrong?
Thanks,
Indu Khurana.
User | Count |
---|---|
89 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.