i studying phpexcel , did 1 of example.
i did this:
public function generateexceltemplate($quotation_id) { //error reporting error_reporting(e_all); //include path ini_set('include_path', ini_get('include_path').';../classes/'); //php excel include('application/libraries/phpexcel.php'); //php excel writer 2007 include('application/libraries/phpexcel/writer/excel2007.php'); //create new phpexcel object echo date('h:i:s') . " create new phpexcel object \n"; $objphpexcel = new phpexcel(); //set properties echo date('h:i:s') . " set properties \n"; $objphpexcel->getproperties()->setcreator('rochelle canale'); $objphpexcel->getproperties()->setlastmodifiedby('rochelle canale'); $objphpexcel->getproperties()->settitle('my new excel'); $objphpexcel->getproperties()->setsubject('my new excel subject'); $objphpexcel->getproperties()->setdescription('test document'); //add data echo date('h:i:s') . " add data \n"; $objphpexcel->setactivesheetindex(0); $objphpexcel->getactivesheet()->setcellvalue('a1', 'hello'); $objphpexcel->getactivesheet()->setcellvalue('b2', 'world'); $objphpexcel->getactivesheet()->setcellvalue('c1', 'hello'); $objphpexcel->getactivesheet()->setcellvalue('d2', 'world'); //rename sheet echo date('h:i:s') . " rename sheet\n"; $objphpexcel->getactivesheet()->settitle('simple'); //save excel 2007 echo date('h:i:s') . " write excel2007 format \n"; $objwriter = new phpexcel_writer_excel2007($objphpexcel); $objwriter->save(str_replace('.php','.xlsx', __file__)); //echo done echo date('h:i:s') . " done writing \r\n"; } and looks fine because generate excel. problem there's no dialog saving file. when check demo , when click link prompt confirmation box asking if want save or open. in page when load it simple shows text.
i think after of above code listing try putting following code lines:
// set active sheet index first sheet, excel opens first sheet $objphpexcel->setactivesheetindex(0); // redirect output client’s web browser (excel2007) //clean output buffer ob_end_clean(); //this header given phpexcel examples. output seems corrupted in cases. //header('content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //so, use header instead. header('content-type: application/vnd.ms-excel'); header('content-disposition: attachment;filename="'.$properties_arr['excel_file_name'].'.xlsx"'); header('cache-control: max-age=0'); $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel2007'); $objwriter->save('php://output'); note:
assume above code listing generates readable excel sheet, unable make downloadable. above code snippet done you!
and within codeigniter's config directory there mimes.php , need add/edit line xlsx associative key-value pair $mimes array. value key xlsx should follows:
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel'), hope works!
Comments
Post a Comment