How to export mysql in SC to Excel

Hi everybody!

I’m having trouble to export mysql SELECT to Excel. Currently using last SC version before 8.1.

Using PHPExcel, dont load class with sc_include, after install in library directory and check it in Applications. I used “sc_include” because of a modal SC message suggesting it, but in production didn’t work so I used “require once” and path.

Here is my code:

$result = mysql_query($sqlf); // $sqlf have the SELECT command
$i = 3;
require_once “/xampp/htdocs/phpexcel/Classes/PHPExcel.php”;
$objPHPExcel = new PHPExcel();
while ($row = mysql_fetch_array($result)) {
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue(“A”.$i, $row[‘Field’])
->setCellValue(“B”.$i, $row[‘S’])
->setCellValue(“C”.$i, $row[‘N’])
->setCellValue(“D”.$i, $row[‘NA’])
->setCellValue(“E”.$i, $row[‘P’])
->setCellValue(“F”.$i, $row[‘X’]);
$i++;
}
$objPHPExcel->getActiveSheet()->SetCellValue(‘A1’, ‘Descripci?n’);
$objPHPExcel->getActiveSheet()->SetCellValue(‘B1’, 'SI);
$objPHPExcel->getActiveSheet()->SetCellValue(‘C1’, ‘NO’);
$objPHPExcel->getActiveSheet()->SetCellValue(‘D1’,‘NO APLICA’);
$objPHPExcel->getActiveSheet()->SetCellValue(‘E1’, ‘PARCIAL’);
$objPHPExcel->getActiveSheet()->SetCellValue(‘F1’, ‘X’);

header(‘Content-Type: application/vnd.ms-excel’);
header(‘Content-Disposition: attachment;filename=’.$filename.’’);
header(‘Cache-Control: max-age=0’);
$objPHPExcel->getActiveSheet()->setTitle(‘Report’);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,‘Excel5’);
$objWriter->save(‘php://output’);
exit;

In the first file attached (1Print) Excel display an Error regarding Saphir CSS, after click OK Excel display the file but with errors (See 2Print)
In the second file it display the output (very frustrating…:()

Maybe there is another way to do this, because I’ve spent many hours dealing with this problem.

Thank you!

1Print.jpg

2Print.jpg

PHPExcel_IOFactory::createWriter($objPHPExcel,‘Exc el5’);

Exc[space]el5 ?

Sorry!
It is:
PHPExcel_IOFactory::createWriter($objPHPExcel,‘Excel5’);

Sorry it is:
PHPExcel_IOFactory::createWriter($objPHPExcel,‘Excel5’);

Sorry! it is ‘Excel5’ without space. Thks!

Finally I got it!

There is no need to use PHPExcel.php. The main problem was to define code in buttom within grid forms. Maybe when running SC tries to inherit CSS properties and blows it. The issue was solved using blank forms. Thank you anyway!

“Success is the sum of small efforts, repeated day in and day out”…