Skip to content

Getting Started

1. Get the package:

WARNING

The method implemented in this component uses HTML tables to draw the .xls files, Microsoft Excel no longer recognize HTML as native content so a warning message will be displayed before opening the file. The content will be rendered perfectly but the message can't be avoided.

cmd
npm install vue-json-excel3

Register JsonExcel in your vue app entry point:

2. Register JsonExcel in your vue app entry point:

js
import {createApp} from 'vue'

const app = createApp({})
import JsonExcel from "vue-json-excel3";

app.component("downloadExcel", JsonExcel);

3. In your template

html

<download-excel :data="json_data">
    Download Data
    <img src="download_icon.png"/>
</download-excel>

Props List

NameTypeDescriptionDefault
dataArrayData to be exported.
fieldsObjectFields inside the JSON Object that you want to export. If none provided, all properties in the JSON will be exported.
export-fields (exportFields)ObjectUsed to fix the problem with other components that use the variable fields, like vee-validate. exportFields works exactly like fields
typestringMime type [xls, csv, xlsx]xls
namestringFile name to export.data.xls
headerstring/ArrayTitle(s) for the data. Can be a string (one title) or an array of strings (multiple titles).
title(deprecated)string/Arraysame as header, title is maintained for retro-compatibility purposes but its use is not recommended due to the conflict with the HTML5 title attribute.
footerstring/ArrayFooter(s) for the data. Can be a string (one footer) or an array of strings (multiple footers).
default-value (defaultValue)stringUse as fallback when the row has no field values.''
worksheetstringName of the worksheet tab.'Sheet1'
fetchFunctionCallback to fetch data before download, if it's set it runs immediately after mouse pressed and before download process.
IMPORTANT: only works if no data prop is defined.
before-generateFunctionCallback to call a method right before the generate / fetch data, eg:show loading progress
before-finishFunctionCallback to call a method right before the download box pops out, eg:hide loading progress
stringifyLongNumBooleanstringify long number and decimal(solve the problem of loss of digital accuracy), default: false
escapeCsvBooleanThis escapes CSV values in order to fix some excel problems with number fields. But this will wrap every csv data with **
="** and ", to avoid that you have to set this prop to false. default: True
emitBlobBooleanThis will emmit the blob data. default: False
debounceNumberThis is for debouce in download function500
rtlBooleanThis is for RTL supportfalse