Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我能';t从数据库中设置值,但硬编码值可以正常工作?_Php_Phpexcel - Fatal编程技术网

Php 为什么我能';t从数据库中设置值,但硬编码值可以正常工作?

Php 为什么我能';t从数据库中设置值,但硬编码值可以正常工作?,php,phpexcel,Php,Phpexcel,我正在使用此代码从数据库中设置cellvalue,但它不起作用 $excel2 = PHPExcel_IOFactory::createReader('Excel2007'); $excel2 = $excel2->load("test.xlsx"); // Empty Sheet $excel2->getActiveSheet()->setCellValue('A1', 'Date'); $m=2; $result=mysqli_query($con,"select *

我正在使用此代码从数据库中设置cellvalue,但它不起作用

$excel2 = PHPExcel_IOFactory::createReader('Excel2007');
$excel2 = $excel2->load("test.xlsx"); // Empty Sheet


$excel2->getActiveSheet()->setCellValue('A1', 'Date');

$m=2;
$result=mysqli_query($con,"select * from settings");

while($row=mysqli_fetch_array($result))
{
  $chan=$row['channelID'];
            $excel2->getActiveSheet()->setCellValue("C$m", $chan);
echo $chan;
echo "<br>";
$m++;
}

我不知道我哪里做错了,我想从数据库中设置值。如能提供任何帮助,将不胜感激。

What did
echo$chan给你看?另外,使用
print\r($row)在循环中。它显示了我在数据库中的值。请尝试将
$chan
包装在quotesTry中,类似这样的
$excel2->getActiveSheet()->setCellValue(“C$m”,“'.$chan”)单引号使其成为字符串。也不起作用。
$excel2->getActiveSheet()->setCellValue("C$m", "static text");