Saídas em formato compatível Excel

Uma tabela deste estilo pode ser interpretada por excel:

que nos mostraria algo deste estilo:

O truque consiste em indicar ao navegador cliente que o que vai receber não é uma página HTML, e sim, um arquivo excel, isto o indicaremos com a instrução asp:

<%Response.ContentType = “application/vnd.ms-excel”%>

No exemplo o que vamos executar é o seguinte código asp:

<html>

<head>
<% Response.Buffer = TRUE
Response.ContentType = “application/vnd.ms-excel”%>

<title>Exemplo de compatibilidade Excel</title>
</head>

<body>
<table border=”1″ width=”60%”>
<tr>
<td width=”50%” align=”center” bgcolor=”#C0C0C0″>Nº de Fatura</td>
<td width=”50%” align=”center” bgcolor=”#C0C0C0″>Importe</td>
</tr>
<tr>
<td width=”50%” align=”center”>1</td>
<td width=”50%” align=”center”>12000</td>
</tr>
<tr>
<td width=”50%” align=”center”>2</td>
<td width=”50%” align=”center”>24000</td>
</tr>
<tr>
<td width=”50%” align=”center”> </td>
<td width=”50%” align=”center”><b>=SOMA(B2:B3)</b></td>
</tr>
</table>

</body>

</html>

Quando executarmos o navegador nos dará a opção de salvar o arquivo ou executa-lo através da rede, escolheremos a opção que mais nos interessar.

Fonte: http://www.criarweb.com/artigos/saidas-formato-compativel-excel.html

Deixe um comentário