Currenty I am trying to read an Excel file that is polled via Apache Camel (2.25.1). This means the method gets the file contents via a String:
@Handler
public void processFile(@Body String body) {
For reading the Excel file I use Apache POI and POI-ooxml (both 4.1.2).
However, using the String directly
WorkbookFactory.create(new ByteArrayInputStream(body.getBytes(Charset.forName("UTF-8"))))
throws an "java.io.IOException: ZIP entry size is too large or invalid".
Using the String with other encodings:
WorkbookFactory.create(new ByteArrayInputStream(body.getBytes()))
throw "org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException: No valid entries or contents found, this is not a valid OOXML (Office Open XML) file".
Besides, I tried:
File file = exchange.getIn().getBody(File.class);
Workbook workbook = new XSSFWorkbook(new FileInputStream(file));
Probably because the file is read from an FTP-server, a java.io.FileNotFoundException is thrown: Invalid file path
However, the next code does work:
URL url = new URL(fileFtpPath);
URLConnection urlc = url.openConnection();
InputStream ftpIs = urlc.getInputStream();
Workbook workbook = new XSSFWorkbook(ftpIs);
But I prefer not making a connection to the FTP server myself, since Camel has already read the file and the needed Excel contents are available (in String body). Is there any way to read the contents of the Excel file from the String with Apache POI?