I'm trying to create a document (excel/word) and then send it to browser for downloading.
The file is created within eclipse directory but I'm not getting a dialog to save/downlaod the file. Instead I have characters like " ������Root Entry���������Workbook������������������ ��A����\php B�a=���=h:�#8X@�"��1���Arial1���Arial1���Arial1���Arial"$"#,##0_);("$"#,##0)"$"#,##0_);[Red]0);(* "-");(@)5)0_("$"* #,##0_);("� ������������������`�bSheet0��� Some text� D � ��X d����MbP?*+��%������"d,,�?�?U�� �">�@ ��"
Here is my code for (excel):
public void exportResults_EXCEL(ActionRequest actionRequest, ActionResponse actionResponse)throws IOException,PortletException{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellValue("Some text");
// write it as an excel attachment
ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
wb.write(outByteStream);
ByteArrayInputStream excelStream = new ByteArrayInputStream(outByteStream.toByteArray());
byte [] outArray = outByteStream.toByteArray();
HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=something.xls");
response.setContentLength(outArray.length);
ServletResponseUtil.sendFile(request, response, "something.xls" ,outArray, ContentTypes.APPLICATION_VND_MS_EXCEL);
FileOutputStream output = new FileOutputStream(new File("something.xls"));
ServletOutputStream out = response.getOutputStream();
wb.write(output);
output.flush();
output.close();
}
P.S ! I'm using eclipse, liferay, poi