Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Last active February 21, 2018 11:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkermatt/a29e69c1780e75527fcad40c292e5c0d to your computer and use it in GitHub Desktop.
Save walkermatt/a29e69c1780e75527fcad40c292e5c0d to your computer and use it in GitHub Desktop.
Copy the data out of a Confluence table as CSV using Chrome devtools
function escapeAsCsv(str) {
// Double up double quotes and quote the entire string if necessary
if (str.includes(',') || str.includes('\n') || str.includes('"')) {
return '"' + str.replace(/"/g, '""') + '"';
}
return str;
}
// Export Confluence table as CSV
// Select the tbody element in Chrome devtools Elements panel then run the
// following in the Console to copy the contents of the table as CSV to the
// clipboard.
copy(jQuery('tr', $0).get().map(function (row) {
return jQuery('p', row).get().map(function (elm) {
return escapeAsCsv(elm.textContent);
}).join(',');
}).join('\n'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment