我将尝试在我的index.xlsx工作表中导入数据库值,因此我编写了一个使用phpExcel进行导入的代码。
Index.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);
?>
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
有人可以帮我吗?谢谢!
这是关于IT技术的问题。