0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

在页面中,添加导出功能。

Last updated at Posted at 2019-06-23
  • 1、外部插件导入到自己的项目中
    文件名字是 : xlsx.full.min.js
    方法project 下 js的文件夹里。

  • 2、在页面中引入外部的插件

//localhost:8080/p_StudentManagerSystem/js/xlsx.full.min.js">
  • 3、在页面中添加一个按钮来完成导出功能
<div style="float: left;">

<a id="exportData" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true">导出</a>

</div>
  • 4、添加插件提供的代码到js块中,放在js代码中,给按钮做设置的地方。
//导出表格方法
		$("#exportData").click(function(){
			var data_rows = $('#dataList').datagrid("getData").rows;//获取当前页面的数组数据
			
			var ws =  XLSX.utils.json_to_sheet(data_rows);//封装入表格
			doit(ws, " 企业数据-");//导出,下载数据  
		});
	  	
		 //下载数据 	ws 表格,title 要保存的名字  
	     function doit(ws,title,fn, dl) {
	    	 var wb  = XLSX.utils.book_new();
	          XLSX.utils.book_append_sheet(wb, ws, title);
	          return dl ?
	              XLSX.write(wb, {bookType:type, bookSST:true, type: 'base64'}) :
	              XLSX.writeFile(wb, fn || (title+'.' + ('xlsx' || 'xls')));//哪种格式放前面默认导出哪种
	    }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?