2

At present I'm storing data in a variable which contains HTML table. I got this idea from How to format excel file with styles, fonts, colors, tables etc with pure PHP?

$table = '<table>';
$table .= '<tr>';
$table .= '<td>1st row, 1st cell</td>';
$table .= '<td>1st row, 2nd cell</td>';
$table .= '</tr>';
$table .= '<tr>';
$table .= '<td>2nd row, 1st cell</td>';
$table .= '<td>2nd row, 2nd cell</td>';
$table .= '</tr>';
$table .= '</table>';
downloadAsExcel($table, 'somefilename');

function downloadAsExcel($html, $filename)
{
    header("Content-Type: application/excel");
    header("Content-Disposition: attachment; filename=".ucwords($filename)."-Data.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    echo $html
}

This is working fine and the output is as expected. However, I was wondering if I could create multiple sheets in a single excel file using a similar approach.

It would be wonderful if it could be done as I don't want to use a library to do the job. I've looked at PHPExcel, ExcelReader, DocRaptor etc and so I'm looking for answers (if at all it is possible) which don't use such libraries.

UPDATE : Almost forgot to mention - I also came across this http://webcheatsheet.com/php/create_word_excel_csv_files_with_php.php#excelcom but again this requires me to have MS Excel installed on the server, which I can't as it's a shared hosting account.

PS: I'm fine with the warning dialog that appears while opening an Excel file created by the above method.

4

2 回答 2

0

为什么你不能参加内置课程PHPExcel

(i.e) $objPHPExcel = new PHPExcel()

请通过以下链接,

使用 PHP 创建多个 Excel 工作表

于 2013-05-22T10:32:20.847 回答
0

您可以从头开始创建文件 - 您应该知道文件格式,并且从 Office 2007 开始,该标准是开放的。

您可以参考http://en.wikipedia.org/wiki/Office_Open_XML开始!

于 2013-05-22T10:34:12.320 回答