Page 1 of 1

How to generate excel spreadsheet in php

Posted: Wed Apr 08, 2009 7:52 am
by mona02
hello friends
I wan't to generate xcel spreadsheet when user click on link export date to excel .The excel should genenrate on the basis of database values .I know how to generate xcel but i didn't know how to set the style for xcel sheet so that it should be visible like the document.for this i am using the excelwriter class my code is as follows:
<?php
require_once('classes/excel.inc.php');
include('connection.php');
header("Content-Disposition: attachment; filename=\"testcases.xls\"");
header("Content-Type: application/vnd.ms-excel; name=\"test.xls\"");
$excel=new ExcelWriter("");
$myArr=array("Testcase Id","Testcase Title","Date","Due Date","Case Status","Priority","Actual Result","Expected Result");
$excel->writeLine($myArr,'style=font-weight:bold;background-color:#999;text-align:center');

$query="Select * from testcase";
$sql=mysql_query($query);
if (!$sql)
{
die('Error in updating the records'.mysql_error());
}
while($row=mysql_fetch_array($sql))
{

$defFontSize=8;
$excel->writeRow();
$excel->writeCol($row['testcase_id'],'style=color:#000;width:172px;text-align:center;text-align:center');
$excel->writeCol($row['testcase_title'],'');
$excel->writeCol($row['date'],'');
$excel->writeCol($row['due_date'],'');
$excel->writeCol($row['case_status'],'');
$excel->writeCol($row['priority'],'');
$excel->writeCol($row['actual_result'],'');
$excel->writeCol($row['expected_result'],'');
}

$excel->instream();
?>

Re: How to generate excel spreadsheet in php

Posted: Sat Jun 06, 2009 10:04 am
by akuji36