如何使用PHP修改现有的excel文件? [英] How to modify existing excel file using PHP?

查看:477
本文介绍了如何使用PHP修改现有的excel文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个excel,我需要添加一些更多的表格到excel使用PHP,我已经使用PEAR,我试图只能写excel和阅读文件,无法读取和修改文件,你们可以帮助我在这个?



提前感谢



Prabu

解决方案

您将需要2个梨包


  1. PHP-ExcelReader包

  2. Spreadsheet_Excel_Writer包

您需要做的是先阅读excel文件使用 PHP-ExcelReader包
它直接读取XLS文件的二进制格式,可以从任何单元格返回值和格式。
http://code.google.com/p/php-excel -reader /



阅读excel文件

  $ data = new Spreadsheet_Excel_Reader(test.xls); 

显示文件的数据

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




一旦将数据存储在变量中,此时将数据保存在另一个文件中,您将使用 Spreadsheet_Excel_Writer包
https://github.com/pear/Spreadsheet_Excel_Writer

 <?php 
require_once'电子表格/ Excel / Writer.php'
$ workbook = new Spreadsheet_Excel_Writer('test.xls');
$ worksheet =& $ workbook-> addWorksheet('我的第一个工作表');
if(PEAR :: isError($ worksheet)){
die($ worksheet-> getMessage());
}
$ workbook-> close();
?>


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

解决方案

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();
?> 

这篇关于如何使用PHP修改现有的excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆