Layui에서 Excel 파일을 가져오는 방법

coldplay.xixi
풀어 주다: 2023-01-13 00:40:16
원래의
10796명이 탐색했습니다.

layui에서 Excel 파일을 가져오는 방법: 먼저 [excel.js] 파일을 페이지에 삽입한 다음 헤더 도구 모음의 클릭 이벤트를 들어보세요. 코드는 [title: 'Import Excel', content: $(" #ImportExcel")] .

Layui에서 Excel 파일을 가져오는 방법

이 튜토리얼의 운영 환경: windows7 시스템,layui v2.5.7 버전, DELL G3 컴퓨터 이 방법은 모든 브랜드의 컴퓨터에 적합합니다.

layui에서 Excel 파일을 가져오는 방법:

1. excel.js 파일을 페이지에 추가합니다:

Layui에서 Excel 파일을 가져오는 방법

//引入excel
    layui.config({
        base: 'layui_ext/',
    }).extend({
        excel: 'excel',
    });
로그인 후 복사

2. ImportExcel()의 클릭 이벤트를 듣습니다. 방법:

// 监听头工具栏事件
table.on('toolbar(terminalConfig)', function(obj) {
var layer = layui.layer;
// 添加终端
if(obj.event == 'import'){
layer.open({
type : 1,
shade : false,
area : [ '350px', '260px' ],
title : '导入Excel',
content : $("#ImportExcel"),
cancel : function() {
layer.close();
},
success : function(layero, index) {
ImportExcel();
},
});
}
//导入Excel结束
});
//监听头工具栏事件结束
로그인 후 복사

4. uploadExcel() 방법:

//导入方法
function ImportExcel(){
var $ = layui.jquery
  ,upload = layui.upload;
  var uploadInst = upload.render({
  elem: '#importExcel',
  /*method: 'POST',*/
  url: basePath + 'PowerUser/importPowerUserData.action',
  accept: 'file', //普通文件
  exts: 'xls|excel|xlsx', //导入表格
  auto: false,  //选择文件后不自动上传
  before: function (obj) {
  layer.load(); //上传loading
  },
  choose: function (obj) {// 选择文件回调
  var files = obj.pushFile();
  var fileArr = Object.values(files);// 注意这里的数据需要是数组,所以需要转换一下
  //console.debug(fileArr)
  // 用完就清理掉,避免多次选中相同文件时出现问题
  for (var index in files) {
  if (files.hasOwnProperty(index)) {
  delete files[index];
  }
  }
  uploadExcel(fileArr); // 如果只需要最新选择的文件,可以这样写: uploadExcel([files.pop()])
  },
  error : function(){
  setTimeout(function () {
  layer.msg("上传失败!", {
icon : 1
});
//关闭所有弹出层
layer.closeAll(); //疯狂模式,关闭所有层
  },1000);
  }
  });
}
로그인 후 복사

권장(무료):

layui 튜토리얼

위 내용은 Layui에서 Excel 파일을 가져오는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!