zoukankan      html  css  js  c++  java
  • 导出csv文件(使用a标签)

    https://blog.csdn.net/oscar999/article/details/16342699
     
    productsCSV(e) {
            const { download } = this.state;
    		// 表头
    		const thead = '时间,Key,服务接口,调用量
    ';
    
    		// 表格数据初始值
    		let str = thead;
    
    		// 表格内数据格式化
    		function tbCell (cell) {
    			return Array.isArray(cell) ? cell.join(',') : ''
    		}
    
    		// // let str = thead+"值1,值2,值3,值4,值5,值6,值7
    值1,值2,值3,值4,值5,值6,值7
    值1,值2,值3,值4,值5,值6,值7
    ";
    		download.map(item => {
    			str += `${item.time},${this.props.licenseKey},${item.uri},${item.dps}
    `
    		})
    
    		str =  encodeURIComponent(str);
    		e.target.href = "data:text/csv;charset=utf-8,ufeff"+str; // 加ufeff保证中文不乱码
    		// e.target.click();
    	},
    
    


                  <Button type="primary" size="small" style={{ marginLeft: "10px",display:'inline-block' }} ref='download' > <a onClick={(e)=>this.productsCSV(e)} download="海外正确流量-海外.csv" href="#">导出文件</a> </Button>

      

  • 相关阅读:
    ACM spiral grid
    ACM 数独
    Codeforces Round #242 (Div. 2) A. Squats
    Codeforces Round #242 (Div. 2) B. Megacity
    Codeforces Round #242 (Div. 2) C. Magic Formulas
    Coder-Strike 2014
    Coder-Strike 2014
    Coder-Strike 2014
    ACM Same binary weight
    C puzzles详解【13-15题】
  • 原文地址:https://www.cnblogs.com/kaiqinzhang/p/11910770.html
Copyright © 2011-2022 走看看