Php generates excelxls documents. Php Tutorial generate excelxls document method 1-use HTTP header as described in MSWord, you need to format the HTMLPHP page and add it to your PHP script using Excel-friendly CSS and header information. Php Tutorial to generate excel xls document
Method 1-use the HTTP header
As described in MS Word, you need to format HTML/PHP pages using Excel-friendly CSS and header information
Add to Your PHP script.
Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: attachment?filename=document_name.xls ");
Echo"";
Echo" ";
Echo"";
Echo"Testdata1TTestdata2T n ";
Echo"";
Echo"";
?>
Method 2-use a COM object
Note that the code described in MS Excel must be installed after running on the server.
We use a file to save to the temporary directory first, as the same practice of MS Word.
// Create new COM object-excel. application
$ Xl = new COM ("excel. application ");
// Hide MS Excel application window
$ Xl-> Visible = 0;
// Create new document
$ XlBook = $ xl-> Workbooks-> Add ();
// Create Sheet 1
$ XlBook-> Worksheets (1)-> Name = "Worksheet 1 ";
$ XlBook-> Worksheets (1)-> Select;
// Set Width & Height
$ Xl-> ActiveSheet-> Range ("A1: A1")-> ColumnWidth = 10.0;
$ Xl-> ActiveSheet-> Range ("B1: B1")-> ColumnWidth = 13.0;
// Add text
$ Xl-> ActiveSheet-> Cells (1, 1)-> Value = "TEXT ";
$ Xl-> ActiveSheet-> Cells (1, 1)-> Font-> Bold = True;
// Save document
$ Filename = tempnam (sys_get_temp_dir (), "excel ");
$ XlBook-> SaveAs ($ filename );
// Close and quit
Unset ($ xlBook );
$ Xl-> ActiveWorkBook-> Close ();
$ Xl-> Quit ();
Unset ($ xl );
Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: attachment?filename=document_name.xls ");
// Send file to browser
Readfile ($ filename );
Unlink ($ filename );
Excel xls document method 1-use the HTTP header as described in MS Word, the HTML/PHP page you want to format is added to your PHP script using Excel-friendly CSS and header information ....