/*
     * 读取Excel文件
     * */
    require_once (dirname(dirname(dirname(__FILE__))).'/PHPExcel/PHPExcel.php');//Classes为根目录
    require_once (dirname(dirname(dirname(__FILE__))).'/PHPExcel/PHPExcel/IOFactory.php');
    require_once (dirname(dirname(dirname(__FILE__)))).'/PHPExcel/PHPExcel/Reader/Excel5.php';
    
    $newfile=md5($_FILES['filename']['name']);
    $do = copy($_FILES['filename']['tmp_name'],dirname(dirname(dirname(__FILE__))).'/PHPExcel/cache/'.$newfile.'.xls');
    
    $file_url=dirname(dirname(dirname(__FILE__))).'/PHPExcel/cache/'.$newfile.'.xls';    
    
    $objReader=PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
    $objPHPExcel=$objReader->load($file_url);//$file_url即Excel文件的路径
    $sheet=$objPHPExcel->getSheet(0);//获取第一个工作表
    $highestRow=$sheet->getHighestRow();//取得总行数
    $highestColumn=$sheet->getHighestColumn(); //取得总列数
    //循环读取excel文件,读取一条,插入一条
    for($j=2;$j<=$highestRow;$j++){//从第一行开始读取数据
        $str='';
        for($k='A';$k<=$highestColumn;$k++){            //从A列读取数据
            //这种方法简单,但有不妥,以'\\'合并为数组,再分割\\为字段值插入到数据库,实测在excel中,如果某单元格的值包含了\\导入的数据会为空
            $str.=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue().'\\';//读取单元格
        }
        //explode:函数把字符串分割为数组。
        $strs=explode("\\",$str);

/*
     * 进行写入数据库操作
    * */    
    
    $table = new Table('customer_info', $_POST);
    $table->SetStrip('location', 'other');
    $table->input_time = time();
    $table->input_admin_id = $login_user_id;
    
    $fieldArr = array(
            'sign_name', 'sign_time', 'floor_num',
            'room_num', 'built_cover', 'suite_cover', 'pay_type',
            'amount_price', 'c_name', 'c_sex', 'identity_id', 'c_position', 'c_email',
            'c_tel', 'c_pscode', 'c_addr', 'company_name',
            'company_tel', 'company_web', 'company_business','account_name',
            'bank_name','bank_account'
    );
    //将值赋予对象
//     for($i=0;$i<count($fieldArr);$i++){
//     $table->$fieldArr[$i]=$strs[$i];
//     }
    $table->sign_name=$strs[0];
    $table->sign_time=$strs[1];
    $table->floor_num=$strs[2];
    $table->room_num=$strs[3];
    $table->built_cover=$strs[4];
    $table->suite_cover=$strs[5];
    $table->pay_type=$strs[6];
    $table->amount_price=$strs[7];
    $table->c_name=$strs[8];
    $table->c_sex=$strs[9];
    $table->identity_id=$strs[10];
    $table->c_position=$strs[11];
    $table->c_email=$strs[12];
    $table->c_tel=$strs[13];
    $table->company_web=$strs[14];
    $table->company_business=$strs[15];
    $table->account_name=$strs[16];
    $table->bank_name=$strs[17];
    $table->bank_account=$strs[18];

$table->insert(array(
        'input_time', 'input_admin_id', 'sign_name', 'sign_time', 'floor_num',
        'room_num', 'built_cover', 'suite_cover', 'pay_type',
        'amount_price', 'c_name', 'c_sex', 'identity_id', 'c_position', 'c_email',
        'c_tel', 'c_pscode', 'c_addr', 'company_name',
        'company_tel', 'company_web', 'company_business','account_name',
        'bank_name','bank_account'
    ));
    
    }
    unlink($file_url);//删除excel文件

PHP读取Excel文件(PHPExcel)的更多相关文章

  1. 利用PHPExcel读取excel文件

    $filePath = "7788.xls"; $PHPExcel = new PHPExcel(); $PHPReader = new PHPExcel_Reader_Excel ...

  2. PhpSpreadsheet如何读取excel文件

    PhpSpreadsheet如何读取excel文件 一.总结 一句话总结:万能的百度,直接搜代码就好,绝对有,毕竟github上面4000+的关注,说明很多人用了这个,使用照着demo倒是异常简单 二 ...

  3. PHPExcel读取Excel文件的实现代码

    <?php require_once 'PHPExcel.php'; /**对excel里的日期进行格式转化*/ function GetData($val){ $jd = GregorianT ...

  4. PHPExcel读取excel文件示例

    PHPExcel读取excel文件示例PHPExcel最新版官方下载网址:http://phpexcel.codeplex.com/PHPExcel是一个非常方便生成Excel格式文件的类,官方下载包 ...

  5. (实用篇)PHPExcel读取Excel文件的实现代码

    用PHPExcel读取Excel 2007 或者Excel2003文件,需要的朋友,可以参考下. 涉及知识点:  php对excel文件进行循环读取 php对字符进行ascii编码转化,将字符转为十进 ...

  6. PHP使用phpexcel读取excel文件

    PHP读取excel文件 require("Classes/PHPExcel.php"); require("Classes/PHPExcel/IOFactory.php ...

  7. php phpexcel 读取excel文件数据

    public function readExcel(){ $allPath = '/home/examine\video/list.xls'; \think\Loader::import('exten ...

  8. PHP读取Excel文件内容

    PHP读取Excel文件内容   项目需要读取Excel的内容,从百度搜索了下,主要有两个选择,第一个是PHPExcelReader,另外一个是PHPExcel.   PHPExcelReader比较 ...

  9. php读取excel文件 更新修改excel

    php读取excel文件示例,还有更新修改功能. 代码: //模板存放目录 $dir = $DOCUMENT_ROOT.'/backoffice/admin/oemcheck/'; $template ...

随机推荐

  1. 笔记整理--Linux编程

    linux c编程open() read() write()函数的使用方法及实例 | 奶牛博客 - Google Chrome (2013/8/31 17:56:10) 今天把文件IO操作的一些东东整 ...

  2. js的阻塞特性

    JS具有阻塞特性,当浏览器在执行js代码时,不能同时做其它事情,即<script>每次出现都会让页面等待脚本的解析和执行(不论JS是内嵌的还是外链的),JS代码执行完成后,才继续渲染页面. ...

  3. access restriction

    一.既然存在访问规则,那么修改访问规则即可.打开项目的Build Path Configuration页面,打开报错的JAR包,选中Access rules条目,选择右侧的编辑按钮,添加一个访问规则即 ...

  4. java删除文件夹 Java中实现复制文件或文件夹

    删除文件夹 import java.io.File; public class DeleteDir { /** * @param args */ public static void main(Str ...

  5. zf-监察系统的左侧菜单树的表

    Sys_Right 这个表

  6. angular 实现modal windows效果(即模态窗口,半透明的遮罩层),以及bootstrap(css,components,js)的初步学习

    废话不说,直接上代码.可直接看效果,对着分析..今天算是bootstrap 入门了,开心.. 突然居然很多事情就是那样,不要太多的畏惧,迈出第一步其实就成功了一半了. <html ng-app= ...

  7. centos 7.1搭建docker本地私有仓库返回500错误

    之前有一篇写到在ubuntu14.04系统上安装私有仓库,遇到了两个问题,本次在centos7上遇到了另外一个问题. 安装完仓库并运行registry镜像之后发现push和pull操作都会返回一个50 ...

  8. 一个combineInputformat

    mark import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import org.apa ...

  9. Chapter 1 First Sight——5

    "He's in a wheelchair now," Charlie continued when I didn't respond, 他现在在轮椅上了,没等我回答查理斯就继续说 ...

  10. C语言常见命名规范

    C语言常见命名规范   1 常见命名规则 比较著名的命名规则首推匈牙利命名法,这种命名方法是由Microsoft程序员查尔斯·西蒙尼(Charles Simonyi) 提出的.其主要思想是“在变量和函 ...