最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于yaf框架和uploadify插件,做的一個(gè)導(dǎo)入excel文件,查看并保存數(shù)據(jù)的功能

 更新時(shí)間:2017年01月24日 14:40:13   作者:暗夜冰封  
本文主要介紹了基于yaf框架和uploadify插件,做的一個(gè)導(dǎo)入excel文件,查看并保存數(shù)據(jù)的功能的思路與方法。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧

思路:

1.首先,頁(yè)面前端,上傳附件,提交給后臺(tái),并帶一個(gè)隨機(jī)性的參數(shù)(可以用時(shí)間戳);

2.后端接收附件,做一系列的邏輯處理,無(wú)誤后,將對(duì)應(yīng)的文件存儲(chǔ)在上傳的目錄下;

3.然后前端,上傳附件成功后,進(jìn)行請(qǐng)求后端,讀取數(shù)據(jù),后端接口對(duì)應(yīng)將附件數(shù)據(jù)讀取出來(lái),前端進(jìn)行顯示(ajax請(qǐng)求);

4.前端展示數(shù)據(jù),用戶對(duì)數(shù)據(jù)檢測(cè)無(wú)誤,點(diǎn)擊保存(ajax請(qǐng)求后端保存代碼的接口),當(dāng)然也可以有選擇性的選擇某些數(shù)據(jù)記錄進(jìn)行保存,樓主這里做的是全部保存(后端處理接口,自動(dòng)過(guò)濾重復(fù)數(shù)據(jù));

5.拿到對(duì)應(yīng)的所需有用數(shù)據(jù)即可, 對(duì)應(yīng)的excel表格,因?yàn)樾枰@取到人員排期數(shù)據(jù),所以樓主是通過(guò)判斷單元格的背景色來(lái)識(shí)別

代碼如下:(關(guān)鍵代碼)

前端 對(duì)應(yīng)html:

<!--導(dǎo)入數(shù)據(jù)操作層-->
<div id="import" class="modal fade bs-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <div class="modal-dialog modal-lg">
 <div class="modal-content">
  <div class="modal-header bg-primary">
  <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
  <h4 class="modal-title">文件導(dǎo)入</h4>
  </div>
  <div class="modal-body">
  <div style="text-align:right;padding:5px">
   <a href="/public/uploadFile/人員資源動(dòng)態(tài)匹配表-模板.xlsx" onclick="javascript:;">
   <img alt="人員資源動(dòng)態(tài)匹配表-模板" src="/public/images/excel.jpg" />
   <span style="font-size:larger;font-weight:200;color:red">人員資源動(dòng)態(tài)匹配表-模板.xlsx</span>
   </a>
  </div>
  <hr/>
  <form id="ffImport" method="post">
   <div title="Excel導(dǎo)入操作" style="padding: 5px" data-options="iconCls:'icon-key'">
   <input class="easyui-validatebox" type="hidden" id="AttachGUID" name="AttachGUID" /> 
   <input id="file_upload" name="file_upload" type="file" multiple="multiple">   
   <a href="javascript:;" class="btn btn-primary" id="btnUpload" onclick="javascript: $('#file_upload').uploadify('upload', '*')">上傳</a>
   <a href="javascript:;" class="btn btn-default" id="btnCancelUpload" onclick="javascript: $('#file_upload').uploadify('cancel', '*')">取消</a>
   <div id="fileQueue" class="fileQueue"></div>
   <br />   
   <hr style="width:98%" />   
   <div id="div_files"></div>
   <br />   
   </div>
  </form>
  <!--數(shù)據(jù)顯示表格-->
  <table id="gridImport" class="table table-striped table-bordered table-hover" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
   <thead id="gridImport_head">
   <tr>
    <th>項(xiàng)目名稱</th>
    <th>項(xiàng)目編號(hào)</th>
    <th>功 能</th>
    <th>人 員</th>
    <th>日 期</th>
   </tr>
   </thead>
   <tbody id="gridImport_body"></tbody>
  </table>
  </div>
  <div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal" id="close_window">關(guān)閉</button>
  <button type="button" class="btn btn-primary" onclick="javascript:SaveImport();">保存</button>
  </div>
 </div>
 </div>
</div>

對(duì)應(yīng)js代碼:

<script type="text/javascript">
 //保存導(dǎo)入的數(shù)據(jù)
 function SaveImport(){
 var guid = $("#AttachGUID").val();
 if (guid == '' || typeof guid == 'undefined') {
  alert('請(qǐng)先上傳excel文件!');
  return false;
 }
 $.ajax({
  url: '/lazy/CheckExcelColumns?type=save&guid=' + guid,
  type: 'get',
  dataType: 'json',
  success: function (data) {
  alert(data.msg);
  $('#close_window').click();
  console.log('報(bào)存數(shù)據(jù)成功!');
  },
  error:function(){
  console.log('出錯(cuò)了!');
  }
 });
 }
 $(function(){
 //導(dǎo)入層的js
 $("#import_schedule").bind('click', function(){
  $("#gridImport_body").html("");
  $("#import").modal("show");
 }); 
 //導(dǎo)入對(duì)應(yīng)的函數(shù)
 $('#file_upload').uploadify({
  'swf': '/public/uploadify/uploadify.swf', //FLash文件路徑
  'buttonText': '瀏 覽',    //按鈕文本
  'uploader': '{{url("lazy/uploadExcel")}}', //后臺(tái)處理程序的路徑
  'queueID': 'fileQueue',    //隊(duì)列的ID
  'queueSizeLimit': 1,    //隊(duì)列最多可上傳文件數(shù)量,默認(rèn)為999
  'auto': false,     //選擇文件后是否自動(dòng)上傳,默認(rèn)為true
  'multi': false,     //是否為多選,默認(rèn)為true
  'removeCompleted': true,   //是否完成后移除序列,默認(rèn)為true
  'fileSizeLimit': '10MB',   //單個(gè)文件大小,0為無(wú)限制,可接受KB,MB,GB等單位的字符串值
  'fileTypeDesc': 'Excel Files',   //文件描述
  'fileTypeExts': '*.xlsx',   //上傳的文件后綴過(guò)濾器
  'onQueueComplete': function (event, data) { //所有隊(duì)列完成后事件
  //業(yè)務(wù)處理代碼
  //提示用戶Excel格式是否正常,如果正常加載數(shù)據(jù)
  var guid = $("#AttachGUID").val();
  $.ajax({
   url: '/lazy/CheckExcelColumns?type=check&guid=' + guid,
   type: 'get',
   dataType: 'json',
   success: function (data) {  
   if (data.status) {
    // InitGrid(); //重新刷新表格數(shù)據(jù)
    $.each(data.rows, function (i, item) {
    var tr = "<tr>";
    tr += "<td>" + item['name']+ "</td>";
    tr += "<td>" + item['identifier'] + "</td>";
    tr += "<td>" + item['subject'] + "</td>"; 
    tr += "<td>" + item['user'] + "</td>";
    tr += "<td>" + item['getExcelTime'] + "</td>";
    tr += "</tr>";
$("#gridImport_body").append(tr);
    });
   }else{
    alert(data.msg);
   }
   }
  });
  },
  'onUploadStart': function (file) {
  InitUpFile(); //重置GUID(每次不同,用時(shí)間戳代替)
  $("#gridImport_body").html("");
  //動(dòng)態(tài)傳參數(shù)
  var guid = $("#AttachGUID").val();
         var salt = 'test' ; //md5加密輔助串
  var token = hex_md5(salt+guid) ; //校驗(yàn)參數(shù)
  $("#file_upload").uploadify(
   "settings", 
   'formData', { 
     'folder': '數(shù)據(jù)導(dǎo)入excel文件', 
     'guid': guid, 
     'token':token,
    }
  ); 
  },
  'onUploadError': function (event, queueId, fileObj, errorObj) {
  alert(errorObj.type + ":" + errorObj.info);
  }
 });
 function InitUpFile(){
  var timestamp = Date.parse(new Date());
  $('#AttachGUID').val(timestamp);
 }
</script>

后端代碼:

//上傳文件處理
 public function uploadExcelAction()
 { 
 $targetFolder = '/public/uploadFile/'; // Relative to the root
     $salt = 'test';
 $verifyToken = md5($test . $_POST['guid']);
 if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
  $tempFile = $_FILES['Filedata']['tmp_name'];
  $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
  $targetFile = rtrim($targetPath,'/') . '/' . $verifyToken.'.xlsx';

  $fileTypes = array('xlsx'); 
  $fileParts = pathinfo($_FILES['Filedata']['name']);
  if (in_array($fileParts['extension'],$fileTypes)) {
  move_uploaded_file($tempFile,$targetFile);
  echo '1';
  } else {
  echo 'Invalid file type.';
  }
 }else{
  echo 'Invalid params.';
 }
 die;
 }

處理excel數(shù)據(jù),就說(shuō)兩個(gè)關(guān)鍵點(diǎn):取單元格的值和背景色

   $objReader  = \PHPExcel_IOFactory::createReader('Excel2007');
   $objPHPExcel = $objReader->load($targetFile);
   $sheet    = $objPHPExcel->getSheet();
   $sheetRows  = $sheet->getHighestDataRow();                      // 取得總行數(shù)
   $sheetColumns = PHPExcel_Cell::columnIndexFromString($sheet->getHighestDataColumn()); //列數(shù)

//讀取單元格
    $value   = $objPHPExcel->getActiveSheet()->getCell($columns[$k] . $j)->getValue(); //獲取每個(gè)單元格的值
    $fillColor = $objPHPExcel->getActiveSheet()->getStyle($columns[$k] . $j)->getFill()->getStartColor()->getARGB(); //背景色

下面附圖:

導(dǎo)入界面:

excel表:

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

  • php加密之discuz內(nèi)容經(jīng)典加密方式實(shí)例詳解

    php加密之discuz內(nèi)容經(jīng)典加密方式實(shí)例詳解

    這篇文章主要介紹了php加密之discuz內(nèi)容經(jīng)典加密方式,結(jié)合具體實(shí)例形式詳細(xì)分析了discuz加密的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2017-02-02
  • 淺談PHP封裝CURL

    淺談PHP封裝CURL

    這篇文章主要介紹了PHP如何封裝CURL,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • php實(shí)現(xiàn)支持中文的文件下載功能示例

    php實(shí)現(xiàn)支持中文的文件下載功能示例

    文件下載功能是我們?cè)诠ぷ髦薪?jīng)常遇到的一個(gè)需求,最近在工作中就又遇到了,下面這篇文章主要給大家介紹了關(guān)于php實(shí)現(xiàn)支持中文的文件下載功能,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下。
    2017-08-08
  • php以fastCGI的方式運(yùn)行時(shí)文件系統(tǒng)權(quán)限問(wèn)題及解決方法

    php以fastCGI的方式運(yùn)行時(shí)文件系統(tǒng)權(quán)限問(wèn)題及解決方法

    在IIS7.0上以FastCGI方式配置好PHP運(yùn)行環(huán)境,測(cè)試可以正常運(yùn)行PHP程序后,將PHP程序部署上去,導(dǎo)入程序原來(lái)的數(shù)據(jù)和配置信息。很快就有問(wèn)題出來(lái)啦下面我們就詳細(xì)記錄下。
    2015-05-05
  • php中使用接口實(shí)現(xiàn)工廠設(shè)計(jì)模式的代碼

    php中使用接口實(shí)現(xiàn)工廠設(shè)計(jì)模式的代碼

    php實(shí)現(xiàn)工廠設(shè)計(jì)模式,使用接口實(shí)現(xiàn),表面上接口沒(méi)有什么用,因?yàn)閜hp是類型自動(dòng)轉(zhuǎn)換的。實(shí)現(xiàn)上使用接口可以約束類的定義,從而實(shí)現(xiàn)一致的訪問(wèn)
    2012-06-06
  • php intval的測(cè)試代碼發(fā)現(xiàn)問(wèn)題

    php intval的測(cè)試代碼發(fā)現(xiàn)問(wèn)題

    測(cè)試php intval函數(shù)的代碼:
    2008-07-07
  • php對(duì)大文件進(jìn)行讀取操作的實(shí)現(xiàn)代碼

    php對(duì)大文件進(jìn)行讀取操作的實(shí)現(xiàn)代碼

    在php中,對(duì)于文件的讀取時(shí),最快捷的方式莫過(guò)于使用一些諸如file、file_get_contents之類的函數(shù),簡(jiǎn)簡(jiǎn)單單的幾行代碼就能很漂亮的完成我們所需要的功能。但當(dāng)所操作的文件是一個(gè)比較大的文件時(shí),這些函數(shù)可能就顯的力不從心, 下面將從一個(gè)需求入手來(lái)說(shuō)明對(duì)于讀取大文件時(shí),常用的操作方法
    2013-01-01
  • hadoop中一些常用的命令介紹

    hadoop中一些常用的命令介紹

    本篇文章是對(duì)hadoop中一些常用的命令進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • PHP中國(guó)際化的字符串排序和比較對(duì)象詳解

    PHP中國(guó)際化的字符串排序和比較對(duì)象詳解

    這篇文章主要給大家介紹了關(guān)于PHP中國(guó)際化字符串排序和比較對(duì)象的相關(guān)資料,這在日常開(kāi)發(fā)中經(jīng)常會(huì)用到,本文通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-08-08
  • php獲取文件擴(kuò)展名的3種方法實(shí)例

    php獲取文件擴(kuò)展名的3種方法實(shí)例

    PHP獲取文件后綴名是PHP學(xué)習(xí)者常見(jiàn)的一種操作,無(wú)論是在面試過(guò)程中還是PHP新手自學(xué)中,下面這篇文章主要給大家介紹了關(guān)于php獲取文件擴(kuò)展名的3種方法,需要的朋友可以參考下
    2023-01-01

最新評(píng)論

阳原县| 沙湾县| 宁化县| 江华| 景泰县| 江华| 惠东县| 武强县| 津市市| 剑川县| 苗栗市| 宁晋县| 青川县| 邛崃市| 金沙县| 武川县| 衡东县| 淳化县| 大足县| 镇宁| 桦南县| 建湖县| 华容县| 元朗区| 惠来县| 乌拉特前旗| 托克托县| 铜陵市| 修文县| 长宁县| 武平县| 溧阳市| 德庆县| 绍兴县| 青浦区| 青州市| 将乐县| 呼伦贝尔市| 黄平县| 河曲县| 玉山县|