PHP commonly used to export the table has two methods, the first is the output table, this method opens with a warning prompt, the General export table will be used Phpexcel, this export is more flexible, but also can set the table style.
The first example of export
/**
* Perform export
* @param unknown $result data source
*/
function Excel ($result, $fileName = ', $Key = ') {
$fileName = iconv (' utf-8 ', ' GBK ', $fileName);
header ("Content-type:text/html;charset=utf-8");
header ("Content-type:application/octet-stream");
header ("Accept-ranges:bytes");
header ("Content-type:application/vnd.ms-excel");
header ("Content-disposition:attachment;filename= $fileName". Date ("y-m-d"). ". XLS ");
header ("Pragma:no-cache");
header ("expires:0");
//First line shows key
if (! $Key) {
$Key = Array ("name", "Gender", "mobile number", "intent Model", "Purchase Plan", "Submission Time");
}
echo iconv (' Utf-8 ', ' GBK ', implode ("\ T", $Key)). " \ n ";
//The third line shows the remaining Val
foreach ($result as $key = = $val) {
echo iconv (' Utf-8 ', ' GBK ', implode ("\ T", $val)). " \ n ";
}
}
The second type of export uses Phpexcel
/**
* Export data (Generate Excel)
* @param $data Excel first row of data
* Example: 1, Array (' field ' = ' 1 ');
* @param data exported $list a two-dimensional array
* @param string $title sheet name
* @param string $filename file name
* @return Boolean
*/
Public Function output1 ($data, $list, $title = ' data template ', $filename = ' data template ') {
$count = count ($data);//Array length
if (!is_array ($data) | | $count > $this->maxstr) {//Data meets requirements
return false;
}
Create New Phpexcel Object
$objPHPExcel = new \phpexcel ();
Set Document Properties
$objPHPExcel->getproperties ()->setcreator ("Maarten Balliauw")
->setlastmodifiedby ("Maarten Balliauw")
->settitle ("Office" XLSX Test Document ")
->setsubject ("Office" XLSX Test Document ")
->setdescription ("Test document for Office" XLSX, generated using PHP classes. ")
->setkeywords ("Office openxml PHP")
->setcategory ("Test result file");
ADD some data first line
Add some data first row
$SheetIndex = $objPHPExcel->setactivesheetindex (0);
$this->setattendance ($SheetIndex);//Write Data
Set the first cell style
$obActiveSheet = $objPHPExcel->getactivesheet ();
Set height
$obActiveSheet->getrowdimension (' 1 ')->setrowheight (40);
$obActiveSheet->getrowdimension (' 6 ')->setrowheight (100);
$obActiveSheet->getrowdimension (' 7 ')->setrowheight (90);
$obActiveSheet->getrowdimension (' 8 ')->setrowheight (90);
$obActiveSheet->getrowdimension (' 9 ')->setrowheight (90);
$obActiveSheet->getrowdimension (' Ten ')->setrowheight (80);
$obActiveSheet->getrowdimension (' n ')->setrowheight (20);
$obActiveSheet->getrowdimension ('->setrowheight ') (30);
$obActiveSheet->getrowdimension (' n ')->setrowheight (30);
Set width
$obActiveSheet->getcolumndimension (' A ')->setwidth (12);
$obActiveSheet->getcolumndimension (' B ')->setwidth (18);
$obActiveSheet->getcolumndimension (' C ')->setwidth (15);
$obActiveSheet->getcolumndimension (' D ')->setwidth (15);
$obActiveSheet->getcolumndimension (' E ')->setwidth (15);
$obActiveSheet->getcolumndimension (' H ')->setwidth (15);
Export
$this->outputphpexcel ($objPHPExcel, $filename);
}
/**
* Attendance Data Write
* @param $SheetIndex Cell Object
* @param $Cycle Cycle Data list
* @param $_clock Employee Attendance data
* @return Number returns the current maximum row count
*/
Private Function Setattendance ($SheetIndex) {
$c = 1;
/**----------------------------Attendance Head Start---------------------------------------*/
$chrA = Chr ($this->asciia + 0);//a
$chrB = Chr ($this->asciia + 1);//b
$chrC = Chr ($this->asciia + 2);//c
$chrD = Chr ($this->asciia + 3);//d
$chrE = Chr ($this->asciia + 4);//e
$chrF = Chr ($this->asciia + 5);//f
$chrG = Chr ($this->asciia + 6);//g
$chrH = Chr ($this->asciia + 7);//g
$chrI = Chr ($this->asciia + 8);//g
$chrJ = Chr ($this->asciia + 9);//g
$chrK = Chr ($this->asciia +);//g
$chrL = Chr ($this->asciia + one);//g
$chrM = Chr ($this->asciia +);//g
$chrN = Chr ($this->asciia +);//g
$chrO = Chr ($this->asciia +);//g
$SheetIndex->setcellvalueexplicit ($chrA. ( $c), ' Post assessment template ');
$SheetIndex->mergecells ($chrA. ( $c). ': ' $chrO. ($c)); /Merge Cell A2,a3
$SheetIndex->setcellvalueexplicit ($chrA. ( $c + 1), ' evaluated by person ');
$SheetIndex->mergecells ($chrA. ( $c + 1). ': ' $chrA. ($c +2)); /Merge Cell A2,a3
$SheetIndex->setcellvalueexplicit ($chrB. ( $c + 1), ' name ');
$SheetIndex->setcellvalueexplicit ($chrB. ( $c +2), ' title ');
$SheetIndex->setcellvalueexplicit ($chrC. ( $c + 1), ' xxx ');
$SheetIndex->setcellvalueexplicit ($chrD. ( $c + 1), ' Department ');
$SheetIndex->setcellvalueexplicit ($chrD. ( $c +2), ' entry Time ');
$SheetIndex->setcellvalueexplicit ($chrE. ( $c + 1), ' website Development Department ');
$SheetIndex->mergecells ($chrE. ( $c + 1). ': ' $chrG. ($c + 1)); /Merge Cells
$SheetIndex->mergecells ($chrE. ( $c +2). ': ' $chrG. ($c +2)); /Merge Cells
$SheetIndex->setcellvalueexplicit ($chrH. ( $c + 1), ' Supervisor of the person being assessed ');
$SheetIndex->mergecells ($chrH. ( $c + 1). ': ' $chrI. ($c + 1)); /Merge Cells
$SheetIndex->mergecells ($chrH. ( $c +2). ': ' $chrI. ($c +2)); /Merge Cells
$SheetIndex->setcellvalueexplicit ($chrJ. ( $c + 1), ' name ');
$SheetIndex->setcellvalueexplicit ($chrJ. ( $c +2), ' title ');
$SheetIndex->setcellvalueexplicit ($chrK. ( $c + 1), ' xxx ';
$SheetIndex->mergecells ($chrK. ( $c + 1). ': ' $chrO. ($c + 1)); /Merge Cells
$SheetIndex->mergecells ($chrK. ( $c +2). ': ' $chrO. ($c +2)); /Merge Cells
$SheetIndex->mergecells ($chrA. ( $c +3). ': ' $chrO. ($c +3)); /Merge Cells
Line 5th
$SheetIndex->setcellvalueexplicit ($chrA. ( $c +4), ' serial number ');
$SheetIndex->setcellvalueexplicit ($chrB. ( $c +4), ' indicator name ');
$SheetIndex->setcellvalueexplicit ($chrC. ( $c +4), ' weight ');
$SheetIndex->setcellvalueexplicit ($chrD. ( $c +4), ' measurement method ');
$SheetIndex->setcellvalueexplicit ($chrM. ( $c +4), ' assessment ');
$SheetIndex->setcellvalueexplicit ($chrN. ( $c +4), ' score ');
$SheetIndex->setcellvalueexplicit ($chrO. ( $c +4), ' final score ');
$SheetIndex->mergecells ($chrD. ( $c +4). ': ' $chrL. ($c +4)); /Merge Cells
Line 6th
$SheetIndex->setcellvalueexplicit ($chrA. ( $c +5), ' 1 ');
$SheetIndex->setcellvalueexplicit ($chrB. ( $c +5), ' completion of work ');
$SheetIndex->setcellvalueexplicit ($chrC. ( $c +5), ' 30% ');
$SheetIndex->setcellvalueexplicit ($chrD. ( $c +5), "A +: Test no crashes, severe and no high-level bugs
A: Test no crashes, severe and high-level bug control within 1% of all bugs, mid-level bug control at 10%
100: Test no crashes, severe and high-level bug control within 2% of all bugs, mid-level bug control at 20%
B: Test no crashes, severe and high-level bug control at 5% of all bugs, there is a bug in the user feedback system that has minor impact on the system, such as copy, compatibility, etc.
B-: There is a crash serious bug or no hit serious bug but there are more than 5% high-level bug, the use of feedback in the use of function can not be used, 500, 404 and Other Serious failure ");
$SheetIndex->setcellvalueexplicit ($chrM. ( $c +5), ' 100 ');
$SheetIndex->setcellvalueexplicit ($chrN. ( $c +5), ' 100 ');
$SheetIndex->setcellvalueexplicit ($chrO. ( $c +5), ' 30 ');
$SheetIndex->mergecells ($chrD. ( $c +5). ': ' $chrL. ($c +5)); /Merge Cells
}
This is just part of the code
PHP Export Table Two methods--phpexcel the case