Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write in an existing spreadSheet with PhpSpreadSheet?

I'm currently using PhpSpreadSheet Library and I wanna write into an existing spreadSheet. Is that possible?

If yes, how? I didn't see any possibility in the documentation.

Thanks!

like image 589
Alexandre Corvino Avatar asked Nov 29 '22 22:11

Alexandre Corvino


1 Answers

  • Load the existing Spreadsheet-File
  • Change something
  • Write it again to Filesystem

Code:

<?php

//load spreadsheet
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load("yourspreadsheet.xlsx");

//change it
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'New Value');

//write it again to Filesystem with the same name (=replace)
$writer = new Xlsx($spreadsheet);
$writer->save('yourspreadsheet.xlsx');
like image 92
Evil_skunk Avatar answered Jan 26 '23 00:01

Evil_skunk