php - 如何使用 PHP 修改现有的 excel 文件?

标签 php excel pear

我有一个 excel,我需要使用 PHP 在 excel 中添加更多的工作表,我使用过 PEAR,我试过只能写 excel 和读取文件,不能读取和修改文件,你们能帮忙吗我在这?

提前致谢

帕布

最佳答案

你需要2个 pear 包

  1. PHP-ExcelReader包
  2. Spreadsheet_Excel_Writer 包

您需要做的是先使用 PHP-ExcelReader 包 读取 excel 文件 它直接读取 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')

将数据存储在变量中后,将数据保存在另一个文件中,这次您将使用 The Spreadsheet_Excel_Writer 包 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 - 如何使用 PHP 修改现有的 excel 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2144638/

相关文章:

PHP Doctrine 初学者 : Doctrine\ORM\Tools\Setup not found

php - Codeigniter:消息:无法修改 header 信息 - header 已发送(输出开始于

java到excel日期格式

php - php钠函数中的编码字符问题

Excel VBA : "Like" Incorrectly Returns True and False with Chr 35

excel - 打开工作表时如何以编程方式更改 Excel 2007 功能区上的标签值

curl - PHPUnit 无法识别 cURL 扩展 - 无法安装 selenium 测试

php - 从 PHP 站点修改 PDF 表单

php - 使用 PHP 和 MySQL 查询连接两个表并对数据数组进行排序

php - 使用广度优先搜索用 PHP 解决 3x3 难题