Working with Excel instance code in PHP _php tutorial

Source: Internet
Author: User
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 ...

  • 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.