PEAR::Spreadsheet_Excel_WriterやJakarta POIなしでEXCEL形式でダウンロード
既知のネタですが、ふと気になったので。
Microsoftの製品(OSを除く)でもEXCELだけはよく使ってます。で、HTMLとの親和性が結構高いので、適切なresponseヘッダとHTMLの表組みを書くだけでEXCELファイルとしてダウンロードできます。
簡単な帳票だったら、これで良いじゃん!と思うんですけど、どうでしょう?以下はPHPの例です。
<?php header("Content-Type: application/vnd.ms-excel"); /** * ファイル名 * @see http://ns1.php.gr.jp/pipermail/php-users/2002-July/008509.html */ $filename = '検索検索.xls'; if (ereg(' MSIE ', $_SERVER["HTTP_USER_AGENT"])) { $encoding = 'sjis'; } else { $encoding = mb_http_output(); // Firefox } $filename = mb_convert_encoding( $filename, $encoding, mb_internal_encoding()); $download_data =<<<EOD <table border="1" cellpadding="0" cellspacing="0"> <tr class="with-border" align="center"> <th nowrap bgcolor="#c8c8c8">id</th> <th nowrap bgcolor="#c8c8c8">合計1</th> <th nowrap bgcolor="#c8c8c8">合計2</th> <th nowrap bgcolor="#c8c8c8">最終更新日時</th> </tr> <tr class="with-border"> <td bgcolor="#cccccc" align="right" nowrap>1</td> <td bgcolor="#ffffff" class="data">512</td> <td bgcolor="#ffffff" class="data">1024</td> <td bgcolor="#ffffff" align="center">2006/12/04</td> </tr> <tr class="with-border"> <td bgcolor="#cccccc" align="right" nowrap>2</td> <td bgcolor="#ffffff" class="data">1024</td> <td bgcolor="#ffffff" class="data">2048</td> <td bgcolor="#ffffff" align="center">2006/12/04</td> </tr> <tr class="with-border"> <td bgcolor="#cccccc" align="right" nowrap>3</td> <td bgcolor="#ffffff" class="data">2048</td> <td bgcolor="#ffffff" class="data">4096</td> <td bgcolor="#ffffff" align="center">2006/12/04</td> </tr> </table> EOD; header('Content-Disposition: attachment; filename=' . $filename); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0,pre-check=0'); header('Pragma: public'); echo mb_convert_encoding($download_data, 'sjis', mb_internal_encoding()); ?>