i want create file. xls in java, not want him stored anywhere. want created , presented download.
i have following code, after downloading excel file says file not valid.
private void criarficheirodeexemplo(requestcontext requestcontext) throws ioexception, interruptedexception { requestcontext.sresponse.setcontenttype("excel.application"); requestcontext.sresponse.setheader("content-disposition", "attachment; filename =ficheiro_de_exemplo_incidencias.xls"); java.io.printwriter pw = requestcontext.sresponse.getwriter(); string ficheiro = construirformatoficheirodeexemplo(); pw.println(ficheiro); pw.flush(); thread.sleep(2000); pw.close(); } private string construirformatoficheirodeexemplo() { stringbuffer html = new stringbuffer(); html.append("<table>"); //"cria" tabela html.append("<tr>"); html.append("<td>"); html.append("<strong>id_incidencia</strong>"); html.append("</td>"); html.append("</tr>"); //"cria" uma linha e uma coluna html.append("</table>"); return html.tostring(); }
any suggestions?
save file disk , open in text editor see if contains expect. if does, , excel won't open it, problem isn't download process. problem what's in file.
if don't want mess around generating excel-format binary data, , don't need formulas in spreadsheet, can excel open tsv or csv format (which plain text).
Comments
Post a Comment