Chinaunix首页 | 论坛 | 博客
  • 博客访问: 144198
  • 博文数量: 21
  • 博客积分: 709
  • 博客等级: 上士
  • 技术积分: 255
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-19 22:23
个人简介

凤飞飞

文章分类

全部博文(21)

文章存档

2012年(3)

2011年(17)

2005年(1)

我的朋友

分类: 系统运维

2012-03-08 16:04:21

  1. class Main extends CI_Controller{

  2.     function __construct(){
  3.         //必需先覆盖父类的析构函数
  4.          parent::__construct();
  5.         //加载session
  6.         $this->load->library('session');
  7.         //加载加密类
  8.         $this->load->library('encrypt');
  9.     }
  10.     function index(){
  11.         $Vdate=array("title"=>"xx系统");
  12.         //图片tmp path
  13.         $TmpPath="images/tmp_execl/";
  14.         //加载Execl读取自定义类
  15.         $this->load->library('phpexecl/PHPExcel');
  16.         $objReader = PHPExcel_IOFactory::createReader('Excel5');
  17.         //$objReader->setReadDataOnly(true);
  18.         $objPHPExcel = $objReader->load('images/tmp/test.xls');
  19.         $currentSheet = $objPHPExcel->getActiveSheet();
  20.         //先处理图片
  21.         $AllImages= $currentSheet->getDrawingCollection();
  22.         $ArrayTmp="";
  23.         foreach($AllImages as $drawing){
  24.             if($drawing instanceof PHPExcel_Worksheet_MemoryDrawing){
  25.                 $image = $drawing->getImageResource();
  26.                 $filename=$drawing->getIndexedFilename();
  27.                 $XY=$drawing->getCoordinates();
  28.                 //把图片存起来
  29.                 imagepng($image, $TmpPath.$filename);
  30.                 //把图片的单元格的值设置为图片名称
  31.                 $cell = $currentSheet->getCell($XY);
  32.                 $cell->setValue($filename);
  33.             }
  34.         }
  35.         //处理每个单元格的数据
  36.         $allColumn = $currentSheet->getHighestColumn();
  37.         $allRow = $currentSheet->getHighestRow();
  38.         for($currentRow = 1;$currentRow<=$allRow;$currentRow++){
  39.             for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){
  40.                 $address = $currentColumn.$currentRow;
  41.                 //获取单元格数据
  42.                 $CellDate=$currentSheet->getCell($address)->getValue();
  43.                 //echo $currentSheet->getCell($address)->getValue()."\t";
  44.                 //写入数据库.....
  45.                 //.....
  46.             }
  47.             //echo "\n";
  48.         }
  49.         $this->load->view('main_view',$Vdate);
  50.     }
  51.         
  52. }
阅读(4608) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~