PHP Excel export Spreadsheet_Excel_Writer Excel
I have seen a lot of articles about exporting Excel from PHP, and I have done so in many ways,
For example, echo a Table and modify the header to Excel.
In fact, among the many methods, it seems that Spreadsheet_Excel_Writer in Pear is very useful.
This article does not describe how to install Spreadsheet_Excel_Writer.
The answer :) can also refer to: http://pear.php.net/package/Spreadsheet_Excel_Writer/download
Reference content is as follows: // Call Writer. php Require_once 'Spreadsheet/Excel/Writer. php '; // Create a Workbook $ Workbook = new Spreadsheet_Excel_Writer (); // Define the exported Excel file name $ Workbook-> send('test.xls '); // Create a Worksheet $ Worksheet = & $ workbook-> addWorksheet ('my first worksheet '); // Set the font size $ Format_column = & $ workbook-> addformat (array ('size' => 9, 'bold '=> 1 )); // Write data // Title line (first line) $ Worksheet-> write (0, 0, 'name', $ format_column ); $ Worksheet-> write (0, 1, 'age', $ format_column ); // The first person (row 2) $ Worksheet-> write (1, 0, 'johnsmith '); $ Worksheet-> write (1, 1, 30 ); // Second person (row 3) $ Worksheet-> write (2, 0, 'Johann Schmidt '); $ Worksheet-> write (2, 1, 31 ); // Third person (row 4) $ Worksheet-> write (3, 0, 'Juan Herrera '); $ Worksheet-> write (3, 1, 32 ); // Close The Workbook $ Workbook-> close (); ?> |
:
Of course, Spreadsheet_Excel_Writer has more than these settings. for details, see:
Http://pear.php.net/package/Spreadsheet_Excel_Writer/docs