Php generates an excel file and outputs it to the browser _ PHP Tutorial

Source: Internet
Author: User
Php generates an excel file and outputs it to the browser. This document introduces phpspreadsheet_excel_writer and how to generate an excel file. Step 1: install spreadsheet_excel_writer because this package uses the php Tutorial to generate an excel file and output it to the browser
This article describes php spreadsheet_excel_writer and how to generate an excel file.
Step 1: install spreadsheet_excel_writer because this package uses the ole package, you may need to install it

Run the following command to update pear.php.net ole-0.5 spreadsheet_excel_writer-0.9.1.

For example, myfile.xls is a file name (including path). The Workbook contains a table with a student list.

Require_once 'Spreadsheet/excel/writer. php ';

// Creating workbook
$ Workbook = new spreadsheet_excel_writer('myfile.xls ');

// Adding worksheet
$ Worksheet = & $ workbook-> addworksheet ('students ');

// Data input
$ Worksheet-> write (0, 0, 'name ');
$ Worksheet-> write (0, 1, 'Grad ');
$ Worksheet-> write (1, 0, 'ivancho ');
$ Worksheet-> write (1, 1, 7 );
$ Worksheet-> write (2, 0, 'mariika ');
$ Worksheet-> write (2, 1, 7 );
$ Worksheet-> write (3, 0, 'stoyancho ');
$ Worksheet-> write (3, 1, 8 );

// Saving file
$ Workbook-> close ();
?>

Next, let's take a look at how to export the data to the user and save it.

Require_once 'Spreadsheet/excel/writer. php ';

// Creating workbook
$ Workbook = new spreadsheet_excel_writer ();

// Sending headers to browser
$ Workbook-> send('students.xls ');

// Adding worksheet
$ Worksheet = & $ workbook-> addworksheet ('students ');

// Data input
$ Worksheet-> write (0, 0, 'name ');
$ Worksheet-> write (0, 1, 'Grad ');
$ Worksheet-> write (1, 0, 'ivancho ');
$ Worksheet-> write (1, 1, 7 );
$ Worksheet-> write (2, 0, 'mariika ');
$ Worksheet-> write (2, 1, 7 );
$ Worksheet-> write (3, 0, 'stoyancho ');
$ Worksheet-> write (3, 1, 8 );

// Sending the file
$ Workbook-> close ();

This article describes php spreadsheet_excel_writer and how to generate an excel file. Step 1: install spreadsheet_excel_writer because this package uses...

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.