php - PHPExcel - .xlsx file downloads unreadable content -


i trying export data spread sheet , working fine in localhost , when uploaded server , downloads files unreadable content . writing code here.

there php_xml, php_zip , gd installed in server. file downloaded readonly.

    error_reporting(e_all);     ini_set('display_errors', true);     ini_set('display_startup_errors', true);     date_default_timezone_set('europe/london');      if (php_sapi == 'cli')         die('this example should run web browser');      /** include phpexcel */     require_once dirname(__file__) . '/lib/phpexcel.php';       // create new phpexcel object     $objphpexcel = new phpexcel();      // set document properties     $objphpexcel->getproperties()->setcreator("test")                          ->setlastmodifiedby("test")                          ->settitle("test report")                          ->setsubject("test report")                          ->setdescription("test report")                          ->setkeywords("test report")                          ->setcategory("test report");      //title     $objphpexcel->getactivesheet()->mergecells('a1:j1');     $objphpexcel->getactivesheet()->getstyle('a1:j1')->getalignment()->sethorizontal(phpexcel_style_alignment::horizontal_center);     $objphpexcel->getactivesheet()->getstyle("a1:j1")->getfont()->setsize(20);     $stylearray = array(         'font' => array(             'bold' => true         )     );     $objphpexcel->getactivesheet()->getstyle('a1:j1')->applyfromarray($stylearray);     $objphpexcel->setactivesheetindex(0)         ->setcellvalue('a1', 'test report');     $objphpexcel->getactivesheet()->getrowdimension(1)->setrowheight(30);     // //set column headlines     $objphpexcel->setactivesheetindex(0)         ->setcellvalue('a2', 'first name')         ->setcellvalue('b2', 'last name')         ->setcellvalue('c2', 'state')         ->setcellvalue('d2', 'email')         ->setcellvalue('e2', 'mob')         ->setcellvalue('f2', 'address')         ->setcellvalue('g2', 'pin')         ->setcellvalue('h2', 'status')         ->setcellvalue('i2', 'condition')         ->setcellvalue('j2', 'log');    $objphpexcel->getactivesheet()->getstyle("a2:j2")->getfont()->setsize(10);   $objphpexcel->getactivesheet()->getstyle('a2:j2')->applyfromarray($stylearray);   $objphpexcel->getactivesheet()->getcolumndimension('a')->setwidth(15);   $objphpexcel->getactivesheet()->getcolumndimension('b')->setwidth(15);   $objphpexcel->getactivesheet()->getcolumndimension('c')->setwidth(15);   $objphpexcel->getactivesheet()->getcolumndimension('d')->setwidth(18);   $objphpexcel->getactivesheet()->getcolumndimension('e')->setwidth(5);   $objphpexcel->getactivesheet()->getcolumndimension('f')->setwidth(7);   $objphpexcel->getactivesheet()->getcolumndimension('g')->setwidth(15);   $objphpexcel->getactivesheet()->getcolumndimension('h')->setwidth(15);   $objphpexcel->getactivesheet()->getcolumndimension('i')->setwidth(18);   $objphpexcel->getactivesheet()->getcolumndimension('j')->setwidth(15);  $colarray=array("a","b","c","d","e","f","g","h","i","j");  $rownumber = 3;      while ($row = mysqli_fetch_row($result)) {      $col = 0;      foreach($row $cell) {          $objphpexcel->getactivesheet()->setcellvalue($colarray[$col].$rownumber,$cell);          $objphpexcel->getactivesheet()->getstyle($colarray[$col].$rownumber)->getfont()->setsize(10);         $col++;      }      $rownumber++;       }  // rename worksheet $objphpexcel->getactivesheet()->settitle('test report');  // set active sheet index first sheet, excel opens first sheet $objphpexcel->setactivesheetindex(0); // redirect output client’s web browser (excel2007) header('content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('content-disposition: attachment;filename="testreport.xlsx"'); header('cache-control: max-age=0'); // if you're serving ie 9, following may needed header('cache-control: max-age=1');  // if you're serving ie on ssl, following may needed header ('expires: mon, 26 jul 1997 05:00:00 gmt'); // date in past header ('last-modified: '.gmdate('d, d m y h:i:s').' gmt'); // modified header ('cache-control: cache, must-revalidate'); // http/1.1 header ('pragma: public'); // http/1.0  $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel2007'); $objwriter->save('php://output'); exit; 

i don't see problem core logic. able generate valid xlsx file off linux box slight modifications

  1. updated require_once line follows (i somehow felt comfortable in keep phpexcel's default folder structure intact)

require_once dirname(file) . '/../classes/phpexcel/iofactory.php';

  1. since don't have mysqli corresponding example, modified to..

    $row = array(1,2,3,4,5,6,7,8,9);
    //while ($row = mysqli_fetch_row($result)) {

overall, guess, need see if mysqli data valid , initiate phpexcel properly. other that, don't see problem here.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -