问候,
我无法弄清楚如何正确使用PHP,特别是PHPExcel.我已经阅读了关于这个主题的多篇帖子,但我一直在圈子里跑来跑去.这是我的代码的相关部分:
$viewinv = MysqL_connect($sqlsrv,$username,$password);
if (!$viewinv) { die('Could not connect to sql server. Contact administrator.'); }
MysqL_select_db($database,$viewinv) or die('Could not connect to database. Contact administrator.');
$query = "select unit_id,config,location from inventory;";
$result = MysqL_query($query);
if ($result = MysqL_query($query) or die(MysqL_error())) {
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setTitle('blah');
$rowNumber = 1;
$headings = array('Unit ID','Config','Location');
$objPHPExcel->getActiveSheet()->fromArray(array($headings),NULL,'A'.$rowNumber);
$rowNumber++;
while ($row = MysqL_fetch_row($result)) {
$col = 'A';
foreach($row as $cell) {
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$cell);
$col++;
}
$rowNumber++;
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="myFile.xls"');
header('Cache-Control: max-age=0');
$objWriter->save('PHP://output');
exit();
}
echo 'a problem has occurred... no data retrieved from the database';
PHPExcel肯定是从查询输出数据,我可以看到明文的点点滴滴,但它被大量的随机字符所包围,好像我正在查看压缩或编译的数据片段的内容.
例如:
PKâh¿>G’D²Xð[Content_Types].xml”MNÃ0…÷œ"ò%nY „švAa •(0ö¤±êØ–gúw{&i‰@ÕnbEö{ßøyìÑdÛ¸l mð¥‘×ÁX¿(ÅÛü)¿’òF¹à¡;@1_滘±Øc)j¢x/%ê…Eˆày¦
任何指针都将非常感激
最佳答案
原文链接:https://www.f2er.com/mysql/434215.html