Skip to content

A PHP Extension to generate and read Excel Files

Notifications You must be signed in to change notification settings

mizafish/PHPExcel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This Extension is Based On ExcelFormat, By Martin Fuchs And Yap Chun Wei. I use their code from codeproject, which can be download from http://www.codeproject.com/Articles/42504/ExcelFormat-Library .Thanks to Martin Fuchs and Yap Chun Wei.

I just wrap this library for PHP, the initial version is test on a windows 7 with Visual Studio 2008, run with PHP 5.4.9, thread safe.

The code was created a years before, just as a demo. Two years ago,I join a company works for electronic commerce, so, I always works with Excel, Initialy, We use a pure PHP version to create Excel, called PHPExcel.This library is great, but we found many times we need use it to work beyond it's design range, just like create a huge excel file. So I decide to create this extension, but with this extension, we found it generate excel very fast, but in destruct stage, it use too much time, So I droped it, use a self designed Excel Genreator instead, which is write by Java, with JXL.

Currently, I'm not busy as before, so I publish it, and try to supply more features and improve the performance by improve memory alloc.

This extension is write with Qt Creator, now the lastest version is 2.6.0, I think it may be the bestest C++ IDE, It makes coding more comfortable, thanks Nokia.

Now it with integrated charset support, so you can set utf-8 or gbk charset to Excel, and it works right!

To set default charset, you can set in you php.ini, with set entry:

	excel.default_charset	= UTF-8

Now I Test it with the code below:

	<?php
	error_reporting(E_ALL);
	$ts	= gettimeofday(true);
	$excel	= Excel::create(1, 'UTF-8');
	$font	= new ExcelFont(ExcelFont::WEIGHT_BOLD);
	$font->setColor(ExcelFont::COLOR_RED);
	$cellFmt	= new ExcelCellFormat($excel);
	$cellFmt->setFont($font);
	$sheet	= $excel->getWorkSheet(0);
	for ($row = 0; $row < 6000; ++ $row)
	{
		for ($col = 0; $col < 30; ++ $col)
		{
			$sheet->setWString($row, $col, '我是一只鱼', $cellFmt);
		}
	}
	$excel->saveAs('aaa.xls');
	echo gettimeofday(true) - $ts, ' sec';

It runs perfect on Windows Now, and it consumes almost 4.1 ~ 4.2 sec to generate this Excel, which size is about 2.55MB.
Now the integrated charset support only works on windows, and only test for chinese gbk and utf-8, Linux support will add in next week.

At 2012-12-20, Before the world rewind, I am glad to annonce, it runs perfect on Linux Now!! On My VPS, SAKURA VPS, 1G RAM and 100G HDD Brand, PHP 5.4.9, CentOS 6.3 32bit, Run the PHP code above, Script Charset is GBK, with itegrated Charset support, generate the Excel File use 2.1544990539551 sec, It runs perfect!

I add a simple compare with the Pure PHP Project, also called PHPExcel, project Home is http://phpexcel.codeplex.com/ , the simple test is based on the newest version, 1.7.8, the scripts is like below:

	<?php
	date_default_timezone_set('Asia/Shanghai');

	require './Classes/PHPExcel.php';

	$ts	= gettimeofday(true);
	$excel	= new PHPExcel();
	$sheet	= $excel->getSheet(0);
	for ($row = 1; $row <= 6000; ++ $row)
	{
		for ($col = 0; $col < 30; ++ $col)
		{
			$sheet->setCellValueByColumnAndRow($col, $row, 'I am a fish', false);
		}
	}
	$writer	= new PHPExcel_Writer_Excel5($excel);
	$writer->save('aaa.xls');
	echo gettimeofday(true) - $ts;

Note here, I did'nt use any style, and I replaced the text from Chinese to Pure English, for to avoid charset convert, But, the script consumes 21 ~ 22 second on my same laptop, and, It uses almost double of memory.
In common issue, the C++ implement will give you 6 times speed and half of memory consume, with less features.

About

A PHP Extension to generate and read Excel Files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published