How to modify an existing excel file using PHP?

I have excel, I need to add some more sheets to excel using PHP, I used PEAR, there I tried to only write excel and read the file, not being able to read and modify the file, guys, can you help me with this?

Thanks in advance

Prabu

+6
php excel pear
source share
1 answer

You will need 2 pear packs

  • PHP-ExcelReader package
  • Spreadsheet_Excel_Writer Package

What you need to do is first read the excel file to use the PHP-ExcelReader package. It reads the binary format of XLS files directly and can return values ​​and formats from any cell. http://code.google.com/p/php-excel-reader/

read excel file

$data = new Spreadsheet_Excel_Reader("test.xls"); 

show file data

 $data->dump($row_numbers=false,$col_letters=false,$sheet=0,$table_class='excel') 

After you have saved the data in a variable, save the data in another file, this time you will use the Spreadsheet_Excel_Writer package https://github.com/pear/Spreadsheet_Excel_Writer

  <?php require_once 'Spreadsheet/Excel/Writer.php'; $workbook = new Spreadsheet_Excel_Writer('test.xls'); $worksheet =& $workbook->addWorksheet('My first worksheet'); if (PEAR::isError($worksheet)) { die($worksheet->getMessage()); } $workbook->close(); ?> 
+12
source share

All Articles