【发布时间】:2019-04-29 14:18:47
【问题描述】:
我必须通过 csv 文件导出表格。
csv 文件数据来自服务器的 Blob 类型。
Blob {size: 2067, type: "text/csv"}
async exportDocumentsByCsv() {
this.commonStore.setLoading(true)
try {
const result = await DocumentSearchActions.exportDocumentsByCsv({
searchOption: this.documentSearchStore.searchOption
})
// first
// const blob = new Blob([result.body], { type: 'text/csv;charset=utf-8;' })
// second
// const blob = new Blob([`\ufeff${result.body}`], { type: 'text/csv;charset=utf-8;' })
const blob = result.body
console.log('result.body', result.body)
const fileName = `document - search - result.csv`
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
// for IE
window.navigator.msSaveOrOpenBlob(blob, fileName)
} else {
FileSaver.saveAs(blob, fileName)
}
this.commonStore.setLoading(false)
} catch (err) {
alert(err.errorMessage)
this.commonStore.setLoading(false)
}
}
由于我的语言,我必须设置 utf-8 否则。
我试图解决这个问题,但我不知道如何解决它。
我通过使用\ufeff 搜索修复了这个问题,但是当我尝试像这样使用它时
第二种方式,它对我不起作用。
| [object | Blob] |
【问题讨论】:
-
@SudhirOjha 这对我不起作用。来自服务器的响应数据是 Blob 类型而不是对象。
标签: javascript blob