Skip to content

Simple Example ​

Pass your rows to data and describe the columns with fields. Keys are the column labels, values are the (possibly nested) JSON paths to export.

Download .xls

Fields ​

fields decides which columns are exported. Each value is exported as is, unless you give a callback to format it:

js
const jsonFields = {
  // regular field (exported as is) — nested paths are supported
  fieldLabel: 'attributeName',
  // callback for formatting
  anotherFieldLabel: {
    field: 'anotherAttributeName', // nested paths are supported
    callback: (value) => `formatted value ${value}`,
  },
}

If no fields are provided, the keys of the first object in data are used as the column names.

You can also pass the fields inline with export-fields:

template
<JsonExcel
  :data="jsonData"
  :export-fields="{
    'Human friendly name': '_name_field_from_json',
    'Last name': '_last_name_text',
  }"
/>

Options API ​

Using the Options API with a globally registered component works the same way:

js
import { createApp } from 'vue'
import JsonExcel from 'vue-json-excel3'

createApp({
  components: { downloadExcel: JsonExcel },
  data() {
    return {
      json_fields: { 'Complete name': 'name', City: 'city', Telephone: 'phone.mobile' },
      json_data: [
        { name: 'Tony Peña', city: 'New York', phone: { mobile: '1-541-754-3010' } },
      ],
      json_meta: [[{ key: 'charset', value: 'utf-8' }]],
    }
  },
}).mount('#app')
html
<download-excel
  class="btn btn-default"
  :data="json_data"
  :fields="json_fields"
  :meta="json_meta"
  worksheet="My Worksheet"
  name="filename.xls"
>
  Download Excel (you can customize this with html code!)
</download-excel>

Released under the MIT License.