Cannot download Excel file created on server onto client's chosen target directory [message #1860935] |
Sun, 10 September 2023 11:02 |
J D Messages: 103 Registered: February 2021 |
Senior Member |
|
|
Hi there everyone,
I can successfully export table data to an Excel file using the Apache POI library. See the method below:
private void persistExcelTable(ITable t) {
FileOutputStream out;
String fileName;
try (XSSFWorkbook workbook = new XSSFWorkbook()) {
if (StringUtility.isNullOrEmpty(invokerName)) {
fileName = "/home/admin/Desktop/YGApp Export "
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+ ".xlsx";
} else {
fileName = "/home/admin/Desktop/YGApp " + invokerName + " "
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+ ".xlsx";
}
out = new FileOutputStream(new File(fileName));
XSSFSheet sheet = workbook
.createSheet(TEXTS.get("Sheet") + String.valueOf(workbook.getNumberOfSheets() + 1));
..... more code ....
//
workbook.write(out);
// download the file to the client session
// See
// https://www.eclipse.org/forums/index.php/m/1440415/?srch=download+excel+file#msg_1440415
ClientSession.get().getDesktop().openUri(fileName, OpenUriAction.DOWNLOAD);
} catch (Exception e) {
throw new VetoException(e.getMessage());
}
}
The file is visible on the desktop of the server because that is where it was created but I want users to be able to download the files into a directory of their choice on their devices (computer/tablet/telephone).
While I was looking around on the forum for tips, I came across
https://www.eclipse.org/forums/index.php/m/1440415/?srch=download+excel+file#msg_1440415
and I used
ClientSession.get().getDesktop().openUri(fileName, OpenUriAction.DOWNLOAD);
to try and download the file to a local client directory, but it doesn't seem to work. Looking at the logs, I see the message
2023-09-10 12:39:43,483 INFO [qtp835227336-42] org.eclipse.scout.rt.ui.html.UiServlet.sendNotFound(UiServlet.java:275) - 404_NOT_FOUND: GET /home/admin/Desktop/YGApp Companies 2023-09-10 12:39:42.xlsx
However, the file is there on the server! What am I doing wrong?
What I would like ideally is after the file is created, a SaveDialog is presented to the user that lets the user chose where the file will be saved and then the file is downloaded there in the same way that a browser downloads files.
Thanks a million for your assistance.
Cheers,
JD
[Updated on: Sun, 10 September 2023 11:10] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03830 seconds