LixiPHP - 专注于建设高品质网站! blog.lixiphp.com

LixiPHP - 专注于建设高品质网站!

站名: LixiPHP - 专注于建设高品质网站!

网址: http://blog.lixiphp.com

目录: 电脑网络 > 软件编程

PR:

Alexa: 523,895

备案号: 晋ICP备09010560号

服务器IP: 116.255.226.18   河南省郑州市 景安计算机网络技术有限公司

描述: LixiPHP博客是一个专业网站建设的IT博客!覆盖网站前端到后台,开发到运营。致力于高品质、高质量的网站建设!分享建设高品质、高性能、高质量网站的技术、运营、管理等原创文章!根据各种开源系统给出网站

查询: [ 网站综合查询 | PR查询 | Alexa排名 | 同IP网站 ]

详细介绍

Skip to contentSkip to menuLixiPHP专注于建设高品质网站! 搜索 最新文章关于博客
function excel_upload_form_submit($form, &$form_state) {
  set_time_limit(0);
  $timestamp = time();
  // 确保Excel文件上传了
  if ($file = file_save_upload(‘file’)) {
    $row = 0; //解析行数
    $paseRows = 0; //跳过行数 没有值的行
    $insertRows = 0; //插入行数
    $table = array(
      ‘dbfield1′,
      ‘dbfield2′,
      ‘dbfield3,
      ‘dbfield4′,
      ‘dbfield5′,
      …
      ‘dbfieldn’,
    );
    require("sites/all/libraries/PHPExcel/PHPExcel/IOFactory.php");
    if(($handle = fopen ( $file->filepath, "r" )) !== FALSE) {
      $PHPExcel = new PHPExcel ();
      $PHPReader = new PHPExcel_Reader_Excel2007 ();
      if (! $PHPReader->canRead ( $file->filepath )) {
        $PHPReader = new PHPExcel_Reader_Excel5 ();
        if (! $PHPReader->canRead ( $file->filepath )) {
          echo ‘no Excel’;
          return;
        }
      }
      $PHPExcel = $PHPReader->load ( $file->filepath );
      $currentSheet = $PHPExcel->getSheet ( 0 );
      /**取得一共有多少列*/
      $allColumn = $currentSheet->getHighestColumn();
      //取得共有多少列,若不使用此静态方法,获得的$col是文件列的最大的英文大写字母
      $col = PHPExcel_Cell::columnIndexFromString($currentSheet->getHighestColumn());
      /**取得一共有多少行*/
      $allRow = $currentSheet->getHighestRow();
      //循环读取每个单元格的内容。注意行从1开始,列从A开始
      for($rowIndex = 2; $rowIndex <= $allRow; $rowIndex++) {
        $token_db = $row_db = $field = array();
        $i = 0;
        $query = ”;
        for($colIndex = 0; $colIndex <= $col; $colIndex++) {
          //$addr = $colIndex.$rowIndex;
          //$cell = $currentSheet->getCell($addr)->getValue();
          $cell = $currentSheet->getCellByCo

猜你喜欢