Operate Excel instance code in PHP

Source: Internet
Author: User

CopyCode The Code is as follows: <? PHP
// 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 ("cannot open an Excel applicationProgram");

// Display the current Excel version on the webpage
Echo "Excel version: {$ ms_excel-> Version} \ n ";

// 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;
?>

In the htdocs folder, save the file as "excelsample. php ". Open your browser and enter:

Http: // localhost/excelsample. php

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.