views:

3172

answers:

5

Hi, I'm loading data from my database, and exporting to an Excel file via a method I found on this site: http://www.appservnetwork.com/modules.php?name=News&file=article&sid=8

It works, but what I want to do now is format the text before it exports - change the font and text size. Does anybody have any ideas on how to do this?

+4  A: 

I have written Excel spreadsheets from PHP 5 using the PEAR :: Package :: Spreadsheet_Excel_Writer classes. You can do a lot with this package.

Bill Karwin
+1  A: 

Depending on the speed in which you wish to deploy your solution, one method is to just use the HTML table tag, store all your data in tables using style markup, and then use PHP header's option to force the browser to save is as a .xls file.

For proof of concept, copy this code into notepad, save as .xls, and then open with Excel:

<table>
<tr><th>Column 1</th><th>Column 2</th></tr>
<tr><td style="font-size:200%">Answer 1</td><td style="color:#f00">Answer 2</td></tr>
<tr><td colspan="2" style="font-weight:bold">Answer 3 with 2 columns</td></tr>
</table>

Its not the most elegant solution, but it will absolutely suit your needs.

Eric Caron
A: 

The TinyButStrong template system (www.tinybutstrong.com) has an optional plugin that allows you to write to excel templates.

I've used this a great deal. It's particularly neat in that you can set up the page to write to either HTML or Excel depending on a flag - so typically my reports offer 'display on page' and 'write to excel' options.

Cruachan
A: 

PHPExcel provides you with the facilities to do this and more.

Peter Howe
Only for 2007. But looks cool.
Justin
+1  A: 

I've used php_writeexcel a few times, and liked it a lot! :)