Thanks to the work that I have learned a way to generate xls files with java, you typically use the Jakarta POI but the Web can do otherwise. Well for starters, when we created a xls file with pure html tables what we are doing is a flat file, when opening or wish to download in Firefox, the extension does not read but he knows that flat file is then shown in browser (sometimes).
to avoid problems and want to download the file and view it (depending on browser settings) created a JSP page and write the following
\u0026lt;% @ page contentType = "application / vnd.ms-excel "%>
\u0026lt;% @ page contentType = "application / vnd.ms-excel"%>
\u0026lt;% response.setHeader ("Content-Disposition", "attachment; filename = \\ "Filename.xls \\" ");%>
And after that write HTML tables.
This can also be done using a small servlet as follows:
VisualizarExcel public class extends HttpServlet {
private static final String CONTENT_TYPE = "application / vnd.ms-excel; charset = windows-1252 ";
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
response.setHeader("Content-Disposition", "attachment; filename=\"Archivo.xls\"");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>VisualizarExcel</title></head>");
out.println("<body>");
out.println("<table><tr><td>HOLA<td></tr></table>");
out.println ("\u0026lt;/ body> \u0026lt;/ html>");
out.close ();
}
}
Source: http://diesil-java.blogspot.com/2007/04/generar-xls.html
0 comments:
Post a Comment