PHPExcel create a new file
17,234
I find how to resolve my problem ... but only half of it. Because it's work with this code :
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()
->setCreator("Temporaris")
->setLastModifiedBy("Temporaris")
->setTitle("Template Relevé des heures intérimaires")
->setSubject("Template excel")
->setDescription("Template excel permettant la création d'un ou plusieurs relevés d'heures")
->setKeywords("Template excel");
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('A1', "12");
$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="excel.xls"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
But it's Excel5 not Excel2007 and when i remplace Excel5 by Excel2007 i have the same error message.
Author by
Kvasir
Updated on June 04, 2022Comments
-
Kvasir almost 2 years
I am trying to create a new Excel file by using PHPExcel library with this code :
include ('/lib/PHPExcel/PHPExcel/IOFactory.php'); include ('/lib/PHPExcel/PHPExcel.php'); $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties() ->setCreator("admin") ->setLastModifiedBy("admin") ->setTitle("Test") ->setSubject("template file") ->setDescription("template file") ->setKeywords("Prout"); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello'); $objPHPExcel->getActiveSheet()->setTitle('Simple'); $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); $objWriter->save(dirname(__FILE__).'/file/test.xlsx');
The file is created, but when i try to open it my excel 2010 tells me there is unreadable content inside the file and i can't open it.
I tried a different way on a different forum but i am always arriving to the same result. I do this manipulation by using Ajax with jquery. Can this be the cause of this error?
-
Taryn about 9 yearsComments are not for extended discussion; this conversation has been moved to chat.
-
Mark Baker about 9 yearsWell I've examined the xlsx file: the zip index is intact, but the individual files fail on a crc check, so it's as though ZipArchive has somehow corrupted the individual files (or at least their crc32 value) when writing.... it's not something I can explain