0

Hi all,

I've created an excel attachment containing an html table that sends using mail().

I'd like to extend that by including multiple tables in different worksheets in the same workbook.

Currently my $message = // The first table.

my $headers are:

$headers .= 'MIME-Version: 1.0' . "\r\n";
          $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
          $headers .= 'Content-Disposition: attachment; filename=Tables.xls' . "\r\n";
          $headers .= "From: me@example.co.uk" . "\r\n" .
           "Reply-To: me@example.co.uk" . "\r\n" .
           "X-Mailer: PHP/" . phpversion();

with mail($to, $subject, $message, $headers).

How would I go about creating another worksheet in that same file with a different message, i.e. table?

Thanks.

3
Contributors
5
Replies
9
Views
4 Years
Discussion Span
Last Post by Tinnin
0

Try looking at PHPExcel. This is a simple example that creates an Excel file with two sheets:

<?php
require_once 'PHPExcel.php';
require_once 'PHPExcel/IOFactory.php';

// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Create a first sheet, representing sales data
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Something');

// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Name of Sheet 1');

// Create a new worksheet, after the default sheet
$objPHPExcel->createSheet();

// Add some data to the second sheet, resembling some different data types
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'More data');

// Rename 2nd sheet
$objPHPExcel->getActiveSheet()->setTitle('Second sheet');

// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="name_of_file.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
?>
0

IIM: I don't really want to go down the PHPexcel route. I was hoping there would be a way to do it using fopen().

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.