baozhengrui

导航

jquery文件excel导入导出

导入excel html代码

<input  id="btn-importnum" type="button" >文件导入</input>

<div id="import-box"  style="display: none" >
  <form action="/file/copy/dir" enctype="multipart/form-data" mothod="post">
    <div  class='row">
      <div  id="file" class=" col-sm-8 textfiled" > <div>
      <div class="col-sm-4">
        <input type="button" class="btn btn-sm btn-flat" value="点击选择文件" onclick="document.getElementById('upload').click()">
        <input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" id="upload"  class="upload"  name="upload"  onchange="document.getElementById('file').innerHTML = this.value">
     </div>
    </div>
  </form>
</div>

js代码

$('#btn-importnum').click(function() {
  $('#import-box').css('display': 'block');
  $('#import-box .textfiled').text('请选择扩展名为:.xslx的文件!');
});
$('#import-box').on('click',function(){
  let file = new formData();
  let myFiles = $('#upload')[0].files[0];
  let isCommon = myFiles.name.includes('.xsxl');
  if(!isCommon){
    $.error('请选择正确的文件,后缀’.xslx');
    return;
  }
  
  file.append('uploadfile', $("#upload')[0].files[0]);
  $.ajax({
    url:    ,
    type: 'post';
    data: file,
    contentType: false;
    processData: false;
    success: fucntion(res) {
      if( res.code === 'success'){
        consoel.log(res);
      } else {
        $.error(res.msg);
      }
    }
  });

});

导出excel

<input id="export" >导出文件</input>

js代码

$('#export').unbind().bind('click', function(){
    window.open('url地址接口', '_blank');
});

文件: https://www.haorooms.com/post/input_file_leixing

posted on 2022-05-05 11:05  芮艺  阅读(761)  评论(0编辑  收藏  举报