我用的是thinkPHP3.2 下载了phpexcel 放在 tp3.2\ThinkPHP\Library\Vendor\PHPExcel目录下
我用的是thinkPHP3.2下载了phpexcel放在tp3.2\ThinkPHP\Library\Vendor\PHPExcel目录下为什么我在代码里$obj=new...
我用的是thinkPHP3.2 下载了phpexcel 放在 tp3.2\ThinkPHP\Library\Vendor\PHPExcel目录下 为什么我在代码里$obj = new \PHPExcel();报错找不到PHPExcel 这个类呢?
实例化之前已加载
import("Vendor.PHPExcel.PHPExcel"); 展开
实例化之前已加载
import("Vendor.PHPExcel.PHPExcel"); 展开
展开全部
用Vendor();
//参考:写入excel
vendor ( "PHPExcel.PHPExcel" );
$objPHPExcel = new \PHPExcel();
$admin_info = session('user_auth');
$objPHPExcel->getProperties()->setCreator($admin_info['username'])->setLastModifiedBy($admin_info['username'])->setTitle("商机信息导出");
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(9);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(45);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
// 字体和样式
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10)->setName('微软雅黑')->getColor()->setRGB('252525');
//设置excel列名
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1','ID');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B1','标题');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C1','供求');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D1','分类');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('E1','新旧程度');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('F1','产品所在地(省)');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('G1','产品所在地(市)');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('H1','产品所在地(区)');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('I1','联系人');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('J1','联系人电话');
//把数据循环写入excel中
foreach($data as $key => $value){
$key+=2;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$key,$value['id']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$key,$value['title']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$key,$sup_array[$value['supbuy']].'信息');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D'.$key,$value['class_name'].'('.$value['class'].')');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('E'.$key,$new_and_old[$value['new_old']]);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('F'.$key,$value['trand_province_name'].'('.$value['trand_province'].')');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('G'.$key,$value['trand_city_name'].'('.$value['trand_city'].')');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('H'.$key,$value['trand_area_name'].'('.$value['trand_area'].')');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('I'.$key,$value['atten_name']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('J'.$key,$value['atten_mobile']);
}
/excel保存在根目录下 如要导出文件,以下改为注释代码
$objPHPExcel->getActiveSheet() -> setTitle('SetExcelName');
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$name = md5(NOW_TIME);
$file = 'Data/exprot/'.$name.'.xlsx';
$objWriter->save('./Data/exprot/'.$name.'.xlsx');
$this->success('导出成功',think_encrypt($file),true);
//参考:写入excel
vendor ( "PHPExcel.PHPExcel" );
$objPHPExcel = new \PHPExcel();
$admin_info = session('user_auth');
$objPHPExcel->getProperties()->setCreator($admin_info['username'])->setLastModifiedBy($admin_info['username'])->setTitle("商机信息导出");
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(9);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(45);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
// 字体和样式
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10)->setName('微软雅黑')->getColor()->setRGB('252525');
//设置excel列名
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1','ID');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B1','标题');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C1','供求');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D1','分类');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('E1','新旧程度');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('F1','产品所在地(省)');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('G1','产品所在地(市)');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('H1','产品所在地(区)');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('I1','联系人');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('J1','联系人电话');
//把数据循环写入excel中
foreach($data as $key => $value){
$key+=2;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$key,$value['id']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$key,$value['title']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$key,$sup_array[$value['supbuy']].'信息');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D'.$key,$value['class_name'].'('.$value['class'].')');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('E'.$key,$new_and_old[$value['new_old']]);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('F'.$key,$value['trand_province_name'].'('.$value['trand_province'].')');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('G'.$key,$value['trand_city_name'].'('.$value['trand_city'].')');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('H'.$key,$value['trand_area_name'].'('.$value['trand_area'].')');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('I'.$key,$value['atten_name']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('J'.$key,$value['atten_mobile']);
}
/excel保存在根目录下 如要导出文件,以下改为注释代码
$objPHPExcel->getActiveSheet() -> setTitle('SetExcelName');
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$name = md5(NOW_TIME);
$file = 'Data/exprot/'.$name.'.xlsx';
$objWriter->save('./Data/exprot/'.$name.'.xlsx');
$this->success('导出成功',think_encrypt($file),true);
展开全部
vendor("PHPExcel.PHPExcel");
$obj = new PHPExcel();
$obj = new PHPExcel();
追问
其实import不是也可以导入吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Vendor('PHPExcel.PHPExcel','','.php');
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |