edit uploaded XLSX file values with PHPExcel

is there possible to edit uploaded xlsx file with PHPExcel? I can read uploaded file using this function:

<?php
require_once('Classes/PHPExcel.php');
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("Ataskaita2.xlsx");
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
echo '<table border=1>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
  echo '<tr>' . "\n";
  $cellIterator = $row->getCellIterator();
  $cellIterator->setIterateOnlyExistingCells(false); 
  foreach ($cellIterator as $cell) {
    echo '<td>' . $cell->getValue() . '</td>' . "\n";
  }
  echo '</tr>' . "\n";
}
echo '</table>' . "\n";

?>

But also I need to edit these cells is there a way to display these cells in a text fields and save it back after editing? Thank you for advices!

Upvotes: 1

Views: 1813

Answers (1)

Mark Baker
Mark Baker

Reputation: 212422

You can use PHPExcel to read a spreadsheet file; change the values in cells, etc; and to save the file again... but it does not provide you with a nice pretty GUI. It's a library for you to manipulate spreadsheet data from your PHP scripts, but your PHP scripts have to provide the form text fields if you want interaction with a GUI front-end.

Personally, I'd write a custom HTML writer to generate the spreadsheet you've read as a form rather than a simple display for presenting to the front-end users, then have a script executed on POST that reread the file, updated it with any changes that the user had made in the form, and save.

Upvotes: 1

Related Questions