zoukankan      html  css  js  c++  java
  • thinkphp3.2导出


    public function test()
    {
    set_time_limit(0);
    ini_set('memory_limit', '500M');

    //导入PHPExcel类库,因为PHPExcel没有用命名空间,只能inport导入
    import("Org.Excel.PHPExcel");
    //要导入的xls文件,位于根目录下的Public文件夹
    //创建PHPExcel对象,注意,不能少了
    $PHPExcel = new PHPExcel();

    //如果excel文件后缀名为.xlsx,导入这下类
    //import("Org.Util.PHPExcel.Reader.Excel2007");
    //$PHPReader=new PHPExcel_Reader_Excel2007();

    //如果excel文件后缀名为.xls,导入这个类
    import("Org.Util.PHPExcel.Reader.Excel5");
    $PHPReader = new PHPExcel_Reader_Excel5();


    if ($_POST) {
    $filePath = $_FILES['files']['tmp_name'];
    //$PHPReader = new PHPExcel_Reader_Excel2007();
    $PHPReader = new PHPExcel_Reader_Excel2007();
    if (!$filePath) {
    echo "<h1 style='color: red'> file don't exist! </h1>";
    return;
    }

    if (!$PHPReader->canRead($filePath)) {
    $PHPReader = new PHPExcel_Reader_Excel5();
    if (!$PHPReader->canRead($filePath)) {
    $PHPReader = new PHPExcel_Reader_CSV();
    if (!$PHPReader->canRead($filePath)) {
    echo 'no Excel';
    return;
    }
    }
    }
    $PHPExcel = $PHPReader->load($filePath);
    $currentSheet = $PHPExcel->getSheet(0);

    /*取得一共有多少列*/
    $allColumn = $currentSheet->getHighestColumn();
    /*取得一共有多少行*/
    $allRow = $currentSheet->getHighestRow();

    for($currentRow=2;$currentRow <=$allRow;$currentRow++){
    $trsaction_id = $currentSheet->getCell('A' . $currentRow)->getValue();
              //这里循环得到结果。

    }
    }
    //-----------------------------------------------------------
    $this->display();
    }




    2.页面:
    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <form action="__URL__/test" method="post" enctype="multipart/form-data" >
    导入:<input type="file" name="files" />
    <input type="submit" name="sub" value="提交" />
    </form>
    </body>
    </html>
  • 相关阅读:
    Linq in
    wp7中应用程序清单(WMAppManifest.xml)详细说明
    wp7 给TextBox设置圆角边框
    js 中的闭包
    远程控制PPT软件的帮助
    wp7三种图标大小配置
    在英文版的sqlserver下用LIKE语句不能查询中文
    程序员版《那些年我们一起追过的女孩》(2)
    程序员版《那些年我们一起追过的女孩》(3)
    webbrowser 请求的资源在使用中。 (异常来自 HRESULT:0x800700AA)
  • 原文地址:https://www.cnblogs.com/kobigood/p/4204440.html
Copyright © 2011-2022 走看看