
function exportToExcel(){
	//要导出的json数据
	const jsonData = [
	{
	  name:'路人甲',
	  phone:'123456789',
	  email:'000@123456.com'
	},
	{
	  name:'炮灰乙',
	  phone:'123456789',
	  email:'000@123456.com'
	},
	{
	  name:'土匪丙',
	  phone:'123456789',
	  email:'000@123456.com'
	},
	{
	  name:'流氓丁',
	  phone:'123456789',
	  email:'000@123456.com'
	},
	]
	//列标题，逗号隔开，每一个逗号就是隔开一个单元格
	let str = `姓名,电话,邮箱\n`;
	//增加\t为了不让表格显示科学计数法或者其他格式
	for(let i = 0 ; i < jsonData.length ; i++ ){
	for(let item in jsonData[i]){
		str+=`${jsonData[i][item] + '\t'},`;     
	}
	str+='\n';
	}
	//encodeURIComponent解决中文乱码
	let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
	//通过创建a标签实现
	let link = document.createElement("a");
	link.href = uri;
	//对下载的文件命名
	link.download =  "json数据表.csv";
	document.body.appendChild(link);
	link.click();
	document.body.removeChild(link);
}

function downloadUrl(filename, url) {
  var element = document.createElement('a');
  element.setAttribute('href', url);
  element.setAttribute('download', filename);
 
  element.style.display = 'none';
  document.body.appendChild(element);
 
  element.click();
 
  document.body.removeChild(element);
}
 
function DownloadContent(filename,content) {
   var eleLink = document.createElement('a');
   eleLink.download = filename;
   eleLink.style.display = 'none';
   // 字符内容转变成blob地址
   var blob = new Blob([content]);
   eleLink.href = URL.createObjectURL(blob);
   // 触发点击
   document.body.appendChild(eleLink);
   eleLink.click();
   // 然后移除
   document.body.removeChild(eleLink);
};

function fakeClick(obj) {
  var ev = document.createEvent("MouseEvents");
  ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  obj.dispatchEvent(ev);
}

function exportRaw(name, data) {
  var urlObject = window.URL || window.webkitURL || window;
  var export_blob = new Blob([data]);
  var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
  save_link.href = urlObject.createObjectURL(export_blob);
  save_link.download = name;
  fakeClick(save_link);
}
		