Reputation: 3
I'm having difficulty getting a Servlet
to create an Excel file using apache POI
.
When I use the following code in a separate Java class it works fine, but when I copy the code into the servlet, the servlet just doesn't create the excel file.
This is essentially all that is in the servlet. I get parameters and just store those. I want to just get the servlet to create the file first, then start adding the user input in later.
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet 1");
Cell cell1 = sheet.createRow(0).createCell(3);
cell1.setCellValue("100000");
Cell cell2 = sheet.createRow(1).createCell(3);
cell2.setCellValue("Text text.");
FileOutputStream output = new FileOutputStream("SampSamp.xls");
workbook.write(output);
output.close();
Upvotes: 0
Views: 541
Reputation: 810
I tried your code and the file is created in c:\glassfish3\glassfish\domains\domain1\config
folder. Maybe you consider giving absolute path. For example : C:\temp\SamSamp.xls.
Upvotes: 1