3
我使用PHPExcel將數據從mysql數據庫輸出到excel工作簿。我的工作簿有3張,大部分工作正常。我在輸出到第三張表格的最後一部分有問題。我想要做的是輸出一個表的行標題和列標題,其中的值取自一個MySQL表,然後每行/列組合的數字也取自基於該行/列標題是什麼。行和列標題按原樣寫入文件,但內部表格數字不是。當我回顯輸出以顯示所有數據時,行/列迭代正在遞增,因爲它們應該只是setCellValueByColumnAndRow似乎不會在工作表中設置值。下面是我遇到問題的那部分代碼。任何人都可以看到問題在我的代碼中?PHPExcel setCellValueByColumnAndRow不將數據寫入電子表格
$objPHPExcel->setActiveSheetIndex(2);
while($srow = mysql_fetch_assoc($query_company))
{
$newarray[] = $srow['entity'];
}
$row4 = 2;
$col4 = 1;
while($trow = mysql_fetch_row($query_ctry))
{
$country = $trow[0];
while($comp = each($newarray))
{
$company = $comp[1];
$total = mysql_query("SELECT noparts FROM totalslist WHERE country = '$country' AND entity = '$company'") or die (mysql_error());
if ($numrows = mysql_num_rows($total) == 0)
{
$totalres = 0;
}
else
{
$result3 = mysql_fetch_row($total);
$totalres = $result3[0];
}
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col4, $row4, $totalres);
$col4++;
}
reset($newarray);
$row4++;
$col4 = 1;
}
如果您找到了解決方案,請隨時回答您自己的問題,並幫助其他人解決同樣的問題。 – SomeKittens 2012-07-13 20:58:30