I am trying to read in a text file, and then apply some data validations rules on it. After adding the rules I then write data back onto an excel file.
But when trying to write it back to the excel file I get this error:
Exception in thread "main" org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : The part /docProps/app.xml fail to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller@74ad1f1f at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:479) at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1414) at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:179) at com.gbt.POC.TxtFileReader.main(TxtFileReader.java:359) Caused by: org.apache.poi.openxml4j.exceptions.OpenXML4JException: The part /docProps/app.xml fail to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller@74ad1f1f at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:470) ... 3 more
Here is what I have so far:
LinkedList < String[] > llist = new LinkedList < > ();
String[] data;
XSSFWorkbook workBook = new XSSFWorkbook();
FileOutputStream outstream = new FileOutputStream("data.xls");
XSSFSheet spreadSheet = workBook.createSheet("Clean");
for (int i = 0; i < llist.size(); i++) {
if (i == 0) {
System.out.println("Hello World!");
} else {
data = llist.get(i);
String empid1 = data[0];
String fname = data[1];
String ccode1 = data[2];
if (data[2].equals("IND")) {
replace = data[2].replaceAll("IND", "IN");
ccode1 = replace;
} else if (data[2].equals("USA")) {
replace = data[2].replaceAll("USA", "US");
ccode1 = replace;
} else {
ccode1 = data[2];
}
//String newData=empid1+","+fname+","+ccode1;
XSSFRow row = spreadSheet.createRow(i);
XSSFCell cell = row.createCell(0);
cell.setCellValue(empid1);
cell = row.createCell(1);
cell.setCellValue(fname);
cell = row.createCell(2);
cell.setCellValue(ccode1);
}
}
workBook.write(outstream);
Any help is appreciated in advance.