Save the file as a "excelsample.php tutorial" in the Htdocs folder. Open the browser and enter in the Address bar:
http://www.jzread.com/excelsample.php
The current version of Excel is displayed on the page, and the workbook named Php_excel_test.xls is created and the test is entered in the worksheet Sheet1 cell A1.
Open the workbook Php_excel_test.xls and you will see that you have entered the test in cell A1.
Note: In order to prevent garbled, the code format has been set up and the file is saved in gb2312 format.
<?php
Specify page encoding to prevent the occurrence of garbled Chinese
Header (' content-type:text/html charset=gb2312 ');
Start Excel
$ms _excel=new COM ("Excel.Application") or Die ("Cannot open Excel application");
Display the current version of Excel in a Web page
echo "Excel version: {$ms _excel->version}n";
Create a new workbook
$ms _excel->application->workbooks->add () or Die ("Cannot add a new workbook");
Enter text in cell A1 in the worksheet Sheet1 of the workbook
$ms _excel->worksheets ("Sheet1")->range ("A1")->value= "test";
Save the workbook, if you do not specify a path, the default is saved in my document
$ms _excel->workbooks (1)->saveas ("Php_excel_test.xls");
Close Workbook
$ms _excel->quit ();
Empty objects
$ms _excel=null;
?>