Hallo Zusammen
Ich möchte in einer REST Funktion Daten als XLSX zurück geben. Via Java Bindings wollte ich in der Xquery Funktion die Apache POI nutzen und habe mal versucht das einfache Beispiel der JSP Seite zu übersetzen, scheitere nun aber an der Meldung "[XPST0017] Several implementations found for …. „ beim Aufruf der Funktion createSheet().
Einfacher Versuch - XQ Funktion.
import module namespace xlsx = "org.apache.poi.xssf.usermodel.XSSFWorkbook";
declare %rest:path('/test') function root:test( ) { let $sheet := xlsx:createSheet() let $row := $sheet:createRow(0) let $cell := $row:createCell(0) return $cell:setCellValue("Some text“) };
JSP Source: <%@page import="org.apache.poi.xssf.usermodel.*" %><%@page import="java.io.*" %><%
// create a small spreadsheet if xls then HSSF.... instead of XSSF.... for xlsx XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell(0); cell.setCellValue("Some text");
// write it as an excel attachment ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); wb.write(outByteStream); byte [] outArray = outByteStream.toByteArray(); //response.setContentType("application/ms-excel"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setContentLength(outArray.length); response.setHeader("Expires:", "0"); // eliminates browser caching //response.setHeader("Content-Disposition", "attachment; filename=testxls.xls"); response.setHeader("Content-Disposition", "attachment; filename=testxls.xlsx"); OutputStream outStream = response.getOutputStream(); outStream.write(outArray); outStream.flush();
%>
Die Dokumentation konnte mir das weitere Vorgehen nicht so ganz aufzeigen. Hat jemand das Apache POI schonmal in XQuery genutzt?
Beim Lesen der Doku und den Beispielen bekomme ich den Eindruck, nicht um das Schreiben einer eigenen JAVA Klasse herum zu kommen.
VG Arthur
Hi Arthur,
scheitere nun aber an der Meldung "[XPST0017] Several implementations found for …. „ beim Aufruf der Funktion createSheet().
I guess the full error message includes the name of the Java method? It seems that the XSSFWorkbook class has more than one of this function with the same number of arguments.
I would suggest writing a Java wrapper class, which calls the appropriate Java code, and which you call from XQuery instead.
Hope this helps, Christian
import module namespace xlsx = "org.apache.poi.xssf.usermodel.XSSFWorkbook";
declare %rest:path('/test') function root:test( ) { let $sheet := xlsx:createSheet() let $row := $sheet:createRow(0) let $cell := $row:createCell(0) return $cell:setCellValue("Some text“) };
JSP Source: <%@page import="org.apache.poi.xssf.usermodel.*" %><%@page import="java.io.*" %><%
// create a small spreadsheet if xls then HSSF.... instead of XSSF.... for xlsx XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell(0); cell.setCellValue("Some text");
// write it as an excel attachment ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); wb.write(outByteStream); byte [] outArray = outByteStream.toByteArray(); //response.setContentType("application/ms-excel"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setContentLength(outArray.length); response.setHeader("Expires:", "0"); // eliminates browser caching //response.setHeader("Content-Disposition", "attachment; filename=testxls.xls"); response.setHeader("Content-Disposition", "attachment; filename=testxls.xlsx"); OutputStream outStream = response.getOutputStream(); outStream.write(outArray); outStream.flush();
%>
Die Dokumentation konnte mir das weitere Vorgehen nicht so ganz aufzeigen. Hat jemand das Apache POI schonmal in XQuery genutzt?
Beim Lesen der Doku und den Beispielen bekomme ich den Eindruck, nicht um das Schreiben einer eigenen JAVA Klasse herum zu kommen.
VG Arthur
basex-talk@mailman.uni-konstanz.de