程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> DB2數據庫 >> DB2教程 >> 一鍵導出excel

一鍵導出excel

編輯:DB2教程

一鍵導出excel


怎樣一鍵導出excel

public function input() {

ob_end_clean(); //清除緩沖區,避免亂碼

header("Content-Typ:text/html;charset=utf-8");

vendor('Excel.PHPExcel.Writer.IWriter');

vendor('Excel.PHPExcel.Writer.Excel5');

vendor('Excel.PHPExcel');

vendor('Excel.PHPExcel.IOFactory');

$objPHPExcel = new PHPExcel();

$objPHPExcel->getActiveSheet()->setCellValue('A1',"ID"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('B1',"Studentname"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('C1',"IDcard"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('D1',"StudentID"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('E1',"ClassID"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('F1',"Sex"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('G1',"Nation"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('H1',"Birth"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('I1',"Imagepath"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('J1',"Huji"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('K1',"Phone"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('L1',"QQ"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('M1',"Email"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('N1',"Addressnow"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('O1',"Local"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('P1',"Position"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('Q1',"Macrosoft"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('R1',"CoachID"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('S1',"CarID"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('T1',"CartypeID"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('U1',"Introducer"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('V1',"Signdate"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('W1',"Signplace"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('X1',"Signgtype"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('Y1',"Lubiao"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('Z1',"Lubiaodate"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AA1',"Zhika"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AB1',"Zhikadate"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AC1',"Subtabdate"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AD1',"Begindate"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AE1',"Bigtabdate"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AF1', "Weier");//設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AG1',"Lixiao"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AH1',"Fingerprint"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AI1',"Inform"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AJ1',"SchoolID"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AK1',"Setting"); //設置列的值

$objPHPExcel->getActiveSheet()->setCellValue('AL1',"Remarks"); //設置列的值

$sql['Lixiao'] = '否';

$sql['SchoolID'] = "$_SESSION[SchoolID]";

$studentname = I('Studentname');

$idcard = I('IDcard');

if ($studentname != '') {

$sql['Studentname'] ="$studentname";

}

if ($idcard != '') {

$sql['IDcard'] ="$idcard";

};

$sql['_logic'] = 'AND';

$arr = M('studentinfo')->where($where)->select();

$count = count($arr); //求出有多少行;

$i = 2; //注意這是2;因為第一行我們已經設置了表頭信息

for ($j = 0; $j < $count; $j++) {

$objPHPExcel->setActiveSheetIndex(0)

->setCellValue('A' . $i,$arr[$j]['ID']) //注意這裡沒有分號結束

->setCellValue('B' . $i,$arr[$j]['Studentname'])

->setCellValue('C' . $i,$arr[$j]['IDcard'])

->setCellValue('D' . $i,$arr[$j]['StudentID'])

->setCellValue('E' . $i,$arr[$j]['ClassID'])

->setCellValue('F' . $i,$arr[$j]['Sex'])

->setCellValue('G' . $i,$arr[$j]['Nation'])

->setCellValue('H' . $i,$arr[$j]['Birth'])

->setCellValue('I' . $i,$arr[$j]['Imagepath'])

->setCellValue('G' . $i,$arr[$j]['Huji'])

->setCellValue('K' . $i,$arr[$j]['Phone'])

->setCellValue('L' . $i,$arr[$j]['QQ'])

->setCellValue('M' . $i,$arr[$j]['Email'])

->setCellValue('N' . $i,$arr[$j]['Addressnow'])

->setCellValue('O' . $i,$arr[$j]['Local'])

->setCellValue('P' . $i,$arr[$j]['Position'])

->setCellValue('Q' . $i,$arr[$j]['Macrosoft'])

->setCellValue('R' . $i,$arr[$j]['CoachID'])

->setCellValue('S' . $i,$arr[$j]['CarID'])

->setCellValue('T' . $i,$arr[$j]['CartypeID'])

->setCellValue('U' . $i,$arr[$j]['Introducer'])

->setCellValue('V' . $i,$arr[$j]['Signdate'])

->setCellValue('W' . $i,$arr[$j]['Signpalce'])

->setCellValue('X' . $i,$arr[$j]['Signgtype'])

->setCellValue('Y' . $i,$arr[$j]['Lubiao'])

->setCellValue('Z' . $i,$arr[$j]['Lubiaodate'])

->setCellValue('AA' .$i, $arr[$j]['Zhika'])

->setCellValue('AB' .$i, $arr[$j]['Zhikadate'])

->setCellValue('AC' .$i, $arr[$j]['Subtabdate'])

->setCellValue('AD' .$i, $arr[$j]['Begindate'])

->setCellValue('AE' .$i, $arr[$j]['Bigtabdate'])

->setCellValue('AF' .$i, $arr[$j]['Weier'])

->setCellValue('AG' .$i, $arr[$j]['Lixiao'])

->setCellValue('AH' . $i,$arr[$j]['Fingerprint'])

->setCellValue('AI' .$i, $arr[$j]['Inform'])

->setCellValue('AJ' .$i, $arr[$j]['SchoolID'])

->setCellValue('AK' .$i, $arr[$j]['Setting'])

->setCellValue('AL' .$i, $arr[$j]['Remarks']);

$i++;

}

$objPHPExcel->getActiveSheet(0)->setTitle('studentinfo');

$objPHPExcel->setActiveSheetIndex(0);

header('Content-Type:application/vnd.ms-excel');

header('Content-Disposition:attachment;filename="studentinfo.xls"');

header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

$objWriter->save('php://output');

}

Html文件中

<div style="float:right"> <formaction="{:U('input')}" > <input type="submit"value="一鍵導出EXCEL"></form></div>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved