代码在下边贴出来了,在从浏览器端下载的excel文件打不开,但是如果直接保存服务器上就可以打开,我的office是07不是版本问题,这是怎么回事,请高手指点。 require_once (Kohana::find_file('libraries/PHPExcel', 'IOFactory'));
require_once (Kohana::find_file('libraries/PHPExcel', 'RichText')); $output_excel_file = DOCROOT .$root['root'] . "votes".date('Y')."-".date('n') . ".xlsx";// Create new PHPExcel object
$objPHPExcel = new PHPExcel();// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("votes")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1',$title)
->setCellValue('A2', 'name')
->setCellValue('B2', 'count')
->setCellValue('A3', 'Hello')
->setCellValue('B3', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('votes');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
header('Content-Disposition: attachment;filename=votes.xlsx');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
// $objWriter->save($output_excel_file); //保存到服务器可以打开,数据完好
$objWriter->save('php://output');
require_once (Kohana::find_file('libraries/PHPExcel', 'RichText')); $output_excel_file = DOCROOT .$root['root'] . "votes".date('Y')."-".date('n') . ".xlsx";// Create new PHPExcel object
$objPHPExcel = new PHPExcel();// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("votes")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1',$title)
->setCellValue('A2', 'name')
->setCellValue('B2', 'count')
->setCellValue('A3', 'Hello')
->setCellValue('B3', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('votes');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
header('Content-Disposition: attachment;filename=votes.xlsx');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
// $objWriter->save($output_excel_file); //保存到服务器可以打开,数据完好
$objWriter->save('php://output');
解决方案 »
- php偷取UTF-8目标站出错
- 如下代码怎么按钮显示在搜索况的下面
- php采集问题
- 哪位老大深入剖析一下百度快照的内部机理,如何把爬下来的网页做成快照保存起来。
- 变成4个三角,散分.顺便问一下.
- 请教关于搜索功能的一个疑部.急.在线等
- require 和 include 作用怎么一样了?
- 好久没用PHP,不知道PHP有没有直接建立文件的函数?
- 关于COOKIE的调用,为什么调用时还得进行刷新才可得到传给COOKIE的传,我要真接得到值,求大侠们帮忙!!
- 形如 index.php/explore-page/colors/pink-color 的地址栏 应该怎么理解?
- PHP SMTP Error: Could not connect to SMTP host.
- php初学登录问题
使用这个玩意的可真不多,2003是打不开的,除非装上微软的大约30M的插件