When exporting PHP excel to excel, TP3.2 + PHPExcel is used for error reporting
Error page:
Public function outxls () {$ model = D ($ this-> dbname); $ map = $ this-> _ search (); if (method_exists ($ this, '_ filter') {$ this-> _ filter ($ map);} $ list = $ model-> where ($ map)-> field ('Id, status, yewujindu, fenlei, uid, juid, juname, uuid, uuname, xcrq, xingming, phone, type, introduce, introphone, daikuanpro, addtime, uname, addm, updatetime, sex, birth, marry, shenhu, shebaonianshu, shebaojishu, baoxianjiaoe ')-> select (); $ headArr = array ('id', 'progress', 'company name', 'next Contact ', 'contacts ', 'Adder', 'Add time', 'update time'); $ filename = 'customer management'; $ this-> xlsout ($ filename, $ headArr, $ list );}
I suspect that there are too many exported fields. you can export 26 fields. if you add another 27 fields, an error is returned. Where can I change the export field limit?
Reply to discussion (solution)
Invalid cell coordinate Invalid cell coordinates
Paste your xlsout method to see it!
Key: column number generation
Invalid cell coordinate Invalid cell coordinates
Paste your xlsout method to see it!
Key: column number generation
Public function xlsout ($ filename = 'data table ', $ headArr, $ list) {// import the PHPExcel class library. because PHPExcel does not use a namespace, only inport import ("Org. util. PHPExcel "); import (" Org. util. PHPExcel. writer. excel5 "); import (" Org. util. PHPExcel. IOFactory. php "); $ this-> getExcel ($ filename, $ headArr, $ list);} publicfunction getExcel ($ fileName, $ headArr, $ data) {// check the data if (empty ($ data) |! Is_array ($ data) {die ("data must be a array");} // check the file name if (empty ($ fileName) {exit ;} $ date = date ("Y_m_d", time (); $ fileName. = "_1_date).xls"; // Create a PHPExcel object. note: \ $ objPHPExcel = new \ PHPExcel (); $ objProps = $ objPHPExcel-> getProperties (); // Set the header $ key = ord ("A"); foreach ($ headArr as $ v) {$ colum = chr ($ key); $ objPHPExcel-> setActiveSheetIndex (0) -> setCellValue ($ colum. '1', $ v); $ key + = 1;} $ column = 2; $ objActSheet = $ objPHPExcel-> getActiveSheet (); // Set it to the text format foreach ($ data as $ key => $ rows) {// write $ span = ord ("A") in the row "); foreach ($ rows as $ keyName => $ value) {// write a column $ j = chr ($ span); $ objActSheet-> setCellValueExplicit ($ j. $ column, $ value); $ span ++ ;}$ column ++ ;}$ fileName = iconv ("UTF-8", "gb2312", $ fileName ); // rename the table // $ objPHPExcel-> getActiveSheet ()-> setTitle ('test'); // Set the activity ticket index to the first table, so in Excel, this is the first table $ objPHPExcel-> setActiveSheetIndex (0); ob_end_clean (); // clear the buffer to 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 '); // download exit from the browser ;}
$ Span = ord ("A"); foreach ($ rows as $ keyName => $ value) {// write A column $ j = chr ($ span ); $ objActSheet-> setCellValueExplicit ($ j. $ column, $ value); $ span ++ ;}
This is incorrect!
When $ span = ord ('Z') + 1, what chr ($ span) obtains is [
Obviously it is wrong. the correct one should be AA.
So we need such a function for calculation.
function CellName($n) { $r = ''; do { $m = $n % 26; $n = intval($n / 26); $r = chr(65 + $m - ($r ? 1 : 0)) . $r; }while($n > 0); return $r;}
Fortunately, php retains some features of the C language and can do this computation very easily.
$c = 'A';for($i=0; $i<100; $i++) printf("%s %s\n", $i, $c++);
With this feature, your program can write
$ Span = "A"; foreach ($ rows as $ keyName => $ value) {// write A column $ j = $ span; $ objActSheet-> setCellValueExplicit ($ j. $ column, $ value); $ span ++ ;}
$ Span = ord ("A"); foreach ($ rows as $ keyName => $ value) {// write A column $ j = chr ($ span ); $ objActSheet-> setCellValueExplicit ($ j. $ column, $ value); $ span ++ ;}
This is incorrect!
When $ span = ord ('Z') + 1, what chr ($ span) obtains is [
Obviously it is wrong. the correct one should be AA.
So we need such a function for calculation.
function CellName($n) { $r = ''; do { $m = $n % 26; $n = intval($n / 26); $r = chr(65 + $m - ($r ? 1 : 0)) . $r; }while($n > 0); return $r;}
Fortunately, php retains some features of the C language and can do this computation very easily.
$c = 'A';for($i=0; $i<100; $i++) printf("%s %s\n", $i, $c++);
With this feature, your program can write
$ Span = "A"; foreach ($ rows as $ keyName => $ value) {// write A column $ j = $ span; $ objActSheet-> setCellValueExplicit ($ j. $ column, $ value); $ span ++ ;}
Thank you for your advice!