Jump to content

How to write in an existing excel file?


hellreaper

Recommended Posts

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
Share on other sites

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
Share on other sites

  • 1 year later...

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.