Heim >Backend-Entwicklung >PHP-Tutorial >PHPExcel导出问题

PHPExcel导出问题

WBOY
WBOYOriginal
2016-06-23 13:55:43959Durchsuche

在利用PHPExcel类做导出时出现了几个错误 。。求大神指导
第一个问题:Warning: Set the ini directive 'precision' without permission in Classes/PHPExcel/Calculation.php on line 1697
第二个问题:Fatal error: Class 'XMLWriter' not found in Classes/PHPExcel/Shared/XMLWriter.php on line 44


回复讨论(解决方案)

贴出你的相关代码

上回的问题解决了,现在又出现了点新问题。
//引入所需的文件
ob_end_clean();
header("Content-type: text/html;charset=utf-8");
require_once '../../Classes/PHPExcel.php';
require_once '../../Classes/PHPExcel/Writer/Excel2007.php';
require_once '../../Classes/PHPExcel/Writer/Excel5.php';
    include_once '../../Classes/PHPExcel/IOFactory.php';  
//创建一个处理对象的实例
$objExcel = new PHPExcel();

//设置基本属性
$objExcel->getProperties()->setCreator("Kemper_Diao");
$objExcel->getProperties()->setLastModifiedBy("Kemper_Diao");
$objExcel->getProperties()->setTitle("Office 2007 XLSX");
$objExcel->getProperties()->setSubject("Office 2007 XLSX");
$objExcel->getProperties()->setDescription("Document for Office 2007 XLSX, generated using PHP classes.");
$objExcel->getProperties()->setKeywords("office php");
$objExcel->getProperties()->setCategory("Excel2007 Output");

//开始处理数据,索引从0开始
$objExcel->setActiveSheetIndex(0);

//设置表头
$objExcel->getActiveSheet()->mergeCells('A1:K1');
$objExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objExcel->getActiveSheet()->getStyle('A1')->getFont()->setName('Candara');
    $objExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16);
    $objExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$objExcel->getActiveSheet()->setCellValue('A1',"供应商Excel导出表");

//字段名
$objExcel->getActiveSheet()->setCellValue('A2', "ID");
$objExcel->getActiveSheet()->setCellValue('B2', "供应商名称");
$objExcel->getActiveSheet()->setCellValue('C2', "投标项目");
$objExcel->getActiveSheet()->setCellValue('D2', "供应品牌");
$objExcel->getActiveSheet()->setCellValue('E2', "供应商地址");
$objExcel->getActiveSheet()->setCellValue('F2', "供应商资质");
$objExcel->getActiveSheet()->setCellValue('G2', "联系人");
$objExcel->getActiveSheet()->setCellValue('H2', "联系电话");
$objExcel->getActiveSheet()->setCellValue('I2', "其它联系方式");
$objExcel->getActiveSheet()->setCellValue('J2', "合作记录");
$objExcel->getActiveSheet()->setCellValue('K2', "最近业绩");

//供应商导出传递参数操作
$projectID = $_POST['projectid'];

//数据库操作
try{
$pdo_db = new PDO("mysql:host=localhost;dbname=test","RASuser","remote");
$pdo_db->query("set names gbk;");
$result = $pdo_db->query("SELECT * FROM table_suppliercheck WHERE ProjectID=".$projectID);
}catch(PDOException $e){
exit("Connection error:".$e->getMessage());
}
$i = 3;
foreach($result as $row){
//写入内容
$objExcel->getActiveSheet()->setCellValue('A'.$i, iconv("gbk","utf-8","$row[ID]"));
$objExcel->getActiveSheet()->setCellValue('B'.$i, iconv("gbk","utf-8","$row[SupplierName]"));
$objExcel->getActiveSheet()->setCellValue('C'.$i, iconv("gbk","utf-8","$row[ProjectName]"));
$objExcel->getActiveSheet()->setCellValue('D'.$i, iconv("gbk","utf-8","$row[SupplierBrand]"));
$objExcel->getActiveSheet()->setCellValue('E'.$i, iconv("gbk","utf-8","$row[SupplierAddress]"));
$objExcel->getActiveSheet()->setCellValue('F'.$i, iconv("gbk","utf-8","$row[SupplierAptitude]"));
$objExcel->getActiveSheet()->setCellValue('G'.$i, iconv("gbk","utf-8","$row[LinkMan]"));
$objExcel->getActiveSheet()->setCellValue('H'.$i, iconv("gbk","utf-8","$row[LinkPhone]"));
$objExcel->getActiveSheet()->setCellValue('I'.$i, iconv("gbk","utf-8","$row[LinkOther]"));
$objExcel->getActiveSheet()->setCellValue('J'.$i, iconv("gbk","utf-8","$row[LastResult]"));
$objExcel->getActiveSheet()->setCellValue('K'.$i, iconv("gbk","utf-8","$row[CooperationRecord]"));
$i++;
}
//重命名表名
$objExcel->getActiveSheet()->setTitle("供应商");
$objExcel->setActiveSheetIndex(0);

//找出项目名作为表名
$name = $pdo_db->query("SELECT TenderTitle FROM table_tendermessage WHERE ID=".$projectID)->fetch();
$filename = $name['TenderTitle'];

//保存为Excel2003
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename='.$filename.'.xls');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel5');
$objWriter->save('php://output');
exit;

?>
这次提示什么OLE.PHP文件出错是什么回事?

这个问题也解决了,原来是时区的设置问题啊。
网上看了下三种时区设置方法:
1.在页头使用date_default_timezone_set()设置 date_default_timezone_set('PRC'); //东八时区 echo date('Y-m-d H:i:s');
2.在页头使用 ini_set('date.timezone','Asia/Chongqing');
3.修改php.ini。打开php5.ini查找date.timezone 去掉前面的分号修改成为:date.timezone =PRC

第二个问题:Fatal error: Class 'XMLWriter' not found in Classes/PHPExcel/Shared/XMLWriter.php on line 44

第二个问题:Fatal error: Class 'XMLWriter' not found in Classes/PHPExcel/Shared/XMLWriter.php on line 44

哥们 ,,,你这的问题怎么解决的说下哈,,,,

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn