5

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!

DeiDei
  • 10,205
  • 6
  • 55
  • 80
Alexandre Corvino
  • 199
  • 1
  • 3
  • 16

1 Answers1

25
  • 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');
Andrea Lazzarotto
  • 2,471
  • 1
  • 22
  • 38
Evil_skunk
  • 3,040
  • 4
  • 30
  • 42
  • 2
    the documentation Vs @Evil_skunk ... man thank you very much... wtf doc phpspreadsheet is this ??????????? I was looking for this answer like 20 min – Markos May 24 '21 at 20:06