我正在使用 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();
?>