标签:ci、phpexcel
header(‘Content-Type: application/vnd.ms-excel‘);
header(‘Content-Disposition: attachment;filename="123.csv"‘);
header(‘Cache-Control: max-age=0‘);
$this->load->library(‘PHPExcel‘);
//设置文件属性
$this->phpexcel->getProperties()->setCreator(‘林泉‘);
$this->phpexcel->getProperties()->setLastModifiedBy(‘林泉‘);
$this->phpexcel->getProperties()->setTitle(‘PHPExcel测试‘);
$this->phpexcel->getProperties()->setSubject(‘PHPExcel测试‘);
$this->phpexcel->getProperties()->setDescription(‘这个是测试‘);
$this->phpexcel->getProperties()->setKeywords(‘PHP Excel 测试‘);
$this->phpexcel->getProperties()->setCategory(‘我我我‘);
//添加数据
$this->phpexcel->setActiveSheetIndex(0);
for($i=1;$i<21;$i++){
$this->phpexcel->getActiveSheet()->setCellValue(‘A‘.$i,$i);
$this->phpexcel->getActiveSheet()->setCellValue(‘B‘.$i,10*$i);
$this->phpexcel->getActiveSheet()->setCellValue(‘C‘.$i,100*$i);
$this->phpexcel->getActiveSheet()->setCellValue(‘D‘.$i,time());
}
//写文件
$obj_writer = new PHPExcel_Writer_CSV($this->phpexcel);
$obj_writer->setDelimiter(‘;‘);
$obj_writer->setEnclosure(‘‘);
$obj_writer->setLineEnding(‘\r\n‘);
$obj_writer->setSheetIndex(0);
$obj_writer->save(‘php://output‘);
标签:ci、phpexcel
原文地址:http://1150895809.blog.51cto.com/9164250/1772353