How to modify existing excel file using PHP?

自作多情 提交于 2019-12-18 13:33:31

问题


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

Thanks in advance

Prabu


回答1:


You will need 2 pear packages

  1. PHP-ExcelReader package
  2. Spreadsheet_Excel_Writer package

What you need to do is read first the excel file use 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 the excel file

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

show the data of the file

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

Once you have stored the data in a variable save the data in another file this time you will use the 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();
?> 


来源:https://stackoverflow.com/questions/2144638/how-to-modify-existing-excel-file-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!