初始提交:实习工作日志系统(设计方案 + Vue3 应用 + Electron 打包)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
function csvCell(v: string | number | null | undefined): string {
|
||||
const s = v == null ? '' : String(v)
|
||||
return '"' + s.replace(/"/g, '""') + '"'
|
||||
}
|
||||
|
||||
// 导出 UTF-8 BOM 的 CSV,Excel 可直接打开中文不乱码
|
||||
export function downloadCsv(filename: string, rows: (string | number | null | undefined)[][]): void {
|
||||
const content = rows.map(r => r.map(csvCell).join(',')).join('\r\n')
|
||||
const blob = new Blob(['\ufeff' + content], { type: 'text/csv;charset=utf-8' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = filename
|
||||
a.click()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
Reference in New Issue
Block a user