我正在使用spreadsheet_excel_writer(9.2)从mysql(4.1.22)数据库下载excel文件。我已经在同一台服务器上成功完成了这个,这段代码非常相似,但在这种情况下它无法正常工作。我得到一个excel文件,其中包含数据但是在一个单元格中混合了各种字符。有谁知道问题可能是什么?我几天来一直在做改造和重新测试。如果有人能发现我没看到的东西,我会非常感激。
<?php
require_once "/home/cloudare/php/Spreadsheet/Excel/Writer.php";
// Create workbook
$workbook =& new Spreadsheet_Excel_Writer();
// sending HTTP headers
$workbook->send('registration.xls');
// Create worksheet
$worksheet =& $workbook->addWorksheet('Registration Worksheet');
// Add DB connection script here
include("dbinfo.inc.php");
include("functions.inc.php");
$from=$_POST['from'];
$to=$_POST['to'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM register WHERE date BETWEEN '$from' AND '$to'" ;
$result = mysql_query($query);
//$result = do_query($query,__LINE__);
// Loop through the data, adding it to the sheet
while($row = mysql_fetch_assoc($result))
{
$array[] = $row;
extract($row);
$worksheet->write($currentRow,0,$id);
$worksheet->write($currentRow,1,$name);
$worksheet->write($currentRow,2,$last);
$worksheet->write($currentRow,3,$title);
$worksheet->write($currentRow,4,$company);
$worksheet->write($currentRow,5,$phone);
$worksheet->write($currentRow,6,$mobile);
$worksheet->write($currentRow,7,$email);
$worksheet->write($currentRow,8,$cloud);
$worksheet->write($currentRow,9,$participant);
$worksheet->write($currentRow,10,$date);
// Remember Excel starts counting rows from #1!
$excelRow = $currentRow + 1;
$currentRow++;
}
$workbook->close();
?>
这是结果工作表:
ÐÏࡱá; THY
þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
取值@格特 MrClann Credogert@clanncredo.ie 2011-06-17°S @吉姆 MaherDirectorTrigraph 01-6390050087-6261422jim@trigraph.ieð?
2011-06-17Às@ MichaelMcKennaPrincipal 顾问 的SmartCloud @ìÌ~TBmmckenna@smartcloud.ieð?
2011-06-17Ðs@ LiamConnolly ConsultantCapricornVentis6|ÊA#liam.connolly@capventis.comð?
2011-06-17às@ MinhajShaikh MrNCIapnaminhaj@hotmail.comð? 2011-06-17&GT; ¶ 根 Entryÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
答案 0 :(得分:1)
S_E_W是死器。你应该在某些时候切换到PHPExcel,特别是如果你想要支持比BIFF 5.0文件更新的东西(Excel 5.0)。
检查您的查询是否正常工作并生成正确的$行。并试着像瘟疫一样避免extract()
。这和register_globals
的想法几乎一样糟糕,让你重现了register_globals引起的完全相同的问题。键入$row['id']
,$row['name']
等等,并没有太多工作,并且在执行extract()调用之前,可以省去覆盖用于其他目的的其他变量的烦恼。