Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create new worksheet and add data from file to it?

I have file what have two worksheets which I wish to use as templates.

In php I create new PHPExcel object and load data from first worksheet to it.

    $objReader = new PHPExcel_Reader_Excel5();
    $objReader->setLoadSheetsOnly('Page1');
    $objPHPExcel = $objReader->load('template.xls');

Then I need to create another worksheet in objPHPExcel and fill it with template from worksheet 'Page2' of file template.xls

But when I do like this:

    $objReader->setLoadSheetsOnly('Page2');
    $objWorksheet = $objPHPExcel->createSheet();
    $objWorksheet->setTitle('Sheet'.$sheetIndex);
    $objPHPExcel = $objReader->load($timesheetTemplatePath);

I get file with only last results.

How can I create worksheet and read data (with styles) from another file?

like image 933
pepper Avatar asked Nov 06 '22 00:11

pepper


1 Answers

Try passing an index to createSheet method, in this case it would be 1:

$objWorksheet = $objPHPExcel->createSheet(1);
like image 118
King Julien Avatar answered Nov 09 '22 12:11

King Julien