我已经从http://phpexportxlsclass.googlecode.com/files/export-xls.class-v1.01.zip下载了 php excel 导出器库
如果我从 zip 独立运行 demo.php 文件,它工作正常。
我已将 export-xls.class.php 文件包含在库文件夹中,并从控制器调用该库
这是代码片段
function export_to_excel() {
require(APPPATH.'libraries/exportxls.php');
$config['filename'] = 'test1.xls'; // The file name you want any resulting file to be called.
$xls = new ExportXLS($config);
$xls->addHeader("Test Spreadsheet");
$xls->addHeader(null);
$header = array("Name", "Age", "Height");
$xls->addHeader($header);
$row = array();
$row[] = array('Jack', '24', '6ft');
$row[] = array('Jim', '22', '5ft');
$row[] = array('Jess', '54', '4ft');
$row[] = array('Luke', '6', '2ft');
$xls->addRow($row);
$xls->sendFile();
}
但是当我使用 url 运行我的代码时,http://www.domain.com/controller/export_to_excel
它会给我以下 excel 文件作为输出。