php write excel
2015-12-21 17:05
567 查看
/** * 写excel方法 */ function writeExcel($tabArr, $dataArr,$path) { require_once CODE_BASE2 . '/util/phpexcel/PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objSheet = $objPHPExcel->setActiveSheetIndex(0); //写表头 $index = 'A'; foreach ($tabArr as $value) { $objSheet->setCellValue($index .'1', $value); $index++; } //写数据 $i = 2; foreach ($dataArr as $key => $line) { $index = 'A'; foreach($line as $val){ $objSheet->setCellValue($index.$i, $val); $index++; } $i++; } $objWriter = PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007'); $objWriter->save($path); }
//php 读取excel function readExcel($path){ require_once CODE_BASE2 . '/util/phpexcel/PHPExcel.php'; $reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-2003工作簿) $PHPExcel = $reader->load($path); // 载入excel文件 $sheet = $PHPExcel->getSheet(0); // 读取第一個工作表 $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumm = $sheet->getHighestColumn(); // 取得总列数 $res=array(); /** 循环读取每个单元格的数据 */ for ($row = 1; $row <= $highestRow; $row++){//行数是以第1行开始 for ($column = 'A'; $column <= $highestColumm; $column++) {//列数是以A列开始 $res[$row-1][] = $sheet->getCell($column.$row)->getValue(); } } return $res; }
相关文章推荐
- PHP商品秒杀计时实现(解决大流量方案)
- 第四十九天:php-7.0编译模块的出错
- PHP(四)运算符、表达式和语句
- phpmyadmin运行远程连接
- php 中间层
- Yocto开发笔记之《工具使用:TFTP & NFS & SSH》(QQ交流群:519230208)
- 学习PHP到底要学习哪些东西?
- FTP无法用Explorer登陆
- 资料下载 ftp://download.atstudy.com/
- 反射调用private方法实践(php、java)
- pureftp部署
- php中ob_start()系列函数的使用
- yii日志功能详解
- PHP连接数据库错误:Can't connect to MySQL server on '127.0.0.1' (13)2003
- laravel5中对pipeline的理解
- Windows搭建SMTP邮件服务器
- PHP mail详细示例
- php获取服务器端ip地址
- php curl
- 如何知道tp和panel是哪个厂商