php產生excel 求解

來源:互聯網
上載者:User
在網上找了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

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.