No announcement yet.

How to export mysql in SC to Excel

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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)) {
    ->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']);
    $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/');
    header('Content-Disposition: attachment;filename='.$filename.'');
    header('Cache-Control: max-age=0');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Exc el5');

    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!
    Attached Files
    Last edited by adeleon2; 07-23-2015, 09:48 AM.

  • #2
    PHPExcel_IOFactory::createWriter($objPHPExcel,'Exc el5');

    Exc[space]el5 ?


    • #3
      Sorry! it is 'Excel5' without space. Thks!


      • #4
        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"...