Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Last active May 28, 2025 09:05
Show Gist options
  • 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'));
@indika-dev
Copy link

copy with headers

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 including headers
// 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) {
      if (jQuery("th", row).length > 0) {
        // If the row is a header, return the header text
        return jQuery("th", row).get().map(function (elm) {
            return escapeAsCsv(elm.textContent);
          }).join(",");
      } else {
        return jQuery("td", 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