vue-json-excel
Javascript to export html table to Excel
The method implemented in this component use HTML tables to draw the .xls files, Microsoft Excel no longer recognize HTML as native content so will prompt a warning message before open the file. The content will be rendered perfectly but the message can’t be avoid.
Getting started
Get the package:
npm install vue-json-excel
Register JsonExcel in your app entrypoint:
import Vue from 'vue'
import JsonExcel from 'vue-json-excel'
Vue.component('downloadExcel', JsonExcel)
In your template
<download-excel
:data = "json_data">
Download Data
<img src="download_icon.png">
</download-excel>
Props List
Name | Type | Description |
---|---|---|
data | Array | (required) Data to be exported |
fields | Object | fields inside the Json Object that you want to export. If no given, all the properties in the Json are exported |
export-fields (exportFields) | Object | this prop is 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 [xls, csv], default: xls |
name | string | filename to export, deault: data.xls |
title | string/Array | Title(s) for the data, could be a string or an array of strings (multiple titles) |
footer | string/Array | Footer(s) for the data, could be a string or an array of strings (multiple footers) |
Example
import Vue from 'vue'
import JsonExcel from 'vue-json-excel'
Vue.component('downloadExcel', JsonExcel)
const app = new Vue({
el: '#app',
data: {
json_fields: {
'Complete name': 'name',
'City': 'city',
'Telephone': 'phone.mobile',
'Telephone 2' : {
field: 'phone.landline',
callback: (value) => {
return `Landline Phone - ${value}`;
}
},
},
json_data: [
{
'name': 'Tony Peña',
'city': 'New York',
'country': 'United States',
'birthdate': '1978-03-15',
'phone': {
'mobile': '1-541-754-3010',
'landline': '(541) 754-3010'
}
},
{
'name': 'Thessaloniki',
'city': 'Athens',
'country': 'Greece',
'birthdate': '1987-11-23',
'phone': {
'mobile': '+1 855 275 5071',
'landline': '(2741) 2621-244'
}
}
],
json_meta: [
[
{
'key': 'charset',
'value': 'utf-8'
}
]
],
}
})
In your HTML call it like
<download-excel
class = "btn btn-default"
:data = "json_data"
:fields = "json_fields"
name = "filename.xls">
Download Excel (you can customize this with html code!)
</download-excel>
REQUIRED
- json_data: Contains the data you want to export,
- json_fields: You can select what fields to export, especify nested data and assign labels to the fields
the key is the label, the value is the JSON field. This will export the field data ‘as is’.
If you need to customize the the exported data you can define a callback function. Thanks to @gucastiliao.
let json_fields = {
// regular field (exported data 'as is')
fieldLabel: attributeName, // nested attribute supported
// callback function for data formatting
anotherFieldLabel: {
field: anotherAttributeName, // nested attribute supported
callback: (value) => {
return `formatted value ${value}`
}
},
}
Export CSV
To export JSON to CSV file just add the prop type with value «csv»:
<download-excel
class = "btn btn-default"
:data = "json_data"
:fields = "json_fields"
type = "csv"
name = "filename.xls">
Download Excel (you can customize this with html code!)
</download-excel>
GitHub
Содержание
- Vue table to excel
- 2) Introduce two JS files
- 3) Modify the path to the Export2Excel.js file to introduce blob.js
- 4) Table data
- 5) Click Export Table button, call method export2excel
- Table Export Excel
- 1. Install dependence
- 2. Table Add attribute
- 3. JS code
- HTML turn Word documentation
- 1. Install dependence
- 2. Form or other HTML
- 3. JS code
- Intelligent Recommendation
- Vue exports table data to Excel
- Vue exports Excel table data
- Vue exports the custom Excel table
- Vue HTML turn Excel
- Java exports PDF, Excel, Word, HTML
- More Recommendation
- HTML Table table exports Excel method
- XLSX exports html table as an excel table
- VUE exports the Excel file corruption
- POI-TL exports Word according to the Word Template, generate HTML using the Spring-Thymeleaf template and turn HTML to Word through Docx4j, using JXLS to export Excel according to Excel template
- Vue exports the excel file on the server, and the vue+element table is exported as an Excel file
- Javascript to export html table to Excel
- vue-json-excel
- Getting started
- Props List
- Example
- Export CSV
- leduyptit/vue-export-excel
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Fetch Example
- Vue table to excel
- Vue — Element-UI Component Library Table Table Export Excel File
- Vue exports the EXCEL file in the page (export the table table data)
- Vue Export Table Table is Excel
- More Recommendation
- Vue-excel file export
- Vue export excel file
- Export Excel file in Vue
- Vue— the page data export excel file (table tabular data)
- Vue implements element-ui el-table form to export excel file
Vue table to excel
Note: Installing in the project root directory
2) Introduce two JS files
In the src directory, create a new Excel folder to put blob.js and export2excel.js
The contents of the two JS files are as follows:
- Blob.js
- Export2Excel.js
3) Modify the path to the Export2Excel.js file to introduce blob.js
4) Table data
This is stored in the following form:
- There are two objects in this example;
- How many items are there in the form, how many objects are there;
- The attribute name of each object is consistent, the corresponding attribute value is different;
5) Click Export Table button, call method export2excel
Detailed explanation of the export2excel method:
1. Note Use the correct path to introduce the modules exported in the export2excel.js file
Home.Vue is the module exported in Export2Excel.js for the current file.
The modules exported in Export2Excel.js are:
2. Set the first line of the export file THEADER, and the attribute name of the title corresponding to the title FilterVal
3. Filter data
Filtered results Data:
4. Set the exported file named hh_excel, and call method export_json_to_excel, export file
Источник
Table Export Excel
1. Install dependence
File-saver is used to save files and must be installed.
2. Table Add attribute
The label adds the REF attribute to obtain the element EL; you can also add ID attribute acquisition.
3. JS code
HTML turn Word documentation
1. Install dependence
File-saver is used to save files and must be installed.
2. Form or other HTML
The label adds the REF attribute to obtain the element EL; you can also add ID attribute acquisition.
3. JS code
Intelligent Recommendation
Vue exports table data to Excel
In project development, encountering the need to export form data to Excel, after searching, find the method is as follows: Install plugin Download attachment (Gitee)Appendix Download the files to put.
Vue exports Excel table data
Website, two options, combined with the ELEMENT-UI component library, the second type, the second kind of second type 1, first download two JS files, the file link is below, you can download it direct.
Vue exports the custom Excel table
1. Vue export Excel 1.1, installation dependencies npm install -S file-saver npm install -S xlsx npm install -D script-loader 1.2, configuration Create a new folder Vendor under the project SRC folder.
Vue HTML turn Excel
1. Install the plugin 2. Introduction in min.js 3. Use directly to the page.
Java exports PDF, Excel, Word, HTML
pom.xml Export CSV Export Word Export HTML Export PDF.
More Recommendation
HTML Table table exports Excel method
First code Reprinted from http://blog.csdn.net/sinat_15114467/article/details/51098522 Github also has a written plugin: This address is also related introduction https://segmentfault.com/a/1190000000.
XLSX exports html table as an excel table
Some of the unrelated code have been omitted in the example. 1. Install XLSX $ npm install xlsx —save 2. Export Excel method Write the export Excel method in mixing and mix each page required. Isshow.
VUE exports the Excel file corruption
Vue exports binary flow from the background, and then prompts the file damage. When exporting, pay attention to the returned data must be a binary stream, and the following code is used to export the .
POI-TL exports Word according to the Word Template, generate HTML using the Spring-Thymeleaf template and turn HTML to Word through Docx4j, using JXLS to export Excel according to Excel template
Export Word in accordance with the Word Template, generate HTML using the Spring-Thymeleaf template and turn HTML to Word via DOCX4J, use JXLS to export Excel according to Excel template Use POI-TL to.
Vue exports the excel file on the server, and the vue+element table is exported as an Excel file
Vue+element table is exported to Excel file Release time: 2020-10-26 03:36:48 Source: Script House Reads: 136 Author: Xiaoyu runs forward The example in this article shares the specific code for expor.
Источник
Javascript to export html table to Excel
vue-json-excel
Javascript to export html table to Excel
The method implemented in this component use HTML tables to draw the .xls files, Microsoft Excel no longer recognize HTML as native content so will prompt a warning message before open the file. The content will be rendered perfectly but the message can’t be avoid.
Getting started
Get the package:
Register JsonExcel in your app entrypoint:
In your template
Props List
Name | Type | Description |
---|---|---|
data | Array | (required) Data to be exported |
fields | Object | fields inside the Json Object that you want to export. If no given, all the properties in the Json are exported |
export-fields (exportFields) | Object | this prop is 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 [xls, csv], default: xls |
name | string | filename to export, deault: data.xls |
title | string/Array | Title(s) for the data, could be a string or an array of strings (multiple titles) |
footer | string/Array | Footer(s) for the data, could be a string or an array of strings (multiple footers) |
Example
In your HTML call it like
- json_data: Contains the data you want to export,
- json_fields: You can select what fields to export, especify nested data and assign labels to the fields
the key is the label, the value is the JSON field. This will export the field data ‘as is’.
If you need to customize the the exported data you can define a callback function. Thanks to @gucastiliao.
Export CSV
To export JSON to CSV file just add the prop type with value «csv»:
Источник
leduyptit/vue-export-excel
Use Git or checkout with SVN using the web URL.
Work fast with our official CLI. Learn more.
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
JSON to Excel for VUE 2
Download your JSON data as an excel file directly from the browser. This component it’s based on the solution proposed on this thread https://stackoverflow.com/questions/17142427/javascript-to-export-html-table-to-excel
Important! Extra prompt in Microsoft Excel
The method implemented in this component use HTML tables to draw the .xls files, Microsoft Excel no longer recognize HTML as native content so will prompt a warning message before open the file. The content will be rendered perfectly but the message can’t be avoid.
Get the package:
Register JsonExcel in your app entrypoint:
In your template
Name | Type | Description |
---|---|---|
data | Array | Data to be exported |
fields | Object | fields inside the Json Object that you want to export. If no given, all the properties in the Json are exported |
export-fields (exportFields) | Object | this prop is 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 [xls, csv], default: xls |
name | string | filename to export, deault: data.xls |
title | string/Array | Title(s) for the data, could be a string or an array of strings (multiple titles) |
footer | string/Array | Footer(s) for the data, could be a string or an array of strings (multiple footers) |
default-value (defaultValue) | string | Use as fallback when the row has no field values, default: » |
worksheet | string | Name of the worksheet tab. default: ‘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 |
In your HTML call it like
- json_data: Contains the data you want to export,
- json_fields: You can select what fields to export, especify nested data and assign labels to the fields the key is the label, the value is the JSON field. This will export the field data ‘as is’. If you need to customize the the exported data you can define a callback function. Thanks to @gucastiliao.
To export JSON to CSV file just add the prop type with value «csv»:
Multi-line values will appear in a single cell in 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.
Fetch Data on Demand
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:
Fetch Example
when using callbacks function in the fields description, you have three option to retrieve data:
- field: ‘path.to.nested.property’ you can retrieve an especific value using the nested property notation.
- field: ‘define.nested.object’ you can retrieve an nested object too
- Or get the whole row if field it’s undefined.
This project is in an early stage of development. Any contribution is welcome 😀
Источник
Vue table to excel
Proceed as follows: I. In this function is packaged into a separate component Reference component.
Vue — Element-UI Component Library Table Table Export Excel File
1.npm import package 2. Add ID to the EL-TABLE tag 3. Reference package 4. Add the export button 5. Export method Reprinted: https://www.cnblogs.com/s313139232/p/12557556.html.
Vue exports the EXCEL file in the page (export the table table data)
1. Install three dependencies 2. Create a folder in the project (usually newly built under SRC, the file name is taken by itself, named Excel here), put in the blob.js and export2excel.js in the folde.
Vue Export Table Table is Excel
VUE uses file-saver export files Source 1: https://blog.csdn.net/mouday/article/details/111958466 Source 2: https://blog.csdn.net/qq_30671099/Article/details/104052782 main body.
More Recommendation
Vue-excel file export
1. Installation dependencies 2. Import two JS 3. main.js import file 4. Used in components tHeader is the header of the table. The data in filterVal is the field of the table. The data in the table is.
Vue export excel file
In general projects, exporting excel forms is generally back-end processing, and the front-end call interface returns a url address. The download function can be achieved through window.open or creati.
Export Excel file in Vue
1. I often use import and export, take notes for myself.
Vue— the page data export excel file (table tabular data)
A mounting three dependencies Second, the new project in a folder (usually in src a new file name self-created, here named excel), placed in a folderBlob.js with export2Excel.js (These two files avail.
Vue implements element-ui el-table form to export excel file
demand: Export the data in the table below to excel file method: 1. Installation dependencies Two, add attributes The tag adds the ref attribute to get the element el; you can also add the id attribut.
Источник
JSON to Excel for VUE 2
Download your JSON data as an excel file directly from the browser. This component it’s based on the solution proposed on this thread https://stackoverflow.com/questions/17142427/javascript-to-export-html-table-to-excel
Important! Extra prompt in Microsoft Excel
The method implemented in this component use HTML tables to draw the .xls files, Microsoft Excel no longer recognize HTML as native content so will prompt a warning message before open the file. The content will be rendered perfectly but the message can’t be avoid.
Getting started
Get the package:
npm install vue-json-excel
Register JsonExcel in your app entrypoint:
import Vue from 'vue' import JsonExcel from 'vue-json-excel' Vue.component('downloadExcel', JsonExcel)
In your template
<download-excel :data = "json_data"> Download Data <img src="download_icon.png"> </download-excel>
Props List
Name | Type | Description |
---|---|---|
data | Array | Data to be exported |
fields | Object | fields inside the Json Object that you want to export. If no given, all the properties in the Json are exported |
export-fields (exportFields) | Object | this prop is 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 [xls, csv], default: xls |
name | string | filename to export, deault: data.xls |
title | string/Array | Title(s) for the data, could be a string or an array of strings (multiple titles) |
footer | string/Array | Footer(s) for the data, could be a string or an array of strings (multiple footers) |
default-value (defaultValue) | string | Use as fallback when the row has no field values, default: » |
worksheet | string | Name of the worksheet tab. default: ‘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 |
Example
import Vue from 'vue' import JsonExcel from 'vue-json-excel' Vue.component('downloadExcel', JsonExcel) const app = new Vue({ el: '#app', data: { json_fields: { 'Complete name': 'name', 'City': 'city', 'Telephone': 'phone.mobile', 'Telephone 2' : { field: 'phone.landline', callback: (value) => { return `Landline Phone - ${value}`; } }, }, json_data: [ { 'name': 'Tony Peña', 'city': 'New York', 'country': 'United States', 'birthdate': '1978-03-15', 'phone': { 'mobile': '1-541-754-3010', 'landline': '(541) 754-3010' } }, { 'name': 'Thessaloniki', 'city': 'Athens', 'country': 'Greece', 'birthdate': '1987-11-23', 'phone': { 'mobile': '+1 855 275 5071', 'landline': '(2741) 2621-244' } } ], json_meta: [ [ { 'key': 'charset', 'value': 'utf-8' } ] ], } })
In your HTML call it like
<download-excel class = "btn btn-default" :data = "json_data" :fields = "json_fields" worksheet = "My Worksheet" name = "filename.xls"> Download Excel (you can customize this with html code!) </download-excel>
REQUIRED
- json_data: Contains the data you want to export,
- json_fields: You can select what fields to export, especify nested data and assign labels to the fields
the key is the label, the value is the JSON field. This will export the field data ‘as is’.
If you need to customize the the exported data you can define a callback function. Thanks to @gucastiliao.
let json_fields = { // regular field (exported data 'as is') fieldLabel: attributeName, // nested attribute supported // callback function for data formatting anotherFieldLabel: { field: anotherAttributeName, // nested attribute supported callback: (value) => { return `formatted value ${value}` } }, }
Export CSV
To export JSON to CSV file just add the prop type with value «csv»:
<download-excel class = "btn btn-default" :data = "json_data" :fields = "json_fields" type = "csv" name = "filename.xls"> Download Excel (you can customize this with html code!) </download-excel>
Multi-line values will appear in a single cell in 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:
<template> <div> <json-excel :data="dataForExcel"></json-excel> </div> </template> <script> import JsonExcel from "@/components/JsonExcel"; export default { components: { JsonExcel }, data: () => { return { dataForExcel: [ { colA: "Hello", colB: "World" }, { colA: "Multi-line", /* Multi-line value: */ colB: "This is a long paragraphnwith multiple linesnthat should show in a single cell." }, { colA: "Another", colB: "Regular cell" } ] }; } }; </script>
Fetch Data on Demand
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:
<template> <div id="app"> <hr> <h2>Fetch Example</h2> <downloadexcel class = "btn" :fetch = "fetchData" :fields = "json_fields" :before-generate = "startDownload" :before-finish = "finishDownload" type = "csv"> Download Excel </downloadexcel> </div> </template> <script> import downloadexcel from "vue-json-excel"; import axios from 'axios'; export default { name: "App", components: { downloadexcel, }, data(){ return { json_fields: { 'Complete name': 'name', 'Date': 'date', }, } }, //data methods:{ async fetchData(){ const response = await axios.get('https://holidayapi.com/v1/holidays?key=a4b2083b-1577-4acd-9408-6e529996b129&country=US&year=2017&month=09'); console.log(response); return response.data.holidays; }, startDownload(){ alert('show loading'); }, finishDownload(){ alert('hide loading'); } } }; </script>
Using callbacks
when using callbacks function in the fields description, you have three option to retrieve data:
- field: ‘path.to.nested.property’ you can retrieve an especific value using the nested property notation.
json_fields: { 'Complete name': 'name', 'City': 'city', 'Telephone': 'phone.mobile', 'Telephone 2' : { field: 'phone.landline', callback: (value) => { return `Landline Phone - ${value}`; } }, },
- field: ‘define.nested.object’ you can retrieve an nested object too
json_fields: { 'Complete name': 'name', 'City': 'city', 'Telephone': 'phone.mobile', 'Telephone 2' : { field: 'phone', callback: (value) => { return `Landline Phone - ${value.landline}`; } }, },
- Or get the whole row if field it’s undefined.
json_fields: { 'Complete name': 'name', 'City': 'city', 'Telephone': 'phone.mobile', 'Telephone 2' : { callback: (value) => { return `Landline Phone - ${value.phone.landline}`; } }, },
License
MIT
Status
This project is in an early stage of development. Any contribution is welcome
Easy way
If you can use different table component try to look into Vue materialize datatable
It’s letting you to export in XLS and print to PDF
Without any component
The way I personally use If i need to export any JSON that is consist of more fields than there are in the actual table:
https://www.papaparse.com/
import Papa from "papaparse";
var blob = new Blob([Papa.unparse(jsonData)], { type: 'text/csv;charset=utf-8;' });
var link = document.createElement("a");
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", 'filename.csv');
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
So, we actually unparsing JSON data into the blob, creating dynamic element which linked to it and downloading the file.