Home > Web Front-end > JS Tutorial > body text

js implements dynamic export string method

小云云
Release: 2018-03-20 17:13:54
Original
1149 people have browsed it

This article mainly shares with you the method of dynamically exporting strings in js. I hope it can help you.

Example 1: Use blob to dynamically export strings to excel:








Document


学生信息
名字 性别 年龄 班级
小明 19 1班
小黄 20 2班
老王 29 3班
${oHtml} `; var debug = { hello: "world" }; // var blob = new Blob([JSON.stringify(debug, null, 2)], // { type: 'application/json' }); var excelBlob = new Blob([excelHtml], { type: 'application/vnd.ms-excel' }) // 创建一个a标签 var oA = document.createElement('a'); // 利用URL.createObjectURL()方法为a元素生成blob URL oA.href = URL.createObjectURL(excelBlob); // 给文件命名 oA.download = '学生名单.xls'; // 模拟点击 oA.click();
Copy after login

Example 2:

Copy after login

Note: DOM.click(); is to simulate a dom click event .

Related recommendations:

Common properties and methods of strings in JS

Detailed explanation of common string operation methods in JavaScript

How to use JavaScript strings

The above is the detailed content of js implements dynamic export string method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!