Excel sheet writer performace in php?

  • Thread starter Thread starter alex
  • Start date Start date
A

alex

Guest
try this code

<?
// Connect database.
mysql_connect("localhost","root","");
mysql_select_db("testdb");

// Get data records from table.
$result=mysql_query("select * from sales");

// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=orderlist.xls ");
header("Content-Transfer-Encoding: binary ");

xlsBOF();

/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/

xlsWriteLabel(0,0,"Report");

// Make column labels. (at line 3)
xlsWriteLabel(2,0,"Id");
xlsWriteLabel(2,1,"Gas");
xlsWriteLabel(2,2,"Cost Amount");
xlsWriteLabel(2,3,"Retail");
xlsWriteLabel(2,4,"Gross Profit");
xlsWriteLabel(2,5,"new");

$xlsRow = 3;

// Put data records from mysql by while loop.
while($row=mysql_fetch_array($result)){

xlsWriteNumber($xlsRow,0,$row['ID']);
xlsWriteLabel($xlsRow,1,$row['GAS']);
xlsWriteNumber($xlsRow,2,$row['CostAmount']);
xlsWriteNumber($xlsRow,3,$row['Retail']);
xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

$xlsRow++;
}
xlsEOF();
exit();
?>
 
I have a thousands of recordsets from mysql database which need to be exported to excel sheet. I am using pear excel sheet writer in php to export the data to excels ,but it is taking too long time (15-20 mins ) to export to excel .Any one please help me to get it done in seconds.
 
try this code

<?
// Connect database.
mysql_connect("localhost","root","");
mysql_select_db("testdb");

// Get data records from table.
$result=mysql_query("select * from sales");

// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=orderlist.xls ");
header("Content-Transfer-Encoding: binary ");

xlsBOF();

/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/

xlsWriteLabel(0,0,"Report");

// Make column labels. (at line 3)
xlsWriteLabel(2,0,"Id");
xlsWriteLabel(2,1,"Gas");
xlsWriteLabel(2,2,"Cost Amount");
xlsWriteLabel(2,3,"Retail");
xlsWriteLabel(2,4,"Gross Profit");
xlsWriteLabel(2,5,"new");

$xlsRow = 3;

// Put data records from mysql by while loop.
while($row=mysql_fetch_array($result)){

xlsWriteNumber($xlsRow,0,$row['ID']);
xlsWriteLabel($xlsRow,1,$row['GAS']);
xlsWriteNumber($xlsRow,2,$row['CostAmount']);
xlsWriteNumber($xlsRow,3,$row['Retail']);
xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

$xlsRow++;
}
xlsEOF();
exit();
?>
 
try this code

<?
// Connect database.
mysql_connect("localhost","root","");
mysql_select_db("testdb");

// Get data records from table.
$result=mysql_query("select * from sales");

// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=orderlist.xls ");
header("Content-Transfer-Encoding: binary ");

xlsBOF();

/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/

xlsWriteLabel(0,0,"Report");

// Make column labels. (at line 3)
xlsWriteLabel(2,0,"Id");
xlsWriteLabel(2,1,"Gas");
xlsWriteLabel(2,2,"Cost Amount");
xlsWriteLabel(2,3,"Retail");
xlsWriteLabel(2,4,"Gross Profit");
xlsWriteLabel(2,5,"new");

$xlsRow = 3;

// Put data records from mysql by while loop.
while($row=mysql_fetch_array($result)){

xlsWriteNumber($xlsRow,0,$row['ID']);
xlsWriteLabel($xlsRow,1,$row['GAS']);
xlsWriteNumber($xlsRow,2,$row['CostAmount']);
xlsWriteNumber($xlsRow,3,$row['Retail']);
xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

$xlsRow++;
}
xlsEOF();
exit();
?>
 
try this code

<?
// Connect database.
mysql_connect("localhost","root","");
mysql_select_db("testdb");

// Get data records from table.
$result=mysql_query("select * from sales");

// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=orderlist.xls ");
header("Content-Transfer-Encoding: binary ");

xlsBOF();

/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/

xlsWriteLabel(0,0,"Report");

// Make column labels. (at line 3)
xlsWriteLabel(2,0,"Id");
xlsWriteLabel(2,1,"Gas");
xlsWriteLabel(2,2,"Cost Amount");
xlsWriteLabel(2,3,"Retail");
xlsWriteLabel(2,4,"Gross Profit");
xlsWriteLabel(2,5,"new");

$xlsRow = 3;

// Put data records from mysql by while loop.
while($row=mysql_fetch_array($result)){

xlsWriteNumber($xlsRow,0,$row['ID']);
xlsWriteLabel($xlsRow,1,$row['GAS']);
xlsWriteNumber($xlsRow,2,$row['CostAmount']);
xlsWriteNumber($xlsRow,3,$row['Retail']);
xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

$xlsRow++;
}
xlsEOF();
exit();
?>
 
try this code

<?
// Connect database.
mysql_connect("localhost","root","");
mysql_select_db("testdb");

// Get data records from table.
$result=mysql_query("select * from sales");

// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=orderlist.xls ");
header("Content-Transfer-Encoding: binary ");

xlsBOF();

/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/

xlsWriteLabel(0,0,"Report");

// Make column labels. (at line 3)
xlsWriteLabel(2,0,"Id");
xlsWriteLabel(2,1,"Gas");
xlsWriteLabel(2,2,"Cost Amount");
xlsWriteLabel(2,3,"Retail");
xlsWriteLabel(2,4,"Gross Profit");
xlsWriteLabel(2,5,"new");

$xlsRow = 3;

// Put data records from mysql by while loop.
while($row=mysql_fetch_array($result)){

xlsWriteNumber($xlsRow,0,$row['ID']);
xlsWriteLabel($xlsRow,1,$row['GAS']);
xlsWriteNumber($xlsRow,2,$row['CostAmount']);
xlsWriteNumber($xlsRow,3,$row['Retail']);
xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

$xlsRow++;
}
xlsEOF();
exit();
?>
 
try this code

<?
// Connect database.
mysql_connect("localhost","root","");
mysql_select_db("testdb");

// Get data records from table.
$result=mysql_query("select * from sales");

// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=orderlist.xls ");
header("Content-Transfer-Encoding: binary ");

xlsBOF();

/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/

xlsWriteLabel(0,0,"Report");

// Make column labels. (at line 3)
xlsWriteLabel(2,0,"Id");
xlsWriteLabel(2,1,"Gas");
xlsWriteLabel(2,2,"Cost Amount");
xlsWriteLabel(2,3,"Retail");
xlsWriteLabel(2,4,"Gross Profit");
xlsWriteLabel(2,5,"new");

$xlsRow = 3;

// Put data records from mysql by while loop.
while($row=mysql_fetch_array($result)){

xlsWriteNumber($xlsRow,0,$row['ID']);
xlsWriteLabel($xlsRow,1,$row['GAS']);
xlsWriteNumber($xlsRow,2,$row['CostAmount']);
xlsWriteNumber($xlsRow,3,$row['Retail']);
xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

$xlsRow++;
}
xlsEOF();
exit();
?>
 
Back
Top