为什么我会收到文件错误:“数据可能已丢失”使用 Microsoft Excel 2007 版本打开 xls 格式的 Excel 文件时?
我正在使用 PHP 生成 Excel 文件。它成功生成了文件,但是当我尝试在 Excel 2007 中打开它时,它显示错误:“数据可能已丢失”。请提出解决建议。
这是我的代码:
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);
I am working on generating an Excel file, using PHP. It is successful in generating the file, but when I try to open it in Excel 2007, it shows an error: "Data may have been lost". Please give suggestions to solve it.
Here is my code:
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论