Cannot download Excel file created on server onto client's chosen target directory [message #1860935] |
Sun, 10 September 2023 07:02  |
Eclipse User |
|
|
|
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 07:10] by Moderator
|
|
|
|
Re: Cannot download Excel file created on server onto client's chosen target directory [message #1860978 is a reply to message #1860936] |
Tue, 12 September 2023 16:18  |
Eclipse User |
|
|
|
Thanks a million, Mr Robot. The file is now downloaded directly into the client's "Downloads" folder, if a default folder was set for downloaded files.
To test the "Save As...." prompt, I removed the setting for a default "Downloads" folder in my browser. The "Save As" dialog then displays correctly
and the client can save the file where he wants to, within the limits of the file system permissions.
Cheers,
JD
|
|
|
Powered by
FUDForum. Page generated in 0.24401 seconds