如何在现有的Excel文件中添加Worksheet

时间:2013-09-10 16:04:09

标签: php pear

我正在使用pear.php.net提供的“Writer.php”文件来生成excel文件。我发现很难做的是将工作表添加到现有的工作簿中。我尝试了一些但没有添加工作表。我对OOP非常不满,任何帮助都会非常感激。提前谢谢。

这是生成excel文件的php代码:

<?php
session_start();
require_once('Spreadsheet/Excel/Writer.php');
include ("config.php");

$username = $_SESSION['username'];
$uid = $_SESSION['uid'];
$name_in_logo=$_POST['name_in_logo'];

if (!is_dir($username))
{     
$oldumask = umask(0); 
mkdir($username, 0777); 
umask($oldumask); 
}

$now = new DateTime(null, new DateTimeZone('Asia/Kolkata'));
$date_time = $now->format('d-m-Y H:i:s');
$filename1 = $username;
$filename2 = "_Design Brief ";
$filename3 = ".xls";
$final_filename = $filename1.$filename2.$date_time.$filename3;
$path_xls = "/";
$path_to_xls = $username.$path_xls.$final_filename;
$workbook = new Spreadsheet_Excel_Writer($path_to_xls);

$_SESSION['objworkbook'] = $workbook;
$worksheet =& $workbook->addWorksheet('Design Brief Details');
$worksheet->write(0, 0, 'uid');
$worksheet->write(0, 1, $uid);
$worksheet->write(1, 0, 'name_in_logo');
$worksheet->write(1, 1, $name_in_logo);
$workbook->close();

?>

1 个答案:

答案 0 :(得分:1)

您无法使用Spreadsheet_Excel_Writer来阅读现有文件。