Home > Backend Development > PHP Tutorial > PHP generates excel files and outputs them to the browser_PHP tutorial

PHP generates excel files and outputs them to the browser_PHP tutorial

WBOY
Release: 2016-07-13 17:05:28
Original
1282 people have browsed it

php tutorial generates excel files and outputs them to the browser
This article introduces php spreadsheet_excel_writer and how to generate excel files.
The first step is to install spreadsheet_excel_writer. Since this package uses the ole package, you may need to install it

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

Look at an example, myfile.xls is the file name (including path), and 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, '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();
?>

Let’s take a look at a method to export data to users for storage.

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();

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630785.htmlTechArticlephp tutorial to generate excel files and output them to the browser. This article introduces php spreadsheet_excel_writer and how to generate excel files. The first step is to install spreadsheet_excel_writer. Since this package uses...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template