How PHP ends the query export Excel

Source: Internet
Author: User
Phpexcel Export Outbound

 
  
  ";} Sqlsrv_free_stmt ($query); sqlsrv_close ($conn);? > 
   
User number User name
$row [0] $row [1]


Reply to discussion (solution)

With Phpexcel
Http://www.jz123.cn/text/2319267.html

Fputcsv ()

Header ("Content-type:application/vnd.ms-excel");
Header ("content-disposition:attachment; Filename= "Aaa.xls");

With Phpexcel
Http://www.jz123.cn/text/2319267.html
+1

Header ("Content-type:application/vnd.ms-excel");
Header ("content-disposition:attachment; Filename= "Aaa.xls");
+1

Excel is actually a powerful feature.

$str = "a1\ta2\ta3\n"; $str. = "b1\tb2\tb3\n"; you write these characters into a file, and the suffix name is changed to. xls,excel can be read directly.

Excel is actually a powerful feature.

$str = "a1\ta2\ta3\n"; $str. = "b1\tb2\tb3\n"; you write these characters into a file, and the suffix name is changed to. xls,excel can be read directly.


But actually not the real XLS file.


Excel is actually a powerful feature.

$str = "a1\ta2\ta3\n"; $str. = "b1\tb2\tb3\n"; you write these characters into a file, and the suffix name is changed to. xls,excel can be read directly.


But actually not the real XLS file.
$query = sqlsrv_query ($conn, $sql), if ($query = = = False) {die    (Print_r (Sqlsrv_errors (), True));} while ($row = Sqlsrv_fetch_array ($query)) {Echo$objphpexcel->getactivesheet ()->setcellvalue (' A2 ', convertUTF8 ($row [0])) ->setcellvalue (' B2 ', convertUTF8 ($row [1]))->setcellvalue (' C2 ', convertUTF8 ($row [2]))->setcellvalue (' D2 ') , ConvertUTF8 ($row [3]))->setcellvalue (' E2 ', ConvertUTF8 ($row [4]))->setcellvalue (' F2 ', ConvertUTF8 ($row [5])) ->setcellvalue (' G2 ', convertUTF8 ($row [6]))->setcellvalue (' H2 ', convertUTF8 ($row [7]))->setcellvalue (' I2 ') , ConvertUTF8 ($row [8]))->setcellvalue (' J2 ', convertUTF8 ($row [9]))->setcellvalue (' K2 ', convertUTF8 ($row [10]) )->setcellvalue (' L2 ', convertUTF8 ($row [11]));}
Is there a problem with this piece of code, please? Why is the following error in execution times:

Catchable fatal error:object of class Phpexcel_worksheet could not being converted to string in D:\MarsdenWeb\Report\output_ 002.php on line 19

$objPHPExcel >getactivesheet ()
The result of the->setcellvalue () operation is to return the Phpexcel_worksheet object and remove the echo from the front.

$objPHPExcel >getactivesheet ()
The result of the->setcellvalue () operation is to return the Phpexcel_worksheet object and remove the echo from the front.
After the echo is removed, it is not an error, but the while loop seems to be invalid, the result of the export is only a single piece of data.


$objPHPExcel >getactivesheet ()
->setcellvalue () operation results in return Phpexcel_worksheet Object, the front of the echo to remove it
after the Echo, is not an error, but the while loop seems to be invalid, the result of the export is only one data.

->setcellvalue (' A2 ', convertUTF8 ($row [0]))
->setcellvalue (' B2 ', convertUTF8 ($row [1]))
, Setcellvalue (' C2 ', convertUTF8 ($row [2]))
->setcellvalue (' D2 ', ConvertUTF8 ($row [3]))
->setcellvalue (' E2 ', ConvertUTF8 ($row [4]))
->setcellvalue (' F2 ', ConvertUTF8 ($row [5]))
->setcellvalue (' G2 ', ConvertUTF8 ($row [6]))
->setcellvalue (' H2 ', convertUTF8 ($row [7])
->setcellvalue (' I2 ', convertUTF8 ($ ROW[8])
->setcellvalue (' J2 ', convertUTF8 ($row [9])
->setcellvalue (' K2 ', convertUTF8 ($row [ten]))
- >setcellvalue (' L2 ', convertUTF8 ($row [11])); The

Red part of the loop does not change, so the value of the previous cell is overwritten.



$objPHPExcel >getactivesheet ()
->setcellvalue () operation results in return PHPEXCEL_ Worksheet object, the front of the echo to remove it
to remove the echo, is not an error, but the while loop seems to be invalid, the result of the export is only one piece of data.

->setcellvalue (' A2 ', convertUTF8 ($row [0]))
->setcellvalue (' B2 ', convertUTF8 ($row [1]))
, Setcellvalue (' C2 ', convertUTF8 ($row [2]))
->setcellvalue (' D2 ', ConvertUTF8 ($row [3]))
->setcellvalue (' E2 ', ConvertUTF8 ($row [4]))
->setcellvalue (' F2 ', ConvertUTF8 ($row [5]))
->setcellvalue (' G2 ', ConvertUTF8 ($row [6]))
->setcellvalue (' H2 ', convertUTF8 ($row [7])
->setcellvalue (' I2 ', convertUTF8 ($ ROW[8])
->setcellvalue (' J2 ', convertUTF8 ($row [9])
->setcellvalue (' K2 ', convertUTF8 ($row [ten]))
- >setcellvalue (' L2 ', convertUTF8 ($row [11])); The

Red part of the loop does not change, so the value of the previous cell is overwritten.
I don't quite understand what you mean, how should I change it?




$objPHPExcel >getactivesheet ()
->setcellvalue () The result of the operation is to return the Phpexcel_ Worksheet object, the front of the echo to remove it
to remove the echo, is not an error, but the while loop seems to be invalid, the result of the export is only one piece of data.

->setcellvalue (' A2 ', convertUTF8 ($row [0]))
->setcellvalue (' B2 ', convertUTF8 ($row [1]))
, Setcellvalue (' C2 ', convertUTF8 ($row [2]))
->setcellvalue (' D2 ', ConvertUTF8 ($row [3]))
->setcellvalue (' E2 ', ConvertUTF8 ($row [4]))
->setcellvalue (' F2 ', ConvertUTF8 ($row [5]))
->setcellvalue (' G2 ', ConvertUTF8 ($row [6]))
->setcellvalue (' H2 ', convertUTF8 ($row [7])
->setcellvalue (' I2 ', convertUTF8 ($ ROW[8])
->setcellvalue (' J2 ', convertUTF8 ($row [9])
->setcellvalue (' K2 ', convertUTF8 ($row [ten]))
- >setcellvalue (' L2 ', convertUTF8 ($row [11])); The

Red part of the loop does not change, so the value of the previous cell is overwritten.
I don't quite understand what you mean, how should I change it?

$i = 2;while ($row = Sqlsrv_fetch_array ($query)) {$objPHPExcel->getactivesheet ()        ->setcellvalue (' A '. $i, ConvertUTF8 ($row [0]))        ->setcellvalue (' B '. $i, ConvertUTF8 ($row [1]))        ->setcellvalue (' C '. $i, ConvertUTF8 ($row [2]))        ->setcellvalue (' D '. $i, ConvertUTF8 ($row [3]))        ->setcellvalue (' E '. $i, ConvertUTF8 ($row [4]))        ->setcellvalue (' F '. $i, ConvertUTF8 ($row [5]))        ->setcellvalue (' G '. $i, ConvertUTF8 ($row [6]))        ->setcellvalue (' H '. $i, ConvertUTF8 ($row [7]))        ->setcellvalue (' i '. $i, ConvertUTF8 ($row [8]))        ->setcellvalue (' J '. $i, ConvertUTF8 ($row [9]))        ->setcellvalue (' K '. $i, ConvertUTF8 ($row [ten]))        ->setcellvalue (' L ' $i, convertUTF8 ($row [one])); $i + +;}





$objPHPExcel >getactivesheet ()
->setcellvalue () operation results in a return Phpexcel_worksheet object, the front of the echo to remove it
to remove the echo, is not an error, but the while loop seems to be invalid, the result of the export is only one piece of data.

->setcellvalue (' A2 ', convertUTF8 ($row [0]))
->setcellvalue (' B2 ', convertUTF8 ($row [1]))
, Setcellvalue (' C2 ', convertUTF8 ($row [2]))
->setcellvalue (' D2 ', ConvertUTF8 ($row [3]))
->setcellvalue (' E2 ', ConvertUTF8 ($row [4]))
->setcellvalue (' F2 ', ConvertUTF8 ($row [5]))
->setcellvalue (' G2 ', ConvertUTF8 ($row [6]))
->setcellvalue (' H2 ', convertUTF8 ($row [7])
->setcellvalue (' I2 ', convertUTF8 ($ ROW[8])
->setcellvalue (' J2 ', convertUTF8 ($row [9])
->setcellvalue (' K2 ', convertUTF8 ($row [ten]))
- >setcellvalue (' L2 ', convertUTF8 ($row [11])); The

Red part of the loop does not change, so the value of the previous cell is overwritten.
I don't quite understand what you mean, how should I change it?

$i = 2;while ($row = Sqlsrv_fetch_array ($query)) {$objPHPExcel->getactivesheet ()        ->setcellvalue (' A '. $i, ConvertUTF8 ($row [0]))        ->setcellvalue (' B '. $i, ConvertUTF8 ($row [1]))        ->setcellvalue (' C '. $i, ConvertUTF8 ($row [2]))        ->setcellvalue (' D '. $i, ConvertUTF8 ($row [3]))        ->setcellvalue (' E '. $i, ConvertUTF8 ($row [4]))        ->setcellvalue (' F '. $i, ConvertUTF8 ($row [5]))        ->setcellvalue (' G '. $i, ConvertUTF8 ($row [6]))        ->setcellvalue (' H '. $i, ConvertUTF8 ($row [7]))        ->setcellvalue (' i '. $i, ConvertUTF8 ($row [8]))        ->setcellvalue (' J '. $i, ConvertUTF8 ($row [9]))        ->setcellvalue (' K '. $i, ConvertUTF8 ($row [ten]))        ->setcellvalue (' L ' $i, convertUTF8 ($row [one])); $i + +;}

Thank you! Finally solved the export problem ...
But now it is automatically saved, there is no way to save their own as it?






$objPHPExcel >getactivesheet ()
->setcellvalue () operation results in a return Phpexcel_worksheet object, the front of the echo to remove it
to remove the echo, is not an error, but the while loop seems to be invalid, the result of the export is only one piece of data.

->setcellvalue (' A2 ', convertUTF8 ($row [0]))
->setcellvalue (' B2 ', convertUTF8 ($row [1]))
, Setcellvalue (' C2 ', convertUTF8 ($row [2]))
->setcellvalue (' D2 ', ConvertUTF8 ($row [3]))
->setcellvalue (' E2 ', ConvertUTF8 ($row [4]))
->setcellvalue (' F2 ', ConvertUTF8 ($row [5]))
->setcellvalue (' G2 ', ConvertUTF8 ($row [6]))
->setcellvalue (' H2 ', convertUTF8 ($row [7])
->setcellvalue (' I2 ', convertUTF8 ($ ROW[8])
->setcellvalue (' J2 ', convertUTF8 ($row [9])
->setcellvalue (' K2 ', convertUTF8 ($row [ten]))
- >setcellvalue (' L2 ', convertUTF8 ($row [11])); The

Red part of the loop does not change, so the value of the previous cell is overwritten.
I don't quite understand what you mean, how should I change it?

$i = 2;while ($row = Sqlsrv_fetch_array ($query)) {$objPHPExcel->getactivesheet ()        ->setcellvalue (' A '. $i, ConvertUTF8 ($row [0]))        ->setcellvalue (' B '. $i, ConvertUTF8 ($row [1]))        ->setcellvalue (' C '. $i, ConvertUTF8 ($row [2]))        ->setcellvalue (' D '. $i, ConvertUTF8 ($row [3]))        ->setcellvalue (' E '. $i, ConvertUTF8 ($row [4]))        ->setcellvalue (' F '. $i, ConvertUTF8 ($row [5]))        ->setcellvalue (' G '. $i, ConvertUTF8 ($row [6]))        ->setcellvalue (' H '. $i, ConvertUTF8 ($row [7]))        ->setcellvalue (' i '. $i, ConvertUTF8 ($row [8]))        ->setcellvalue (' J '. $i, ConvertUTF8 ($row [9]))        ->setcellvalue (' K '. $i, ConvertUTF8 ($row [ten]))        ->setcellvalue (' L ' $i, convertUTF8 ($row [one])); $i + +;}

Thank you! Finally solved the export problem ...
But now it is automatically saved, there is no way to save their own as it?

Don't read the documentation?
The last->save ()

Switch
Header ("Content-type:application/force-download");
Header ("Content-type:application/octet-stream");
Header ("Content-type:application/download");
Header (' Content-disposition:inline;filename= '. $FileName. ' ');
Header ("Content-transfer-encoding:binary");
Header ("Expires:mon, Jul 1997 05:00:00 GMT");
Header ("last-modified:".) Gmdate ("D, D M Y h:i:s"). "GMT");
Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0");
Header ("Pragma:no-cache");
$objWriter->save (' php://output ');


Excel is actually a powerful feature.

$str = "a1\ta2\ta3\n"; $str. = "b1\tb2\tb3\n"; you write these characters into a file, and the suffix name is changed to. xls,excel can be read directly.




But actually not the real XLS file.


Well, it is not, and Chinese in foreign countries see also the possibility of garbled, later changed to HTML, not only can solve garbled, and style can control, have to say that Excel is too powerful
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.