在網上找了phpexcel 產生了個簡單的檔案, 但最後他是用save方法 儲存下來的 ,好像是輸出到php://output( 我的理解),後台許可權沒過(好像不能訪問這個地址,我已經登入了後台) 然後下載的檔案是登入的那個網頁 產生到伺服器端 然後重新導向下載是沒問題的 但這樣 我不好刪除這個檔案 對phpexcel不熟 求解 還是說換個庫~~~
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');$objWriter->save(str_replace('.php', '.xls', __FILE__));$callEndTime = microtime(true);$callTime = $callEndTime - $callStartTime;
回複討論(解決方案)
上面代碼搞錯了 具體組建檔案代碼如下 :
getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Test Document") ->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', 'Hello') ->setCellValue('B2', 'world!') ->setCellValue('C1', 'Hello') ->setCellValue('D2', 'world!');// Miscellaneous glyphs, UTF-8$objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A4', 'Miscellaneous glyphs') ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');// Rename worksheet$objPHPExcel->getActiveSheet()->setTitle('Simple');// 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.openxmlformats-officedocument.spreadsheetml.sheet');header('Content-Disposition: attachment;filename="01simple.xlsx"');header('Cache-Control: max-age=0');// If you're serving to IE 9, then the following may be neededheader('Cache-Control: max-age=1');// If you're serving to IE over SSL, then the following may be neededheader ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the pastheader ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modifiedheader ('Cache-Control: cache, must-revalidate'); // HTTP/1.1header ('Pragma: public'); // HTTP/1.0$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');$objWriter->save('php://output');exit;
從 61 都 71 行都是為了向瀏覽器輸出做的準備工作
如果你只是想儲存到檔案只需
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('檔案名稱');
即可
換csv吧。 現在還用什麼xls
fgetcsv 讀
fputcsv 寫
單純匯出Excel檔案
http://jingyan.baidu.com/article/915fc414f4c2e451384b205c.html
匯出帶圖片的Excel檔案:
http://jingyan.baidu.com/article/4f7d5712aea37f1a201927d7.html