hellreaper Posted August 12, 2009 Share Posted August 12, 2009 Hello, I have an template excel file and for each of my users in my data base i need to be able to create a different excel file. If anyone could guide be i would really appreciate it. Thanks Link to comment https://forums.phpfreaks.com/topic/169899-how-to-write-in-an-existing-excel-file/ Share on other sites More sharing options...
Mark Baker Posted August 12, 2009 Share Posted August 12, 2009 Read the excel file into PHP using a library such as PHPExcel. Modify the cells that you wish to personalise, and write it out as a new Excel file Link to comment https://forums.phpfreaks.com/topic/169899-how-to-write-in-an-existing-excel-file/#findComment-896334 Share on other sites More sharing options...
hellreaper Posted August 12, 2009 Author Share Posted August 12, 2009 Thank you for your reply, I didn't find any information on how to read an existing excel file and writing in it with PHPExcel, I just found how to create a file here http://g-ernaelsten.developpez.com/tutoriels/excel2007/ Link to comment https://forums.phpfreaks.com/topic/169899-how-to-write-in-an-existing-excel-file/#findComment-896440 Share on other sites More sharing options...
Mark Baker Posted August 12, 2009 Share Posted August 12, 2009 I didn't find any information on how to read an existing excel file and writing in it with PHPExcel[/url] You didn't look very hard require_once './Classes/PHPExcel/IOFactory.php'; $objPHPExcel = PHPExcel_IOFactory::load("excelTemplate.xls"); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->setCellValue('A1', 'Hello') ->setCellValue('B2', 'World!'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('excelCustomised.xls'); Link to comment https://forums.phpfreaks.com/topic/169899-how-to-write-in-an-existing-excel-file/#findComment-896481 Share on other sites More sharing options...
hellreaper Posted August 13, 2009 Author Share Posted August 13, 2009 i really suck because i cant find were you found that info..... Link to comment https://forums.phpfreaks.com/topic/169899-how-to-write-in-an-existing-excel-file/#findComment-897127 Share on other sites More sharing options...
hellreaper Posted August 13, 2009 Author Share Posted August 13, 2009 Ok i found how to do it thank you! include 'Classes/PHPExcel/IOFactory.php'; $objReader = PHPExcel_IOFactory::createReader('Excel2007'); //we load the file that we want to read $objPHPExcel = $objReader->load("test.xlsx"); //we change the file $objPHPExcel->getActiveSheet() ->setCellValue('A1','EEEEEEEEE') ->setCellValue('A2','DDDDDDDDDDDD') ->setCellValue('A3','CCCCCCCCC') ->setCellValue('A4','BBBBBBBBBB') ->setCellValue('A5','AAAAAAAAAAAAA') ->setCellValue('A29','MaitrePylos'); //we create a new file $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); //we save $objWriter->save('coco.xlsx'); Link to comment https://forums.phpfreaks.com/topic/169899-how-to-write-in-an-existing-excel-file/#findComment-897135 Share on other sites More sharing options...
cancer10 Posted July 26, 2011 Share Posted July 26, 2011 HI Guys, hellreaper's code worked like a charm. But If you try to read a file with formulaes for example if you add the formula =SUM(B1,B2,C1,D2) somewhere in the file, then the new generated file will be generated with reversed GUI. PFA excel file for example. Does anyone have any idea how to fix this? [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/169899-how-to-write-in-an-existing-excel-file/#findComment-1247163 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.