Spreadsheet_Excel_Writer (Previous) (Next) Formatting Tutorial

View this page in Last updated: Sun, 24 Aug 2008
English | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Plain HTML

Introduction

Introduction -- how to generate Excel files

What is Spreadsheet_Excel_Writer?

Spreadsheet_Excel_Writer is a tool for creating Excel files without the need for COM components. The files generated by the current version of Spreadsheet_Excel_Writer correspond to the Excel 5 (BIFF5) format, so all functionality until that version of Excel (but not beyond) should be available.

Using it

The most common use for Spreadsheet_Excel_Writer will be spitting out large (or not so large) amounts of information in the form of a spreadsheet, which is easy to manipulate with a fairly ubiquitous spreadsheet program such as Excel (or OpenOffice).

So let's cut to the chase and see how this is done:

The first thing you should notice, is that we created a workbook before any worksheets. All worksheets are contained within a workbook, and a workbook may contain several worksheets.

Another important thing, which you should have in mind when programming with Spreadsheet_Excel_Writer, is that ampersand sign (&) that appears when we created our worksheet. That ampersand means we are referencing a Worksheet object instead of copying it. If you don't know what that means, don't worry, all you have to remember is to always use ampersands when calling addWorksheet() for creating a worksheet, or addFormat() for creating a format.

Saving to a regular file

You may have noticed also the following line:

// sending HTTP headers
$workbook->send('test.xls');
What that means is that we are sending our spreadsheet to a browser. But what if we just want to save the spreadsheet in our machine? Well, you just have to omit that line and give a valid file path to the workbook constructor.

For example, if we wanted to save the same spreadsheet we created in our first example to a file named 'test.xls', we would do it like so:

More tutorials

If you would like to learn about formatting (fonts, cell color, text alignment, etc...) with Spreadsheet_Excel_Writer, you can check the formatting tutorial here.

Spreadsheet_Excel_Writer (Previous) (Next) Formatting Tutorial

Download Documentation Last updated: Sun, 24 Aug 2008
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
Note by: alangrus
CSVtoXLS.php Program Notes

I am often asked to provide output from the database in a spreadsheet XLS file. I built a shell around spreadsheet-excel-writer to use as a production conversion tool, to accomplish high format XLS file creation from an ASCII CSV file. As a PHP program, it should work on any O/S that you can install PHP 4.3 or better onto.

CSVtoXLS.php is a PHP utility to convert CSV data into business class XLS spreadsheet files, tested as compatible with OpenOffice 2.0 Calc and Excel 2000. It is provides for a high level of spreadsheet formatting and also offers formulas. CSVtoXLS.php takes advantage of those features and provides meaningful formatting and a simple Column SUM automatically generated at the bottom of any Decimal Column.

See Narrative and Download at http://performantsystems.com/CSVtoXLS.html
- Alan Gruskoff