PHP generates Excel files and prints to the browser

Source: Internet
Author: User

This article describes the PHP spreadsheet_excel_writer and how to generate Excel files.
First step, install Spreadsheet_excel_writer because this package uses OLE packages, you may need to install it

Perform the following command to perform the update: Update pear.php.net ole-0.5 spreadsheet_excel_writer-0.9.1

Looking at an instance, Myfile.xls is the filename (including the path), and the workbook contains a list of student lists

<?php
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, ' grade ');
$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 ();
?>

Here is a section to export data to the user to save it.

<?php
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, ' grade ');
$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 ();

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.