export my Sql to excel sử dụng php với Spreadsheet Excel Writer

Bước 1 : cài pear lên server
các bạn dùng gói OLE
các bạn vào console của apache
gỏ
[root@localhost root]# pear install OLE
sẻ xúât hiện
downloading http://pear.php.net/get/OLE …
…done: 9,058 bytes
installed file /usr/share/pear///OLE.php
installed file /usr/share/pear/OLE/PPS.php
installed file /usr/share/pear/OLE/PPS/Root.php
installed file /usr/share/pear/OLE/PPS/File.php
install ok

Tiếp tục
[root@localhost root]# pear install Spreadsheet_Excel_Writer

xuất hiện
downloading http://pear.php.net/get/Spreadsheet_Excel_Writer …
…done: 55,402 bytes
installed file /usr/share/pear/Spreadsheet/Excel//Writer.php
installed file /usr/share/pear/Spreadsheet/Excel//Writer/BIFFwriter.php
installed file /usr/share/pear/Spreadsheet/Excel//Writer/Workbook.php
installed file /usr/share/pear/Spreadsheet/Excel//Writer/Format.php
installed file /usr/share/pear/Spreadsheet/Excel//Writer/Worksheet.php
installed file /usr/share/pear/Spreadsheet/Excel//Writer/Parser.php
installed file /usr/share/pear/Spreadsheet/Excel//Writer/Validator.php
install ok

xong

xampp 1.7.7 có cài sẳn pear rồi các bạn nhé

Bước 2 :

Các bạn down Spreadsheet Excel Writer

bạn đưa thư mục write vào project của bạn

rồi tạo 1 file export.php ( mục đích xuất ra file exel ) với nội dung sau:

require_once(‘Writer.php’);

$workbook = new Spreadsheet_Excel_Writer();

//tạo file exel mới
$workbook->setVersion(8, ‘utf-8′);

$worksheet =& $workbook->addWorksheet(‘test 1243′);

//tạo sheet mới

$worksheet->setInputEncoding(‘utf-8′);

 

//dữ liệu ghi ra file exel

 

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

 

//kết thúc

$worksheet->hideGridLines();
$worksheet->setHeader(‘Header’);
$worksheet->setFooter(‘Footer’);

//gửi header để lưu file

$workbook->send(‘test.xls’);
$workbook->close();

 

 

bạn nào muốn hiểu kĩ hơn về exel có thể đọc 2 tài liệu dưới đây nhé

- Microsoft Excel File Format
- Microsoft Compound Document

2 Responses to “export my Sql to excel sử dụng php với Spreadsheet Excel Writer”

  1. Phương says:

    “Bước 2 :
    Các bạn down Spreadsheet Excel Writer”
    không có link bạn ạ

Leave a Reply

UserOnline

Tìm Kiếm

Đối Tác

Quảng cáo

Link Exchange

Giao diện website vietnam travel Magento themes
Creating intuitive magento themes, professional magento templates and powerful magento extensions

About

Với đội ngũ nhân viên trẻ, nhiệt huyết yêu thích công nghệ mới. Tận tâm với công việc. Chúng tôi cam kết mang lại sự hài lòng tối đa với các dịch vụ mà chúng tôi cung cấp.

Liên hệ

Zblue.net
Địa Chỉ: 356 QL 20, KP4
Liên Nghĩa, Đức Trọng, Lâm Đồng
Phone: 0633.994.997
Hotline: 0919911011
Email: info@zblue.net