Recently there is a need, THINKPHP3.2 data in a total of 43 items, export time will be wrong Invalid cell coordinate [1
Because Phpexcel's cell.php in the default set of 26 columns, and the method of the default from A-Z and the next column is Aa1, and actually in Excel after Z should be AA,AB,AC,AD,AE,AF so need to change the method of judgment, I have written an Excel export, just need one of the methods to change, the idea is that when more than 26 columns when the next column should be named Aa,ab, rather than AA1,AA2, the improved method is as follows
protected function Getexcel ($fileName, $HEADARR, $data) {
Import the Phpexcel class library because Phpexcel does not use a namespace, only inport import
Import ("Org.Util.PHPExcel");
Import ("Org.Util.PHPExcel.Writer.Excel5");
Import ("Org.Util.PHPExcel.IOFactory.php");
$date = Date ("Y_m_d", Time ());
$fileName. = "_{$date}.xls";
Create a Phpexcel object, note that there is no less \
$objPHPExcel = new \phpexcel ();
$objProps = $objPHPExcel->getproperties ();
Set table header more than 26 columns
$key = 0;
foreach ($headArr as $v) {
Attention, no less. Converts a column number to a letter \
$colum = \phpexcel_cell::stringfromcolumnindex ($key);
$objPHPExcel->setactivesheetindex (0)->setcellvalue ($colum. ' 1 ', $v);
$key + = 1;
}
Set up the table header
$column = 2; Write data from the second line the first row is the table header
$objActSheet = $objPHPExcel->getactivesheet ();
foreach ($data as $key = + $rows) {//Line write
$span = 0;
foreach ($rows as $keyName = + $value) {//Column write
$j = \phpexcel_cell::stringfromcolumnindex ($span);
$objActSheet->setcellvalue ($j. $column, $value);
$span + +;
}
$column + +;
}
$fileName = Iconv ("Utf-8", "gb2312", $fileName);
Renaming a table
$objPHPExcel->getactivesheet ()->settitle (' Test ');
Set the activity Order index to the first table, so Excel opens this is the first table
$objPHPExcel->setactivesheetindex (0);
Ob_end_clean ();//clear buffer, avoid garbled
Header (' Content-type:application/vnd.ms-excel ');
Header ("content-disposition:attachment;filename=\" $fileName \ "");
Header (' cache-control:max-age=0 ');
$objWriter = \phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 ');
$objWriter->save (' php://output '); Files are downloaded through the browser
Exit
}
OK encounter its problems or other bugs can contact my group 84451248 dabigatran words please note Blog Park Big White donkey otherwise cannot pass.
Phpexcel how to export more than 26 columns of Excel data What to do Invalid cell coordinate [1 (developed encountered in THINKPHP3.2)