一個最簡單phpExcel匯出的例子,麻煩指點一上

來源:互聯網
上載者:User
一個最簡單phpExcel匯出的例子,麻煩指點一下?
php版本 5.2 安全執行緒 vc6
伺服器:apache2.2 線程 模組載入方式(CLI)
其他頁面運轉正常


廢話少說,excel的匯出代碼,最簡單的測試代碼,但是下載以後開啟提示如下

重新命名無效的工作表名稱。

PHP code
setActiveSheetIndex(0);      $objActSheet = $objExcel->getActiveSheet();           //設定當前活動sheet的名稱      $objActSheet->setTitle(iconv('utf-8','gbk', "測試工作pu名字"));          //ROW 1$objActSheet->setCellValueByColumnAndRow(1,2,iconv('utf-8','gbk', "測試"));//ROW 2//ROW 3//擷取資料    //在瀏覽器匯出header("Content-Type: application/force-download");header('Content-Type: application/vnd.ms-excel');header("Content-Disposition: attachment;filename=\"匯出查詢.xls\"");header('Cache-Control: max-age=0');header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache"); // 建立檔案格式寫入對象執行個體, uncomment      $objWriter = new PHPExcel_Writer_Excel5($objExcel);         //到檔案      $objWriter->save("php://output");  ?>


------解決方案--------------------
require('config.php');//載入配置文
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ('Content-type: application/x-msexcel');
header ("Content-Disposition: attachment; filename=weibo.xls" );
header ("Content-Description: PHP/INTERBASE Generated Data" );
//
// the next lines demonstrate the generation of the Excel stream
//
$content = $db->getList("select * from weibo_baidu");
$num = count($content);

/*echo $num;
foreach($content as $k=>$contents){
echo $aa=$k+1;
echo "
";
//echo $contents['b_title']."
";
}*/
xlsBOF(); // begin Excel stream
xlsWriteLabel(0, 0,iconv("UTF-8", "GBK",序號) );
xlsWriteLabel(0, 1,iconv("UTF-8", "GBK",發行者));
xlsWriteLabel(0, 2,iconv("UTF-8", "GBK",內容概要) );
xlsWriteLabel(0, 3,iconv("UTF-8", "GBK",URl));
xlsWriteLabel(0, 4,iconv("UTF-8", "GBK",來源));
xlsWriteLabel(0, 5,iconv("UTF-8", "GBK",抓取日期));
foreach($content as $k=>$contents){
$i=$k+1;
xlsWriteLabel($i, 0, $i);
xlsWriteLabel($i, 1, iconv("UTF-8", "GBK",$contents['b_title']));
xlsWriteLabel($i, 2, iconv("UTF-8", "GBK",$contents['b_info']));
xlsWriteLabel($i, 3, iconv("UTF-8", "GBK",$contents['b_url']));
xlsWriteLabel($i, 4, iconv("UTF-8", "GBK",$contents['b_source']));
xlsWriteLabel($i, 5, iconv("UTF-8", "GBK",$contents['b_tiem']));
}
xlsEOF(); // close the stream


// ----- begin of function library -----
// Excel begin of file header
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
// Excel end of file footer
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
// Function to write a Number (double) into Row, Col
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.