Gathering detailed insights and metrics for vue-json-excel3
Gathering detailed insights and metrics for vue-json-excel3
Gathering detailed insights and metrics for vue-json-excel3
Gathering detailed insights and metrics for vue-json-excel3
npm install vue-json-excel3
Typescript
Module System
Node Version
NPM Version
82.2
Supply Chain
99.7
Quality
86.8
Maintenance
100
Vulnerability
100
License
Vue (96.04%)
JavaScript (3.96%)
Total Downloads
225,384
Last Day
451
Last Week
4,085
Last Month
21,063
Last Year
175,571
44 Stars
55 Commits
8 Forks
4 Watching
8 Branches
3 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.30
Package Id
vue-json-excel3@1.0.30
Unpacked Size
1.99 MB
Size
526.33 kB
File Count
20
NPM Version
8.5.0
Node Version
16.14.2
Publised On
17 Dec 2024
Cumulative downloads
Total Downloads
Last day
-61.5%
451
Compared to previous day
Last week
-21.3%
4,085
Compared to previous week
Last month
7%
21,063
Compared to previous month
Last year
296.9%
175,571
Compared to previous year
3
Old Document - https://vue-json-excel.netlify.app/
Note - for is there is error Cannot read property 'isCE' of null in remote component with slot using Module Federation #4344
1 chainWebpack(config) { 2 config.resolve.symlinks(false) 3 config.resolve.alias.set( 'vue', path.resolve('./node_modules/vue')) 4 }
Download your JSON data as an Excel file directly from the browser.
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.
Get the package:
1npm install vue-json-excel3
Register JsonExcel in your vue app entry point:
1import { createApp } from 'vue' 2const app = createApp({}) 3import JsonExcel from "vue-json-excel3"; 4app.component("downloadExcel", JsonExcel);
In your template
1<download-excel :data="json_data"> 2 Download Data 3 <img src="download_icon.png" /> 4</download-excel>
Name | Type | Description | Default |
---|---|---|---|
data | Array | Data to be exported. | |
fields | Object | Fields inside the JSON Object that you want to export. If none provided, all properties in the JSON will be exported. | |
export-fields (exportFields) | Object | Used to fix the problem with other components that use the variable fields, like vee-validate. exportFields works exactly like fields | |
type | string | Mime type [xlsx, xls, csv] | xls |
name | string | File name to export. | data.xls |
header | string/Array | Title(s) for the data. Can be a string (one title) or an array of strings (multiple titles). | |
title(deprecated) | string/Array | same as header, title is maintained for retro-compatibility purposes but its use is not recommended due to the conflict with the HTML5 title attribute. | |
footer | string/Array | Footer(s) for the data. Can be a string (one footer) or an array of strings (multiple footers). | |
default-value (defaultValue) | string | Use as fallback when the row has no field values. | '' |
worksheet | string | Name of the worksheet tab. | 'Sheet1' |
fetch | Function | Callback 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-generate | Function | Callback to call a method right before the generate / fetch data, eg:show loading progress | |
before-finish | Function | Callback to call a method right before the download box pops out, eg:hide loading progress | |
stringifyLongNum | Boolean | stringify long number and decimal(solve the problem of loss of digital accuracy), default: false | |
escapeCsv | Boolean | This 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 | |
emitBlob | Boolean | This will emmit the blob data. default: False | |
debounce | Number | This is for debouce in download function | 500 |
rtl | Boolean | This is for RTL support | false |
1import { createApp } from 'vue' 2import JsonExcel from "vue-json-excel3"; 3 4const app = new createApp({ 5 data(){ 6 return { 7 json_fields: { 8 "Complete name": "name", 9 City: "city", 10 Telephone: "phone.mobile", 11 "Telephone 2": { 12 field: "phone.landline", 13 callback: (value) => { 14 return `Landline Phone - ${value}`; 15 }, 16 }, 17 }, 18 json_data: [ 19 { 20 name: "Tony Peña", 21 city: "New York", 22 country: "United States", 23 birthdate: "1978-03-15", 24 phone: { 25 mobile: "1-541-754-3010", 26 landline: "(541) 754-3010", 27 }, 28 }, 29 { 30 name: "Thessaloniki", 31 city: "Athens", 32 country: "Greece", 33 birthdate: "1987-11-23", 34 phone: { 35 mobile: "+1 855 275 5071", 36 landline: "(2741) 2621-244", 37 }, 38 }, 39 ], 40 json_meta: [ 41 [ 42 { 43 key: "charset", 44 value: "utf-8", 45 }, 46 ], 47 ], 48 } 49 }, 50 component:{ 51 downloadExcel:JsonExcel 52 } 53}).mount('#app');
In your HTML call it like
1<download-excel 2 class="btn btn-default" 3 :data="json_data" 4 :fields="json_fields" 5 worksheet="My Worksheet" 6 name="filename.xls" 7> 8 Download Excel (you can customize this with html code!) 9</download-excel>
REQUIRED
1let json_fields = { 2 // regular field (exported data 'as is') 3 fieldLabel: attributeName, // nested attribute supported 4 // callback function for data formatting 5 anotherFieldLabel: { 6 field: anotherAttributeName, // nested attribute supported 7 callback: (value) => { 8 return `formatted value ${value}`; 9 }, 10 }, 11};
json_fields is a object that represents which columns will be exported. If no object is provided, the component will be use the first object in your data array to extract the keys as columns names. Json field example:
:export-fields="{
'Human friendly name': '_name_field_from_json',
'user's last name': '_last_name_text'
}"
To export JSON as a CSV file, just add the prop type
with a value of "csv":
1<download-excel 2 class="btn btn-default" 3 :data="json_data" 4 :fields="json_fields" 5 type="csv" 6 name="filename.xls" 7> 8 Download CSV (you can customize this with html code!) 9</download-excel>
A single text value in the data that contains newline characters will appear as a single cell in Excel. This avoids the undesired behavior of multi-line values getting split into multiple cells that must be merged before using data filters and pivot tables.
For example:
1<template> 2 <div> 3 <json-excel :data="dataForExcel" /> 4 </div> 5</template> 6<script> 7 import JsonExcel from "vue-json-excel3"; 8 9 export default { 10 components: { 11 JsonExcel, 12 }, 13 data: () => { 14 return { 15 dataForExcel: [ 16 { colA: "Hello", colB: "World" }, 17 { 18 colA: "Multi-line", 19 /* Multi-line value: */ 20 colB: 21 "This is a long paragraph\nwith multiple lines\nthat should show in a single cell.", 22 }, 23 { colA: "Another", colB: "Regular cell" }, 24 ], 25 }; 26 }, 27 }; 28</script>
In case you need to fetch data from the server, you could use the fetch prop that allows you to define a callback function that is executed when your user click the download button. This function has to return a JSON value containing the data to export. A basic use case is:
1<template> 2 <div id="app"> 3 4 <hr> 5 <h2>Fetch Example</h2> 6 <downloadexcel 7 class = "btn" 8 :fetch = "fetchData" 9 :fields = "json_fields" 10 :before-generate = "startDownload" 11 :before-finish = "finishDownload"> 12 Download Excel 13 </downloadexcel> 14 </div> 15</template> 16 17<script> 18import downloadexcel from "vue-json-excel3"; 19import axios from 'axios'; 20 21export default { 22 name: "App", 23 components: { 24 downloadexcel, 25 }, 26 data(){ 27 return { 28 json_fields: { 29 'Complete name': 'name', 30 'Date': 'date', 31 }, 32 } 33 }, //data 34 methods:{ 35 async fetchData(){ 36 const response = await axios.get('https://holidayapi.com/v1/holidays?key=a4b2083b-1577-4acd-9408-6e529996b129&country=US&year=2017&month=09'); 37 console.log(response); 38 return response.data.holidays; 39 }, 40 startDownload(){ 41 alert('show loading'); 42 }, 43 finishDownload(){ 44 alert('hide loading'); 45 } 46 } 47}; 48</script> 49
when using callback functions in the fields description, you have three option to retrieve data:
1 json_fields: { 2 'Complete name': 'name', 3 'City': 'city', 4 'Telephone': 'phone.mobile', 5 'Telephone 2' : { 6 field: 'phone.landline', 7 callback: (value) => { 8 return `Landline Phone - ${value}`; 9 } 10 }, 11 },
1 json_fields: {s 2 'Complete name': 'name', 3 'City': 'city', 4 'Telephone': 'phone.mobile', 5 'Telephone 2' : { 6 field: 'phone', 7 callback: (value) => { 8 return `Landline Phone - ${value.landline}`; 9 } 10 }, 11 },
1 json_fields: { 2 'Complete name': 'name', 3 'City': 'city', 4 'Telephone': 'phone.mobile', 5 'Telephone 2' : { 6 callback: (value) => { 7 return `Landline Phone - ${value.phone.landline}`; 8 } 9 }, 10 },
If this helped you in any way, you can contribute to this project for long term survival by supporting me:
Be sure to check out my sponsor page.
Thank you so much!!!
No vulnerabilities found.
No security vulnerabilities found.