PHP Export Excel spreadsheet_excel_writer

Source: Internet
Author: User

I've seen so many articles about PHP exporting Excel, and I've done it through a lot of ways.

For example, ECHO is a table, and then the header is modified to Excel.

In fact, in many ways the feeling of pear spreadsheet_excel_writer is very useful.

About the installation of Spreadsheet_excel_writer This article is not introduced, can be found through Google

Answer:) can also refer to: http://pear.php.net/package/Spreadsheet_Excel_Writer/download

<?php
//调用Writer.php
require_once 'Spreadsheet/Excel/Writer.php';
//创建Workbook
$workbook = new Spreadsheet_Excel_Writer();
//定义导出Excel文件名
$workbook->send('test.xls');
//创建Worksheet
$worksheet =& $workbook->addWorksheet('My first worksheet');
//设置字体大小
$format_column = & $workbook->addformat(array('Size'=>9,'Bold'=>1));
//数据写入
//标题行(第一行)
$worksheet->write(0, 0, 'Name', $format_column);
$worksheet->write(0, 1, 'Age', $format_column);
//第一个人(第二行)
$worksheet->write(1, 0, 'John Smith');
$worksheet->write(1, 1, 30);
//第二个人(第三行)
$worksheet->write(2, 0, 'Johann Schmidt');
$worksheet->write(2, 1, 31);
//第三个人(第四行)
$worksheet->write(3, 0, 'Juan Herrera');
$worksheet->write(3, 1, 32);
//关闭Workbook
$workbook->close();
?>

Effect Chart:

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.