为什么在使用microsoft excel 2007版本以xls格式打开excel文件时出现文件错误:“数据可能已丢失”?

时间:2011-05-22 11:08:38

标签: php excel

我正在努力生成excel file.it是succssfully生成文件但是当我试图打开它时显示error.please建议我如何解决它。

这是我的代码

 require_once "../php_writeexcel-0.3.0/class.writeexcel_workbook.inc.php";
 require_once "../php_writeexcel-0.3.0/class.writeexcel_worksheet.inc.php";

$fname = tempnam("/tmp", "demo.xls");
$workbook =& new writeexcel_workbook($fname);
$worksheet =& $workbook->addworksheet('Demo');
$worksheet2 =& $workbook->addworksheet('Another sheet');
$worksheet3 =& $workbook->addworksheet('And another');



$worksheet->set_column('A:C', 32);
$heading  =& $workbook->addformat(array(
                                        bold    => 1,
                                        color   => 'blue',
                                        size    => 18,
                                        merge   => 1,
                                        ));

$headings = array('Out Telco Wise Report', '');
$worksheet->write_row('C1', $headings, $heading);




$worksheet->write('A2', "Request From");
$worksheet->write('B2', "Out Telco");
$worksheet->write('C2', "Total");


$i=3;
while($rowres=mysql_fetch_array($result_excel))
{

            $sql3="select ceil(length(msg_body)/160) as no_sms, count(*)as total from outbox   ".$with_out_client." AND request_from='".$rowres['request_from']."' AND out_telco='".                 $rowres['out_telco']."'  group by no_sms";
                 $result2=mysql_query($sql3);
                 $count2=0;
                 while($row2 = mysql_fetch_array($result2))
                   {
                     $count2 =$count2+($row2['total']*$row2['no_sms']);             
                   }




$worksheet->write('A'.$i, $rowres["request_from"]);
$worksheet->write('B'.$i, $rowres["out_telco"]);
$worksheet->write('C'.$i, $count2);
$i++;
}


$workbook->close();


header("Content-Type:application/vnd.ms-excel; name=\"example-demo.xls\"");
header("Content-Disposition: attachment; filename=\"example-demo.xls\"");
$fh=fopen($fname, "rb");
fpassthru($fh);
unlink($fname);

0 个答案:

没有答案