Mostrando entradas con la etiqueta javaejemplo. Mostrar todas las entradas
Mostrando entradas con la etiqueta javaejemplo. Mostrar todas las entradas

sábado, 6 de marzo de 2010

Exportar de JSP a Excel (Table to Excel Java)

Una Forma rápida y fácil de obtener un excel a partir de un jsp puede ser de la siguiente manera:
Sólo agregando en la cabecera del documento

    response.setContentType ("application/vnd.ms-excel");
    response.setHeader ("Content-Disposition", "attachment;filename=\"report.xls\"");



Podemos comprenderlo mejor con el siguiente Ejemplo.


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

    pageEncoding="ISO-8859-1"%>

<%

    response.setContentType ("application/vnd.ms-excel"); //Tipo de fichero.

response.setHeader ("Content-Disposition", "attachment;filename=\"report.xls\"");

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

<TABLE border="1">

<TR>

<TH>CICLO</TH>

<TH>CODIGO</TH>

<TH>APELLIDOS Y NOMBRES</TH>

</TR>

<TR>

 <TD>1</TD>

   <TD>12233</TD>

   <TD>JocLuis</TD>

</TR>



</TABLE>

</body>

</html>