Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per columns headers #141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions JsonExcel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default {
header: {
default: null,
},

// Title(s) for single column data, must be an array (ex: ['titleCol0',,TitleCol2])
perColumnsHeaders: {
default: null,
},

// Footer(s) for the data, could be a string or an array of strings (multiple footers)
footer: {
default: null,
Expand Down Expand Up @@ -158,6 +164,16 @@ export default {
);
}

// perColumnsHeaders
const perColumnsHeaders = this.perColumnsHeaders;
if(Array.isArray(perColumnsHeaders)) {
xlsData += "<tr>";
for (let pchKey in perColumnsHeaders) {
xlsData += "<th>" + perColumnsHeaders[pchKey] + "</th>";
}
xlsData += "</tr>";
}

//Fields
xlsData += "<tr>";
for (let key in data[0]) {
Expand Down Expand Up @@ -211,6 +227,17 @@ export default {
csvData.push(this.parseExtraData(header, "${data}\r\n"));
}

// perColumnsHeaders
const perColumnsHeaders = this.perColumnsHeaders;
if(Array.isArray(perColumnsHeaders)) {
for (let pchKey in perColumnsHeaders) {
csvData.push(perColumnsHeaders[pchKey]);
csvData.push(",");
}
csvData.pop();
csvData.push("\r\n");
}

//Fields
for (let key in data[0]) {
csvData.push(key);
Expand Down
25 changes: 25 additions & 0 deletions dist/vue-json-excel.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ var script = {
header: {
default: null,
},
// Title(s) for single column data, must be an array (ex: ['titleCol0',,TitleCol2])
perColumnsHeaders: {
default: null,
},
// Footer(s) for the data, could be a string or an array of strings (multiple footers)
footer: {
default: null,
Expand Down Expand Up @@ -323,6 +327,16 @@ var script = {
);
}

// perColumnsHeaders
const perColumnsHeaders = this.perColumnsHeaders;
if(Array.isArray(perColumnsHeaders)) {
xlsData += "<tr>";
for (let pchKey in perColumnsHeaders) {
xlsData += "<th>" + perColumnsHeaders[pchKey] + "</th>";
}
xlsData += "</tr>";
}

//Fields
xlsData += "<tr>";
for (let key in data[0]) {
Expand Down Expand Up @@ -376,6 +390,17 @@ var script = {
csvData.push(this.parseExtraData(header, "${data}\r\n"));
}

// perColumnsHeaders
const perColumnsHeaders = this.perColumnsHeaders;
if(Array.isArray(perColumnsHeaders)) {
for (let pchKey in perColumnsHeaders) {
csvData.push(perColumnsHeaders[pchKey]);
csvData.push(",");
}
csvData.pop();
csvData.push("\r\n");
}

//Fields
for (let key in data[0]) {
csvData.push(key);
Expand Down
25 changes: 25 additions & 0 deletions dist/vue-json-excel.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ var script = {
header: {
default: null,
},
// Title(s) for single column data, must be an array (ex: ['titleCol0',,TitleCol2])
perColumnsHeaders: {
default: null,
},
// Footer(s) for the data, could be a string or an array of strings (multiple footers)
footer: {
default: null,
Expand Down Expand Up @@ -321,6 +325,16 @@ var script = {
);
}

// perColumnsHeaders
const perColumnsHeaders = this.perColumnsHeaders;
if(Array.isArray(perColumnsHeaders)) {
xlsData += "<tr>";
for (let pchKey in perColumnsHeaders) {
xlsData += "<th>" + perColumnsHeaders[pchKey] + "</th>";
}
xlsData += "</tr>";
}

//Fields
xlsData += "<tr>";
for (let key in data[0]) {
Expand Down Expand Up @@ -374,6 +388,17 @@ var script = {
csvData.push(this.parseExtraData(header, "${data}\r\n"));
}

// perColumnsHeaders
const perColumnsHeaders = this.perColumnsHeaders;
if(Array.isArray(perColumnsHeaders)) {
for (let pchKey in perColumnsHeaders) {
csvData.push(perColumnsHeaders[pchKey]);
csvData.push(",");
}
csvData.pop();
csvData.push("\r\n");
}

//Fields
for (let key in data[0]) {
csvData.push(key);
Expand Down
31 changes: 28 additions & 3 deletions dist/vue-json-excel.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@
// Title(s) for the data, could be a string or an array of strings (multiple titles)
header: {
default: null,
},
},
// Title(s) for single column data, must be an array (ex: ['titleCol0',,TitleCol2])
perColumnsHeaders: {
default: null,
},
// Footer(s) for the data, could be a string or an array of strings (multiple footers)
footer: {
default: null,
Expand Down Expand Up @@ -325,7 +329,17 @@
header,
'<tr><th colspan="' + colspan + '">${data}</th></tr>'
);
}
}

// perColumnsHeaders
const perColumnsHeaders = this.perColumnsHeaders;
if(Array.isArray(perColumnsHeaders)) {
xlsData += "<tr>";
for (let pchKey in perColumnsHeaders) {
xlsData += "<th>" + perColumnsHeaders[pchKey] + "</th>";
}
xlsData += "</tr>";
}

//Fields
xlsData += "<tr>";
Expand Down Expand Up @@ -378,7 +392,18 @@
const header = this.header || this.$attrs.title;
if (header) {
csvData.push(this.parseExtraData(header, "${data}\r\n"));
}
}

// perColumnsHeaders
const perColumnsHeaders = this.perColumnsHeaders;
if(Array.isArray(perColumnsHeaders)) {
for (let pchKey in perColumnsHeaders) {
csvData.push(perColumnsHeaders[pchKey]);
csvData.push(",");
}
csvData.pop();
csvData.push("\r\n");
}

//Fields
for (let key in data[0]) {
Expand Down