gpt4 book ai didi

php - 对象类无法转换为字符串错误

转载 作者:搜寻专家 更新时间:2023-10-31 21:06:56 24 4
gpt4 key购买 nike

我正在尝试将我的数据库值导入到我的 index.xlsx 工作表中所以我写了一个代码,使用 phpExcel 导入它

索引.php

<?php
require_once 'E:\Xampp\htdocs\Excel\Classes\phpExcel.php';
$con = mysql_connect('localhost','root','');
mysql_select_db('khader',$con);
$sql = "SELECT * FROM person";
$result = mysql_query($sql);
$filename = "index.xlsx";
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader ->setReadDataOnly(true);
$objReader ->$objReader->load($filename);
$objWorksheet ->$objPHPExcel->getActiveSheet();
$objWorksheet->$objPHPExcel->setActiveSheetIndex(0);
echo " <form method='post'>
<input type='submit' value='Convert' name='submit'>
</form>";
if(isset($_POST['submit']))
{
$col = 1;
while($rows = mysql_fetch_row($result))
{
$row = 1 ;
foreach($rows as $value )
{
$objPHPExcel ->getActivesheet()->setCellValueByColumnAndRow($col,$row,$value);
$objPHPExcel ->getActivesheet()->getColumnDimension('A')->SetAutoSize(true);
$objPHPExcel ->getActivesheet()->getColumnDimension('B')->SetAutoSize(true);
$objPHPExcel ->getActivesheet()->getColumnDimension('C')->SetAutoSize(true);
$objPHPExcel ->getActivesheet()->getColumnDimension('D')->SetAutoSize(true);
$objPHPExcel ->getActivesheet()->getColumnDimension('E')->SetAutoSize(true);
$row++;











}
$col++;









}









echo "imported";
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(index.xlsx);



?>

当我运行程序 index.php 时出现错误

Catchable fatal error: Object of class PHPExcel_Reader_Excel2007 could not be converted to string in E:\Xampp\htdocs\Example\index.php on line 10

谁能帮我解决这个问题,谢谢!!

最佳答案

正如错误信息所说,在第 10 行

$objReader ->$objReader->load($filename);

应该是

$objPHPExcel=$objReader->load($filename);

关于php - 对象类无法转换为字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30882061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com