alphy
alphy

Reputation: 991

Exporting to excel using php excel to the most immediate sheet

I want to export data to excel sheet. I have a workbook x, the workbook is to have several worksheets created by php excel. I would like to export data in the format that if sheet one has data, then php excel needs to create the second sheet by itself and subsequent sheets without me specifying the sheet index $objReader = PHPExcel_IOFactory::createReader('Excel2007');

$objPHPExcel = $objReader->load("workbooks/" . $labref . "/" . $labref . ".xlsx");
        $objPHPExcel->getActiveSheet();
        $objWorkSheet = $objPHPExcel->createSheet();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
  $objWriter->save("workbooks/" . $labref . "/" . $labref . ".xlsx");

In the above case, when exporting, the workbook is deleted by php excel and so phpexcel can't create and write to the created sheet

Upvotes: 2

Views: 1216

Answers (1)

Mark Baker
Mark Baker

Reputation: 212412

I'm having difficulty understanding your problem.

PHPExcel will never delete a workbook file: there is no code in PHPExcel that can delete any file. If a script is deleting a file, then it is not being deleted by PHPExcel.

In the above code snippet, you are loading a workbook; adding a new worksheet to that workbook; and then saving that workbook, overwriting the original. There should still be a workbook in your workbooks/ folder called .xlsx, but with one extra worksheet.

Can you please clarify exactly what is happening?

Upvotes: 1

Related Questions