If you want to write an xls with only one sheet, as it seems from your code,
then try this way.
just print your whole things on a web page, using colors you want.
then add the code in the beginning of file
// set $filename here
if( isset( $_GET['e'] ) ){
echo 'header("Content-type: application/vnd.ms-excel");'.
'header("Content-Disposition: attachment;
filename=\"$filename\"");'.
'header("Expires: 0");'.
'header("Cache-Control: must-revalidate,
post-check=0,pre-check=0");'.
'header("Pragma: public");';
}else{
echo "<a href='{$_SERVER[PHP_SELF]}?e=1'>Export</a>";
}
On Mon, Jul 13, 2009 at 11:39 PM, binoy <binoymvee@...> wrote:
>
>
> Hi friends,
>
> Iam trying to export the datas from mysql to excel file with different
> color for different columns. All are working if the datas are low (about
> 2000), but i need to export about 8000 records from the mysql. when i try to
> take this mcuh record i need to wait abt 5 minutes. How can i speed up this
> process,
> Iam pasting my code here. Please give an advice.
>
> <?php
> include ('config.php');
> $select = "SELECT Tariff, Service, DeliveryDate, DeliveryTime, POD FROM pod
> order by Date asc";
> $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( )
> );
> $fields = mysql_num_fields ( $export );
>
> $row =0;
>
> require_once "class.writeexcel_workbook.inc.php";
> require_once "class.writeexcel_worksheet.inc.php";
> $fname = tempnam("/tmp", "panes.xls");
> $workbook = &new writeexcel_workbook($fname);
> $worksheet1 =& $workbook->addworksheet('Panes 1');
>
> for ( $i = 1; $i < $fields; $i++ ){
> $headerfieldname = mysql_field_name( $export , $i );
> $worksheet1->write(0, $i, $headerfieldname, '');
> }
>
> $cnt =1;
>
> $format1 =& $workbook->addformat(array('fg_color' =>'rose'));
> $format2 =& $workbook->addformat(array('fg_color' =>'yellow'));
> $format3 =& $workbook->addformat(array('fg_color' =>'purple'));
> $format4 =& $workbook->addformat(array('fg_color' =>'white'));
>
>
> while( $row = mysql_fetch_row( $export ) ) {
>
> $selectcolor = "SELECT colorname, col FROM colorscheme where
> row='".$cnt."' order by col";
>
> $exportcolor = mysql_query ( $selectcolor );
> $newcolors = mysql_fetch_object($exportcolor);
> $column = $newcolors->col;
>
> for($q=1; $q <=14; $q++) {
>
>
> switch($newcolors->colorname) {
> case 'rose' :
> $format = $format1;
> break;
> case 'yellow' :
> $format = $format2;
> break;
> case 'purple' :
> $format = $format3;
> break;
> default:
> $format = $format4;
> break;
> }
>
> $newcolors = mysql_fetch_object($exportcolor);
> $column = $newcolors->col;
>
>
> $worksheet1->write($cnt, $q, $row[$q], $format );
>
> }
> $cnt++;
>
>
> }
>
> $workbook->close();
> header("Content-Type: application/x-msexcel;
> name=\"".'Log-'.date('dmy', time()).".xls\"");
> header("Content-Disposition: inline; filename=\"".'Log-'.date('dmy',
> time()).".xls\"");
> $fh=fopen($fname, "rb");
> fpassthru($fh);
> unlink($fname);
>
> With Regards
> Binoy.M.V
>
>
> Looking for local information? Find it on Yahoo! Local
> http://in.local.yahoo.com/
>
> [Non-text portions of this message have been removed]
>
>
>
[Non-text portions of this message have been removed]