# Exportando tabelas para excel e acertando o formato dos campos

Como 'gerar' um arquivo excel com php, todo mundo já sabe:

`$arquivo = "export".date("dmY_His").".xls";`  
`header("Content-Type: text/plain");`  
`header("Content-Disposition: attachment; filename=\"$arquivo\";");`

Mas como fazer com que as colunas fiquem com os tipos de dados certos, como por exemplo, os campos de data?

Simples: Criando o seguinte css:

`.date {`  
`  mso-number-format:"Short Date";`  
`}`

E aplicando este estilo na célula da tabela que contém o valor que deve ser formatado.

Aqui tem os formatos aceitos: [http://cosicimiento.blogspot.com.br/2008/11/styling-excel-cells-with-mso-number.html](http://cosicimiento.blogspot.com.br/2008/11/styling-excel-cells-with-mso-number.html)  
  
<span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">Fonte:</span>  
[http://cosicimiento.blogspot.com.br/2008/11/styling-excel-cells-with-mso-number.html](http://cosicimiento.blogspot.com.br/2008/11/styling-excel-cells-with-mso-number.html)  
[http://stackoverflow.com/questions/354476/html-to-excel-how-can-tell-excel-to-treat-columns-as-numbers](http://stackoverflow.com/questions/354476/html-to-excel-how-can-tell-excel-to-treat-columns-as-numbers)