feature[Excel]: support bookType option
This commit is contained in:
parent
dc84e7b9fb
commit
ff1fa4ed91
|
@ -149,7 +149,8 @@ export function export_json_to_excel({
|
||||||
header,
|
header,
|
||||||
data,
|
data,
|
||||||
filename,
|
filename,
|
||||||
autoWidth = true
|
autoWidth = true,
|
||||||
|
bookType= 'xlsx'
|
||||||
} = {}) {
|
} = {}) {
|
||||||
/* original data */
|
/* original data */
|
||||||
filename = filename || 'excel-list'
|
filename = filename || 'excel-list'
|
||||||
|
@ -196,11 +197,11 @@ export function export_json_to_excel({
|
||||||
wb.Sheets[ws_name] = ws;
|
wb.Sheets[ws_name] = ws;
|
||||||
|
|
||||||
var wbout = XLSX.write(wb, {
|
var wbout = XLSX.write(wb, {
|
||||||
bookType: 'xlsx',
|
bookType: bookType,
|
||||||
bookSST: false,
|
bookSST: false,
|
||||||
type: 'binary'
|
type: 'binary'
|
||||||
});
|
});
|
||||||
saveAs(new Blob([s2ab(wbout)], {
|
saveAs(new Blob([s2ab(wbout)], {
|
||||||
type: "application/octet-stream"
|
type: "application/octet-stream"
|
||||||
}), filename + ".xlsx");
|
}), `${filename}.${bookType}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<template>
|
||||||
|
<div style="display:inline-block;">
|
||||||
|
<label class="radio-label">Cell Auto-Width: </label>
|
||||||
|
<el-radio-group v-model="autoWidth">
|
||||||
|
<el-radio :label="true" border>True</el-radio>
|
||||||
|
<el-radio :label="false" border>False</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
autoWidth: {
|
||||||
|
get() {
|
||||||
|
return this.value
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
this.$emit('input', val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -0,0 +1,38 @@
|
||||||
|
<template>
|
||||||
|
<div style="display:inline-block;">
|
||||||
|
<label class="radio-label">Book Type: </label>
|
||||||
|
<el-select v-model="bookType" style="width:120px;" >
|
||||||
|
<el-option
|
||||||
|
v-for="item in options"
|
||||||
|
:key="item"
|
||||||
|
:label="item"
|
||||||
|
:value="item"/>
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: String,
|
||||||
|
default: 'xlsx'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
options: ['xlsx', 'csv', 'txt']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
bookType: {
|
||||||
|
get() {
|
||||||
|
return this.value
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
this.$emit('input', val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -0,0 +1,28 @@
|
||||||
|
<template>
|
||||||
|
<div style="display:inline-block;">
|
||||||
|
<!-- $t is vue-i18n global function to translate lang -->
|
||||||
|
<label class="radio-label" style="padding-left:0;">Filename: </label>
|
||||||
|
<el-input :placeholder="$t('excel.placeholder')" v-model="filename" style="width:340px;" prefix-icon="el-icon-document"/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
filename: {
|
||||||
|
get() {
|
||||||
|
return this.value
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
this.$emit('input', val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -2,14 +2,12 @@
|
||||||
<!-- $t is vue-i18n global function to translate lang -->
|
<!-- $t is vue-i18n global function to translate lang -->
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
|
|
||||||
<label class="radio-label" style="padding-left:0;">Filename: </label>
|
<div>
|
||||||
<el-input :placeholder="$t('excel.placeholder')" v-model="filename" style="width:340px;" prefix-icon="el-icon-document"/>
|
<FilenameOption v-model="filename" />
|
||||||
<label class="radio-label">Cell Auto-Width: </label>
|
<AutoWidthOption v-model="autoWidth" />
|
||||||
<el-radio-group v-model="autoWidth">
|
<BookTypeOption v-model="bookType" />
|
||||||
<el-radio :label="true" border>True</el-radio>
|
<el-button :loading="downloadLoading" style="margin:0 0 20px 20px;" type="primary" icon="document" @click="handleDownload">{{ $t('excel.export') }} Excel</el-button>
|
||||||
<el-radio :label="false" border>False</el-radio>
|
</div>
|
||||||
</el-radio-group>
|
|
||||||
<el-button :loading="downloadLoading" style="margin:0 0 20px 20px;" type="primary" icon="document" @click="handleDownload">{{ $t('excel.export') }} Excel</el-button>
|
|
||||||
|
|
||||||
<el-table v-loading="listLoading" :data="list" element-loading-text="拼命加载中" border fit highlight-current-row>
|
<el-table v-loading="listLoading" :data="list" element-loading-text="拼命加载中" border fit highlight-current-row>
|
||||||
<el-table-column align="center" label="Id" width="95">
|
<el-table-column align="center" label="Id" width="95">
|
||||||
|
@ -46,15 +44,22 @@
|
||||||
import { fetchList } from '@/api/article'
|
import { fetchList } from '@/api/article'
|
||||||
import { parseTime } from '@/utils'
|
import { parseTime } from '@/utils'
|
||||||
|
|
||||||
|
// options components
|
||||||
|
import FilenameOption from './components/FilenameOption'
|
||||||
|
import AutoWidthOption from './components/AutoWidthOption'
|
||||||
|
import BookTypeOption from './components/BookTypeOption'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ExportExcel',
|
name: 'ExportExcel',
|
||||||
|
components: { FilenameOption, AutoWidthOption, BookTypeOption },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
list: null,
|
list: null,
|
||||||
listLoading: true,
|
listLoading: true,
|
||||||
downloadLoading: false,
|
downloadLoading: false,
|
||||||
filename: '',
|
filename: '',
|
||||||
autoWidth: true
|
autoWidth: true,
|
||||||
|
bookType: 'xlsx'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -79,7 +84,8 @@ export default {
|
||||||
header: tHeader,
|
header: tHeader,
|
||||||
data,
|
data,
|
||||||
filename: this.filename,
|
filename: this.filename,
|
||||||
autoWidth: this.autoWidth
|
autoWidth: this.autoWidth,
|
||||||
|
bookType: this.bookType
|
||||||
})
|
})
|
||||||
this.downloadLoading = false
|
this.downloadLoading = false
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue