How can i ignore comma inside a table field while exporting it to csv?












0















i found this code to download my table content into csv format but the problem is my table field has comma(,) within its field but the function splits the field.



these are the functions:



 function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;

csvFile = new Blob([csv], {type: "text/csv"});


downloadLink = document.createElement("a");

downloadLink.download = filename;

downloadLink.href = window.URL.createObjectURL(csvFile);


downloadLink.style.display = "none";

document.body.appendChild(downloadLink);


downloadLink.click();
}


function exportTableToCSV(filename) {
var csv = ;
var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {
var row = , cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);

csv.push(row.join(","));
}

// Download CSV file
downloadCSV(csv.join("n"), filename);
}


here is the html code:



<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Location</th>
</tr>
<tr>
<td>John Doe</td>
<td>john@gmail.com</td>
<td>India,up</td>
</tr>
<tr>
<td>Stephen Thomas</td>
<td>stephen@gmail.com</td>
<td>UK,london</td>
</tr>
<tr>
<td>Natly Oath</td>
<td>natly@gmail.com</td>
<td>France</td>
</tr>
</table>

<button onclick="exportTableToCSV('members.csv')">Export HTML Table To CSV
File</button>


the location column of john and natly will be split.










share|improve this question




















  • 1





    Do you mean it will split for John and Stephen? Also have you tried to alter the code yourself? It would help us if you showed an attempt as we can guide you through that.

    – Andrew Lohr
    Nov 20 '18 at 18:51













  • This would be a good read for you too- stackoverflow.com/questions/769621/…

    – Andrew Lohr
    Nov 20 '18 at 18:54











  • @AndrewLohr hey, i meant it for India and up similarly UK and london

    – Sri Ranjan
    Nov 20 '18 at 19:03
















0















i found this code to download my table content into csv format but the problem is my table field has comma(,) within its field but the function splits the field.



these are the functions:



 function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;

csvFile = new Blob([csv], {type: "text/csv"});


downloadLink = document.createElement("a");

downloadLink.download = filename;

downloadLink.href = window.URL.createObjectURL(csvFile);


downloadLink.style.display = "none";

document.body.appendChild(downloadLink);


downloadLink.click();
}


function exportTableToCSV(filename) {
var csv = ;
var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {
var row = , cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);

csv.push(row.join(","));
}

// Download CSV file
downloadCSV(csv.join("n"), filename);
}


here is the html code:



<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Location</th>
</tr>
<tr>
<td>John Doe</td>
<td>john@gmail.com</td>
<td>India,up</td>
</tr>
<tr>
<td>Stephen Thomas</td>
<td>stephen@gmail.com</td>
<td>UK,london</td>
</tr>
<tr>
<td>Natly Oath</td>
<td>natly@gmail.com</td>
<td>France</td>
</tr>
</table>

<button onclick="exportTableToCSV('members.csv')">Export HTML Table To CSV
File</button>


the location column of john and natly will be split.










share|improve this question




















  • 1





    Do you mean it will split for John and Stephen? Also have you tried to alter the code yourself? It would help us if you showed an attempt as we can guide you through that.

    – Andrew Lohr
    Nov 20 '18 at 18:51













  • This would be a good read for you too- stackoverflow.com/questions/769621/…

    – Andrew Lohr
    Nov 20 '18 at 18:54











  • @AndrewLohr hey, i meant it for India and up similarly UK and london

    – Sri Ranjan
    Nov 20 '18 at 19:03














0












0








0








i found this code to download my table content into csv format but the problem is my table field has comma(,) within its field but the function splits the field.



these are the functions:



 function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;

csvFile = new Blob([csv], {type: "text/csv"});


downloadLink = document.createElement("a");

downloadLink.download = filename;

downloadLink.href = window.URL.createObjectURL(csvFile);


downloadLink.style.display = "none";

document.body.appendChild(downloadLink);


downloadLink.click();
}


function exportTableToCSV(filename) {
var csv = ;
var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {
var row = , cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);

csv.push(row.join(","));
}

// Download CSV file
downloadCSV(csv.join("n"), filename);
}


here is the html code:



<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Location</th>
</tr>
<tr>
<td>John Doe</td>
<td>john@gmail.com</td>
<td>India,up</td>
</tr>
<tr>
<td>Stephen Thomas</td>
<td>stephen@gmail.com</td>
<td>UK,london</td>
</tr>
<tr>
<td>Natly Oath</td>
<td>natly@gmail.com</td>
<td>France</td>
</tr>
</table>

<button onclick="exportTableToCSV('members.csv')">Export HTML Table To CSV
File</button>


the location column of john and natly will be split.










share|improve this question
















i found this code to download my table content into csv format but the problem is my table field has comma(,) within its field but the function splits the field.



these are the functions:



 function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;

csvFile = new Blob([csv], {type: "text/csv"});


downloadLink = document.createElement("a");

downloadLink.download = filename;

downloadLink.href = window.URL.createObjectURL(csvFile);


downloadLink.style.display = "none";

document.body.appendChild(downloadLink);


downloadLink.click();
}


function exportTableToCSV(filename) {
var csv = ;
var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {
var row = , cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);

csv.push(row.join(","));
}

// Download CSV file
downloadCSV(csv.join("n"), filename);
}


here is the html code:



<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Location</th>
</tr>
<tr>
<td>John Doe</td>
<td>john@gmail.com</td>
<td>India,up</td>
</tr>
<tr>
<td>Stephen Thomas</td>
<td>stephen@gmail.com</td>
<td>UK,london</td>
</tr>
<tr>
<td>Natly Oath</td>
<td>natly@gmail.com</td>
<td>France</td>
</tr>
</table>

<button onclick="exportTableToCSV('members.csv')">Export HTML Table To CSV
File</button>


the location column of john and natly will be split.







javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 19:06







Sri Ranjan

















asked Nov 20 '18 at 18:48









Sri RanjanSri Ranjan

11




11








  • 1





    Do you mean it will split for John and Stephen? Also have you tried to alter the code yourself? It would help us if you showed an attempt as we can guide you through that.

    – Andrew Lohr
    Nov 20 '18 at 18:51













  • This would be a good read for you too- stackoverflow.com/questions/769621/…

    – Andrew Lohr
    Nov 20 '18 at 18:54











  • @AndrewLohr hey, i meant it for India and up similarly UK and london

    – Sri Ranjan
    Nov 20 '18 at 19:03














  • 1





    Do you mean it will split for John and Stephen? Also have you tried to alter the code yourself? It would help us if you showed an attempt as we can guide you through that.

    – Andrew Lohr
    Nov 20 '18 at 18:51













  • This would be a good read for you too- stackoverflow.com/questions/769621/…

    – Andrew Lohr
    Nov 20 '18 at 18:54











  • @AndrewLohr hey, i meant it for India and up similarly UK and london

    – Sri Ranjan
    Nov 20 '18 at 19:03








1




1





Do you mean it will split for John and Stephen? Also have you tried to alter the code yourself? It would help us if you showed an attempt as we can guide you through that.

– Andrew Lohr
Nov 20 '18 at 18:51







Do you mean it will split for John and Stephen? Also have you tried to alter the code yourself? It would help us if you showed an attempt as we can guide you through that.

– Andrew Lohr
Nov 20 '18 at 18:51















This would be a good read for you too- stackoverflow.com/questions/769621/…

– Andrew Lohr
Nov 20 '18 at 18:54





This would be a good read for you too- stackoverflow.com/questions/769621/…

– Andrew Lohr
Nov 20 '18 at 18:54













@AndrewLohr hey, i meant it for India and up similarly UK and london

– Sri Ranjan
Nov 20 '18 at 19:03





@AndrewLohr hey, i meant it for India and up similarly UK and london

– Sri Ranjan
Nov 20 '18 at 19:03












1 Answer
1






active

oldest

votes


















1














you can use quotes to ignore comma



 function exportTableToCSV(filename) {
var csv = ;
var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {
var row = , cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)
row.push("""+cols[j].innerText+""");

csv.push(row.join(","));
}

// Download CSV file
downloadCSV(csv.join("n"), filename);
}





share|improve this answer
























  • Thank you so much ! it solved my issue :)

    – Sri Ranjan
    Nov 20 '18 at 20:08











  • If solution is works then please mark as correct then future user easily find out correct answer

    – suresh bambhaniya
    Nov 21 '18 at 4:34











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399609%2fhow-can-i-ignore-comma-inside-a-table-field-while-exporting-it-to-csv%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














you can use quotes to ignore comma



 function exportTableToCSV(filename) {
var csv = ;
var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {
var row = , cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)
row.push("""+cols[j].innerText+""");

csv.push(row.join(","));
}

// Download CSV file
downloadCSV(csv.join("n"), filename);
}





share|improve this answer
























  • Thank you so much ! it solved my issue :)

    – Sri Ranjan
    Nov 20 '18 at 20:08











  • If solution is works then please mark as correct then future user easily find out correct answer

    – suresh bambhaniya
    Nov 21 '18 at 4:34
















1














you can use quotes to ignore comma



 function exportTableToCSV(filename) {
var csv = ;
var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {
var row = , cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)
row.push("""+cols[j].innerText+""");

csv.push(row.join(","));
}

// Download CSV file
downloadCSV(csv.join("n"), filename);
}





share|improve this answer
























  • Thank you so much ! it solved my issue :)

    – Sri Ranjan
    Nov 20 '18 at 20:08











  • If solution is works then please mark as correct then future user easily find out correct answer

    – suresh bambhaniya
    Nov 21 '18 at 4:34














1












1








1







you can use quotes to ignore comma



 function exportTableToCSV(filename) {
var csv = ;
var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {
var row = , cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)
row.push("""+cols[j].innerText+""");

csv.push(row.join(","));
}

// Download CSV file
downloadCSV(csv.join("n"), filename);
}





share|improve this answer













you can use quotes to ignore comma



 function exportTableToCSV(filename) {
var csv = ;
var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {
var row = , cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)
row.push("""+cols[j].innerText+""");

csv.push(row.join(","));
}

// Download CSV file
downloadCSV(csv.join("n"), filename);
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 19:35









suresh bambhaniyasuresh bambhaniya

880214




880214













  • Thank you so much ! it solved my issue :)

    – Sri Ranjan
    Nov 20 '18 at 20:08











  • If solution is works then please mark as correct then future user easily find out correct answer

    – suresh bambhaniya
    Nov 21 '18 at 4:34



















  • Thank you so much ! it solved my issue :)

    – Sri Ranjan
    Nov 20 '18 at 20:08











  • If solution is works then please mark as correct then future user easily find out correct answer

    – suresh bambhaniya
    Nov 21 '18 at 4:34

















Thank you so much ! it solved my issue :)

– Sri Ranjan
Nov 20 '18 at 20:08





Thank you so much ! it solved my issue :)

– Sri Ranjan
Nov 20 '18 at 20:08













If solution is works then please mark as correct then future user easily find out correct answer

– suresh bambhaniya
Nov 21 '18 at 4:34





If solution is works then please mark as correct then future user easily find out correct answer

– suresh bambhaniya
Nov 21 '18 at 4:34


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399609%2fhow-can-i-ignore-comma-inside-a-table-field-while-exporting-it-to-csv%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules