Copy CodeThe code is as follows:
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 worksheet Sheet1 of a workbook
$ms _excel->worksheets ("Sheet1")->range ("A1")->value= "test";
Save the workbook, or save it in my document by default if no path is specified
$ms _excel->workbooks (1)->saveas ("Php_excel_test.xls");
Close Workbook
$ms _excel->quit ();
Empty objects
$ms _excel=null;
?>
Save the file as "excelsample.php" in the Htdocs folder. Open your browser and enter it in the Address bar:
http://localhost/excelsample.php
At this point, the current version of Excel is displayed in the page, a workbook named Php_excel_test.xls is created, and the test is entered in cell A1 in worksheet Sheet1.
Open Workbook Php_excel_test.xls, and in cell A1 you will see that you have entered test.
Note: To prevent garbled characters, the encoding format is set at the beginning of the code, and when you save the file, choose Save as gb2312 format.
http://www.bkjia.com/PHPjc/321657.html www.bkjia.com true http://www.bkjia.com/PHPjc/321657.html techarticle Copy the code as follows: PHP//Specify the page encoding, to prevent the occurrence of Chinese garbled case header (' content-type:text/html; charset=gb2312 ');//Start Excel $ms _excel=new COM ("Excel.app ...