1

I am using "Writer.php" file provided by pear.php.net to generate excel files. What i'm finding difficult to do is adding worksheets to an existent workbook. I tried few things but failed to add worksheet. I am really bad at OOP, any help would be much appreciated. Thanks in advance.

Here is the php code that genrates the excel file:

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

?>
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
Amit Singh
  • 2,267
  • 4
  • 25
  • 50
  • 2
    To add a worksheet to an existing workbook, you'll need a reader and a writer, or a library that can both read and write: Spreadsheet_Excel_Writer (as its name might suggest) only writes spreadsheet files, it can't read them, so when you save you're overwriting any existing file with the same name. In addition to my own [PHPExcel library](http://www.phpexcel.net) that can both read and write, you'll find most other libraries for working with spreadsheets listed [here](http://stackoverflow.com/questions/3930975/alternative-for-php-excel) – Mark Baker Sep 10 '13 at 16:12
  • Removed PHPExcel tag as the question isn't about PHPExcel – Mark Baker Sep 10 '13 at 22:12
  • that was edited by parixit – Amit Singh Sep 11 '13 at 08:35

1 Answers1

1

You cannot use Spreadsheet_Excel_Writer to read existing files.

cweiske
  • 30,033
  • 14
  • 133
  • 194