Ec (2); In the htdocs folder, save the file as & ldquo; excelsample. php tutorial & rdquo ;. Open a browser and enter "example" in the address bar. The current "excelite" page is displayed. Create a workbook named "php_excel_test.xls" at the same time and enter "test" and "rdquo" in cell A1 of the worksheet ;. Open the work book php_excel_test.xls. In cell A1, you will see the script ec (2); script
In the htdocs folder, save the file as "excelsample. php tutorial ". Open your browser and enter:
The current Excel worksheet is displayed on the page. A Workbook named php_excel_test.xls is created at the same time and "test" is entered in cell A1 of Sheet 1 ".
Open the work bookphp_excel_test.xls. In cell A1, you will see that "test" has been entered ".
Note: To prevent garbled characters, the encoding format is set at the beginning of the code, and the file is saved in gb2312 format when saving the file.
// Specify the page encoding to prevent Chinese garbled characters
Header ('content-type: text/html; charset = gb2312 ');
// Start Excel
$ Ms_excel = new COM ("excel. application") or die ("Excel application cannot be opened ");
// Display the current Excel version on the webpage
Echo "Excel Version: {$ ms_excel-> Version }";
// Create a workbook
$ Ms_excel-> Application-> Workbooks-> Add () or die ("New Workbooks cannot be added ");
// Input text in cell A1 in worksheet Sheet1 of the workbook
$ Ms_excel-> Worksheets ("Sheet1")-> Range ("A1")-> Value = "test ";
// Save the workbook. If no path is specified, it is saved in my document by default.
$ Ms_excel-> Workbooks (1)-> SaveAs ("php_excel_test.xls ");
// Close the workbook
$ Ms_excel-> Quit ();
// Clear the object
$ Ms_excel = null;
?>