• PHPExcel


     1 /**
     2 * 读取excel
     3 */
     4 public function index()
     5 {
     6 $fileName = 'USCA';
     7 $fileContent = '';
     8 ini_set('memory_limit','3072M'); // 临时设置最大内存占用为3G
     9 set_time_limit(0); // 设置脚本最大执行时间 为0 永不过期
    10 require __DIR__ . '/../Common/Excel/PHPExcel/IOFactory.php';
    11 $uploadfile = "D:/tel/$fileName.xlsx";
    12 $reader = PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档
    13 $PHPExcel = $reader->load($uploadfile); // 文档名称
    14 $sheet = $PHPExcel->getSheet(0);
    15 $highestRow = $sheet->getHighestRow(); // 取得总行数
    16 $highestColumn = $sheet->getHighestColumn(); // 取得总列数
    17 
    18 // 获取一行的数据
    19 for ($row = 1; $row <= $highestRow; $row++){
    20 // Read a row of data into an array
    21 $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
    22 if (count($rowData) >0) {
    23 $rowData = $rowData[0];
    24 foreach ($rowData as $key => $value) {
    25 $str = preg_replace('/[^0-9]+/','',$value);
    26 $str = trim($str);
    27 if ( strlen( $str) > 5) {
    28 // $arr = explode("-",$str);
    29 // if (count($arr) > 1) {
    30 // $str = preg_replace('/[^0-9]+/','',$arr[0]);
    31 // echo "INSERT into t_au(tel) VALUE($str);";
    32 // $str = preg_replace('/[^0-9]+/','',$arr[1]);
    33 // echo "INSERT into t_au(tel) VALUE($str);";
    34 // }else{
    35 $fileContent .= "INSERT into t_$fileName(tel) VALUE($str);";
    36 // }
    37 }
    38 }
    39 }
    40 }
    41 self::addFile($fileName,$fileContent);
    42 }
    43 
    44 public function addFile($fileName,$content)
    45 {
    46 
    47 $myfile = fopen("d:/tel/$fileName.sql", "a") or die("Unable to open file!");//这个是在c盘根目录生成文件
    48 fwrite($myfile, $content);//写入内容,可以写多次哦,不过没啥意义,因为你拼接好字符串,一次写入就行了
    49 fclose($myfile);//关闭该操作
    50 }
    那些个风花雪月的日子 那些铺满星辰的大地 那个被代码包裹的我
  • 相关阅读:
    42.旋转数组的最小元素[Get min value of rotated array]
    洛谷 P3496 [POI2010]GIL-Guilds
    洛谷 P2777 [AHOI2016初中组]自行车比赛
    洛谷 P3184 [USACO16DEC]Counting Haybales数草垛
    洛谷 P2563 [AHOI2001]质数和分解
    洛谷 P2997 [USACO10NOV]旗帜Banner
    洛谷 P2959 [USACO09OCT]悠闲漫步The Leisurely Stroll
    洛谷 P2965 [USACO09NOV]农活比赛The Grand Farm-off
    洛谷 P2548 [AHOI2004]智能探险车
    洛谷 P1041 传染病控制
  • 原文地址:https://www.cnblogs.com/jigong/p/8503776.html
Copyright © 2020-2023  润新知