-2

I am using jakartaPOI to create an excel file in my GWT application as it doesnt allow me to write the code on client side , So i have the code of writing excel file in my server side .

This creates an excel file correctly on server machine What I want is to create the same excel file on the client/user machine.

Is there a solution for this

Thanks

Code:

         try {
        FileOutputStream fileOut = new FileOutputStream("D:\\POI111.xls");
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet worksheet = workbook.createSheet("POI Worksheet");

        // index from 0,0... cell A1 is cell(0,0)
        HSSFRow row1 = worksheet.createRow((short) 0);

        HSSFCell cellA1 = row1.createCell((short) 0);
        cellA1.setCellValue(dto.getColumn1());


        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "exported";
}
junaidp
  • 10,801
  • 29
  • 89
  • 137
  • 1
    You cannot do that on the client. The code you write on the client side will get converted to plain javascript. Btw, what do you want to achieve? – pratZ Sep 03 '14 at 18:56
  • When my application is running , Users from different locations try to download excel file from my Application , But those excel files get downloaded on my machine , (because my machine is server), So WHat i want to acheive is saving those excel files to users machine not on server – junaidp Sep 04 '14 at 02:39
  • What do u want to do with the location? Number formatting? – pratZ Sep 04 '14 at 08:34
  • its very common, I mean just consider any Email application, We received an attachment in our email, we download the attachment, So that attached file save in our machine (client machine, not server).Thats what I want to do in my application... – junaidp Sep 04 '14 at 16:18

3 Answers3

1

You cannot save file to the client system using javascript(GWT client side). Java script cannot access the disk contents. So if you need to save the file in client system, one option is to generate the file in server side and let the client download that file and save it.

Syam Kumar S
  • 832
  • 2
  • 8
  • 26
0

seeing as GWT is compiled into javascript, and creating files of any kind is impossible (and rightly so) in javascript, what you would like to do is not possible in GWT. At the risk of being ruthlessly down voted you can do this with a flash script, not knowing flash at all I can't really tell you how. In spite of that, I would recommend abandoning the idea altogether. Altering the client side machine should not be done.

Assaf
  • 1,352
  • 10
  • 19
0

You probably want to download the file. So you should create the file on the server and pass the client an id which can be use to map the location of the file located on the server. Using a Servlet you should be able to download a file. As for your comment on Email Application file download, the file is not created on the client system, it is downloaded. You might want to look at the existing post on downloading file.

Community
  • 1
  • 1
pratZ
  • 3,078
  • 2
  • 20
  • 29