我正在使用 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();
?>
这是生成的工作表:
ÐÏࡱá;þÿ
þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
s@Gert MrClann Credogert@clanncredo.ie 2011-06-17°s@Jim MaherDirectorTrigraph 01-6390050087-6261422jim@trigraph.ieð?
2011-06-17Às@MichaelMcKennaPrincipal Consultant 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> ¶ Root Entryÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿ
最佳答案
S_E_W 是死软件。你应该切换到 PHPExcel在某些时候,特别是如果您希望支持比 BIFF 5.0 文件 (Excel 5.0) 更新的内容。
检查您的查询是否正常工作并生成正确的 $row。并尽量避免 extract()
就像瘟疫一样。这几乎和 register_globals
一样可怕,并且让您重现 register_globals 最初引起的完全相同的问题。键入 $row['id']
、$row['name']
等并没有太多工作,并且省去了覆盖其他内容的烦恼在执行 extract() 调用之前,您用于其他目的的变量。
关于php - 电子表格 excel writer 9.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6413999/