首页 > 其他分享 >Export2Zip.js

Export2Zip.js

时间:2022-11-12 09:11:07浏览次数:45  
标签:Export2Zip const name zip js file txtData txt

/* eslint-disable */
import { saveAs } from 'file-saver'
import JSZip from 'jszip'

export function export_txt_to_zip(th, jsonData, txtName, zipName) {
  const zip = new JSZip()
  const txt_name = txtName || 'file'
  const zip_name = zipName || 'file'
  const data = jsonData
  let txtData = `${th}\r\n`
  data.forEach((row) => {
    let tempStr = ''
    tempStr = row.toString()
    txtData += `${tempStr}\r\n`
  })
  zip.file(`${txt_name}.txt`, txtData)
  zip.generateAsync({
    type: "blob"
  }).then((blob) => {
    saveAs(blob, `${zip_name}.zip`)
  }, (err) => {
    alert('导出失败')
  })
}

标签:Export2Zip,const,name,zip,js,file,txtData,txt
From: https://www.cnblogs.com/strundent/p/16882682.html

相关文章