In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces JS how to achieve the export of Excel and CSV files related knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that after reading this JS how to achieve the export of Excel and CSV files article will have a harvest, let's take a look.
1. Js export Excel / * general method of opening and downloading dialog box. The compatibility of * @ param url download address has not been tested. It can also be a blob object. * @ param saveName is required to save the file name. Optional * / function openDownloadDialog (url, saveName) {if (typeof url = = 'object' & & url instanceof Blob) {url = URL.createObjectURL (url) / / create blob address} var aLink = document.createElement ('a'); aLink.href = url; aLink.download = saveName | |'; / HTML5 added attribute that specifies to save the file name without suffix. Note that var event; if (window.MouseEvent) event = new MouseEvent ('click') will not take effect in file:/// mode; else {event = document.createEvent (' MouseEvents') Event.initMouseEvent ('click', true, false, window, 0,0,0,0,0, false, 0, null);} aLink.dispatchEvent (event);} / / convert a sheet to the blob object of the final excel file, and then use URL.createObjectURL to download function sheet2blob (sheet, sheetName) {sheetName = sheetName | |' sheet1'; var workbook = {SheetNames: [sheetName], Sheets: {}} Workbook.Sheets [sheetName] = sheet; / / generate excel configuration item var wopts = {bookType: 'xlsx', / / the file type to be generated: bookSST: false, / / whether to generate Shared String Table. The official explanation is that if generation is enabled, the speed will slow down, but there is better compatibility on lower-version IOS devices type:' binary'} Var wbout = XLSX.write (workbook, wopts); var blob = new Blob ([s2ab (wbout)], {type: "application/octet-stream"}); / / string to ArrayBuffer function s2ab (s) {var buf = new ArrayBuffer (s.length); var view = new Uint8Array (buf); for (var I = 0; I! = s.stories; + + I) view [I] = s.charCodeAt (I) & 0xFF Return buf;} return blob } var exportDataSource = [{name: 'passerby A', phone: '123456789', email: '0003456.com'}, {name: 'cannon fodder B', phone: '123456789' Email: '000girls 123456.com', {name: 'bandits C', phone: '123456789', email:' 000girls 123456.com', {name: 'hooligans' Phone: '123456789, email:' 000mm 123456.com'},] / / Export json data source function exportExcel () {var excelItems = []; for (let I = 0; I < exportDataSource.length) ) {if (exportDataSource [I] .name! = "") {excelItems.push ({"name": exportDataSource.name, "phone": exportDataSource.phone, "mailbox": exportDataSource.email}) / / attribute}} var sheet = XLSX.utils.json_to_sheet (excelItems); openDownloadDialog (sheet2blob (sheet), 'exportdata.xlsx');}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.