Format text in Excel file via PHP

31,082

Solution 1

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

Solution 2

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.

Solution 3

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

Edit: This project is now deprecated.

Share:
31,082

Related videos on Youtube

Pamela
Author by

Pamela

Updated on July 09, 2022

Comments

  • Pamela
    Pamela 11 months

    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?

  • Lucas
    Lucas almost 11 years
    Old post but damn, that was useful. Thanks a lot!
  • Recovering Nerdaholic
    Recovering Nerdaholic over 7 years
    Simple and elegant solution.
  • user1015214
    user1015214 about 5 years
    This is a dead link.
  • Peter Howe
    Peter Howe about 5 years
    Fixed - but the project is now deprecated.

Related