I am trying to use an excel to write the into new file using Apache POI. This is the method code,
<code>import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream;
import java.io.IOException;
class Scratch {
public static void main(String[] args) throws IOException {
XSSFWorkbook excelWB = null;
try {
String fileName = "C:\Users\frank\Desktop\Output\test.xlsx";
System.out.println("fileName: " + fileName);
excelWB = new XSSFWorkbook();
XSSFSheet sheet = excelWB.createSheet("PartList");
XSSFRow headerRow = sheet.createRow(0);
headerRow.createCell(0).setCellValue("Type");
XSSFRow dataRow = sheet.createRow(1);
dataRow.createCell(0).setCellValue("0th column");
dataRow.createCell(1).setCellValue("1st column");
FileOutputStream fileOut = new FileOutputStream(fileName);
excelWB.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
//assert excelWB != null;
excelWB.close();
}
}
}
</code>
<code>import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream;
import java.io.IOException;
class Scratch {
public static void main(String[] args) throws IOException {
XSSFWorkbook excelWB = null;
try {
String fileName = "C:\Users\frank\Desktop\Output\test.xlsx";
System.out.println("fileName: " + fileName);
excelWB = new XSSFWorkbook();
XSSFSheet sheet = excelWB.createSheet("PartList");
XSSFRow headerRow = sheet.createRow(0);
headerRow.createCell(0).setCellValue("Type");
XSSFRow dataRow = sheet.createRow(1);
dataRow.createCell(0).setCellValue("0th column");
dataRow.createCell(1).setCellValue("1st column");
FileOutputStream fileOut = new FileOutputStream(fileName);
excelWB.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
//assert excelWB != null;
excelWB.close();
}
}
}
</code>
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream;
import java.io.IOException;
class Scratch {
public static void main(String[] args) throws IOException {
XSSFWorkbook excelWB = null;
try {
String fileName = "C:\Users\frank\Desktop\Output\test.xlsx";
System.out.println("fileName: " + fileName);
excelWB = new XSSFWorkbook();
XSSFSheet sheet = excelWB.createSheet("PartList");
XSSFRow headerRow = sheet.createRow(0);
headerRow.createCell(0).setCellValue("Type");
XSSFRow dataRow = sheet.createRow(1);
dataRow.createCell(0).setCellValue("0th column");
dataRow.createCell(1).setCellValue("1st column");
FileOutputStream fileOut = new FileOutputStream(fileName);
excelWB.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
//assert excelWB != null;
excelWB.close();
}
}
}
It is giving me the error as below
<code>14:24:12.172 [main] WARN org.apache.poi.util.XMLHelper - SAX Feature unsupported [log suppressed for 5 minutes] http://javax.xml.XMLConstants/property/accessExternalStylesheet
java.lang.IllegalArgumentException: Not supported: http://javax.xml.XMLConstants/property/accessExternalStylesheet
at org.apache.xalan.processor.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:571)
at org.apache.poi.util.XMLHelper.trySet(XMLHelper.java:283)
at org.apache.poi.util.XMLHelper.getTransformerFactory(XMLHelper.java:224)
at org.apache.poi.util.XMLHelper.newTransformer(XMLHelper.java:230)
at org.apache.poi.openxml4j.opc.StreamHelper.saveXmlInStream(StreamHelper.java:56)
at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.saveImpl(ZipContentTypeManager.java:68)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.save(ContentTypeManager.java:450)
at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:563)
at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1490)
at org.apache.poi.ooxml.POIXMLDocument.write(POIXMLDocument.java:227)
at Scratch.main(20240726.excel.hata.java:27)
</code>
<code>14:24:12.172 [main] WARN org.apache.poi.util.XMLHelper - SAX Feature unsupported [log suppressed for 5 minutes] http://javax.xml.XMLConstants/property/accessExternalStylesheet
java.lang.IllegalArgumentException: Not supported: http://javax.xml.XMLConstants/property/accessExternalStylesheet
at org.apache.xalan.processor.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:571)
at org.apache.poi.util.XMLHelper.trySet(XMLHelper.java:283)
at org.apache.poi.util.XMLHelper.getTransformerFactory(XMLHelper.java:224)
at org.apache.poi.util.XMLHelper.newTransformer(XMLHelper.java:230)
at org.apache.poi.openxml4j.opc.StreamHelper.saveXmlInStream(StreamHelper.java:56)
at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.saveImpl(ZipContentTypeManager.java:68)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.save(ContentTypeManager.java:450)
at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:563)
at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1490)
at org.apache.poi.ooxml.POIXMLDocument.write(POIXMLDocument.java:227)
at Scratch.main(20240726.excel.hata.java:27)
</code>
14:24:12.172 [main] WARN org.apache.poi.util.XMLHelper - SAX Feature unsupported [log suppressed for 5 minutes] http://javax.xml.XMLConstants/property/accessExternalStylesheet
java.lang.IllegalArgumentException: Not supported: http://javax.xml.XMLConstants/property/accessExternalStylesheet
at org.apache.xalan.processor.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:571)
at org.apache.poi.util.XMLHelper.trySet(XMLHelper.java:283)
at org.apache.poi.util.XMLHelper.getTransformerFactory(XMLHelper.java:224)
at org.apache.poi.util.XMLHelper.newTransformer(XMLHelper.java:230)
at org.apache.poi.openxml4j.opc.StreamHelper.saveXmlInStream(StreamHelper.java:56)
at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.saveImpl(ZipContentTypeManager.java:68)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.save(ContentTypeManager.java:450)
at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:563)
at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1490)
at org.apache.poi.ooxml.POIXMLDocument.write(POIXMLDocument.java:227)
at Scratch.main(20240726.excel.hata.java:27)