We have a wiki at work that we use for documentation called Confluence. It has the ability to export pages to Word or PDF, but a lacking feature is the ability to take a table and export it for Excel. So, I decided to create a bookmarklet that will allow you to select an HTML table on any web page and create a CSV file from that table that can be downloaded to your machine. Below is the bookmarklet. Just drag it to your bookmarks toolbar. Then give it a shot by clicking the bookmarklet and the below example table should get a link right before it that says “Export to CSV”. Click that link and you will be prompted to download the CSV version of that table. Let me know if it is useful for you.
On thing of note, this will not work correctly in Internet Explorer 9 and below as IE will not allow data uri’s for anything other than images.
Bookmarklet:
Export to CSV <- drag this to your bookmarks toolbar
Update:
05/08/2019 – Enhanced to not kill line breaks.
09/16/2016 – Now works with IE 10+.
04/19/2016 – Fixed issue with tables that have header cells not on top.
Example Table:
Heading 1 | Heading 2 | Heading 3 | Heading 4 | Heading 5 | Heading 6 |
---|---|---|---|---|---|
Data 1, 1 | Data 1, 2 | Data 1, 3 | Data 1, 4 | Data 1, 5 | Data 1, 6 |
Data 2, 1 | Data 2, 2 | Data 2, 3 | Data 2, 4 | Data 2, 5 | Data 2, 6 |
Data 3, 1 | Data 3, 2 | Data 3, 3 | Data 3, 4 | Data 3, 5 | Data 3, 6 |
Data 4, 1 | Data 4, 2 | Data 4, 3 | Data 4, 4 | Data 4, 5 | Data 4, 6 |
Data 5, 1 | Data 5, 2 | Data 5, 3 | Data 5, 4 | Data 5, 5 | Data 5, 6 |
Data 6, 1 | Data 6, 2 | Data 6, 3 | Data 6, 4 | Data 6, 5 | Data 6, 6 |
Bookmarklet Source:
javascript:(function(){ function getJavaScript(url, success) { var script = document.createElement('script'); script.src = url; var head = document.getElementsByTagName('head')[0], done = false; script.onload = script.onreadystatechange = function(){ if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { done = true; success(); script.onload = script.onreadystatechange = null; head.removeChild(script); } }; head.appendChild(script); } function addCSVLinks() { jQuery('.csvLink').remove(); jQuery('table').each(function(index){ jQuery(this).attr('data-csvtable', index).before('<a href="#" class="csvLink" data-forcsvtable="' + index + '">Export to CSV</a>'); }); jQuery('.csvLink').click(function(){ var text = ''; var csvTableIndex = jQuery(this).attr('data-forcsvtable'); jQuery('table[data-csvtable="' + csvTableIndex + '"] tr').each(function(){ jQuery('td, th', this).each(function(index){ if(index != 0) { text += ','; } text += '"' + formatedText(jQuery(this).html()) + '"'; }); text += '\r\n'; }); jQuery('.csvLink').remove(); downloadCSVFile('TableExport.csv', 'text/csv', text); }); } function formatedText(html) { var ret = html; //replace line breaks ret = ret.replace(/\n/g, ' '); //replace tabs ret = ret.replace(/\t/g, ' '); //replace multiple spaces ret = ret.replace(/\s+/g, ' '); //Fix html encoded characters ret = decodeHtml(ret); //Deal with lines breaks and paragraphs ret = ret.replace(/<br>/ig, '\n<br>'); ret = ret.replace(/<br/ig, '\n<br '); ret = ret.replace(/<p/ig, '\n<p '); //Deal with quotes ret = ret.replace(/"/ig, '""'); //Deal first character being line break ret = ret.replace(/^\n/, ''); //Remove HTML tags ret = ret.replace(/(<([^>]+)>)/ig,""); return ret; } function decodeHtml(html) { var txt = document.createElement('textarea'); txt.innerHTML = html; return txt.value; } function downloadCSVFile(filename, mime, text) { if (window.navigator.msSaveOrOpenBlob){ // IE 10+ var blob = new Blob([decodeURIComponent(encodeURI(text))], { type: 'text/csv;charset=utf-8' }); window.navigator.msSaveBlob(blob, filename); } else { var pom = document.createElement('a'); pom.setAttribute('href', 'data:' + mime + ';charset=utf-8,' + encodeURIComponent(text)); pom.setAttribute('download', filename); document.body.appendChild(pom); pom.click(); document.body.removeChild(pom); } } if(typeof jQuery == 'undefined') { getJavaScript( '//code.jquery.com/jquery-latest.min.js', function(){ addCSVLinks(); } ) } else { addCSVLinks(); } })();
Nice one, made my life easier with confluence.
Glad to hear it.
This is a great tool and has made my life so much easier!!
Great job!
Nice plugin..!!
Very nice thank you
Great bookmarklet very useful. Thank you
This is great! How have I not seen this before??
(the captcha sucks – too hard for me)
Really usefull to download Tables from a Confluence Page… Thank you for this
Great ! thanks
Man, this is great ! Thank you so much !!
Ditto! works like a charm! thank you for saving my day.
Good work ! Appreciate it !
Thanks! Appreciate it.
Hello, when I click on the Export to CSV link (after clicking the bookmarklet), the resulting csv file only contains the first column.
All of my tables have only two columns with the left column acting as a “header” and right column containing data/values.
I am using Chrome (on Windows), with Confluence 5.8.8.
Any help would be appreciated. Cheers!
I’ve got the same problem. In Confluence, only the header columns are exported.
Fixed the issue and it should work fine now.
Thanks for the input. I have fixed the issue and it should now work as expected.
Thanks for this — works as advertised with OS X Chrome.
Thoughts on why it doesn’t work with Safari?
Thanks again!
There seems to be a problem with exporting tables that contain merged cells.
I have a LOT of merged cells in the table I want to export, since it would be very confusing to look at otherwise. But the bookmarklet doesn’t seem to be very friendly with merged cells. I doubt that can be fixed, can it?
Works just fine for “normal” tables though, so thanks anyways
Hmm … not sure how the best way would be to handle tables with merged cells as those would not translate nicely to csv. I’ll think on it.
Brilliant. This makes getting data out of Confluence “Page property report” macros a painless task. Thank you!
hello!
i try it in confluence and have duplicate title row
please find this error in screenshot
http://savepic.ru/11416433.jpg
I also have the same issue I get a duplicate row
Thank you very much. You saved my bacon. I am a non-technical PM and was gnashing my teeth trying to sum up our progress for management until I found your utility.
Hey there,
great job! Just one thing: could you publish a version with “;” as separator instead of “,”? I found the part in the code but can’t figure out how to change it in the boomarklet 🙁
Best Regards
Dmitry
I thrashed for a bit trying to find a solution until I found your bookmarklet. Worked great with Chrome Version 53.0.2785.143 (64-bit) — thank you!
This is wonderful, exactly what I went to the Google to find! Thank you 🙂
Thanks a lot for this. It saved a lot of time for me
Perfect! This works great. Thank you!
OMG – This made my day – thank you so much!!!
Genius!!!!
I seem to have encoding issues. My confluence is set to UTF-8 in general settings, and if I understand it correctly, your script is supposed to export UTF-8, but the export clearly has some artifacts, and it does not match what I see on the screen in confluence. Even s are replaced with  . Is there a way you could help me troubleshoot this?
With ‘s’ I meant non-breaking spaces, which come out of confluence when cells are NULL.
Similar here; superscripts and math symbols are garbled; still saves a tonne of work but it would be great if there was a function that could be easily enhanced with known search/replace requirements post-export.
The BOM modification referenced further down this comment block fixes the garbled math symbols. Makes no difference for the super/subscript issues; they come through as regular letters on the same baseline as the rest of the content.
Found this through a search. Really useful – thanks
Super useful, my friend:) Well done!
Great little tool! Thank you for sharing!
Hey!
Brilliant! Helped me a lot. I had to add a BOM mark to get my Japanese characters to play nicely in the exported CSV though. Also added it into a script block so it can be neatly pasted into an html module and dropped in the end of a confluence page.
https://gist.github.com/ddikman/c915abaa1ea63606ebe33fa93a379d7a
Hi. This has been very useful, but for some reason I now cannot “drag and drop” the export to cvs bookmarklet to my favorite bar. I am using IE, but in other browsers I was unable also. This was not a problem previously. Do you have any suggestions for help or where I can find something similar.
This is a great tool, thank you!
Is there a way for this bookmarklet to include the links that might exist in the tables as well?
That is a great little function, thanks!
Does the input data stay local to the browser ? I’d like to use this, but the data I work with is confidential and cannot be transmitted outside of the corporate network and approved partners. I noticed this hostname in the script, which is why I asked – code.jquery.com
Yes, it stays local. That is simply injecting jQuery into the page to make it easier to work with if jQuery is not already in the page. Nothing is transmitted anywhere.
Thank you. I’m sure you get this all the time (judging by the comments), but your little solution is awesome. Awe some. It should be two words, it’s that good!
This worked like a charm, thank you!
Thank you very much. This works for me. it really helps my work!
You’re welcome.
Many thanks for this great bookmarklet. It helps me ervery day at work and it saves me a lot of time.
You’re welcome.
You’re an angel. Thank you!
Glad it helps out.
WOW!!!! 🙂 Super useful! Thank you!!!
Your welcome.
wow !! great stuff ! Thank you very much for sharing!
You’re welcome. Hope it helps.
Thank you so much, very helpful.
I have many tables on one page, any way to click once and get all tables in different excel worksheets in same excel workbook.
Unfortunately, that’s not really possible with CSV. It has no concept of sheets and workbooks.
This is great! But I get many blank cells in the output (where data should be). I wonder what could be causing some cells to output as nothing.
Hmm. Without knowing what the data is I could not say.
I think if its a drop down or checklist it doesn’t appear correctly. In my case the Status column didn’t show up at all.
Very Nice. Thank you. It really helped. Been struggling for many months
AMAZING!!!!
Just brilliant and generous, thanks Davin
You are welcome.
Simple and brilliant useful on quite a few websites that look built in export functions. Cheers!
Glad you find it useful.
I have been using this for 5 years now, it is great, it simplifies my day to day live big time.
Thank you!
Wow! That’s awesome. Thanks for letting me know. I appreciate it.
Hello Davin! Could you clarify, why it could cause the following error (I’m using Chrome?
Refused to load the script ‘https://code.jquery.com/jquery-latest.min.js’ because it violates the following Content Security Policy directive: “script-src ‘self’ ‘unsafe-inline’ ‘unsafe-eval’ https://*.google.com https://*.googleapis.com https://*.googlesyndication.com https://*.googleadservices.com https://*.gravatar.com https://*.gstatic.com https://*.wp.com https://wordpress.com https://s.w.org https://www.googletagservices.com https://googleads.g.doubleclick.net https://cdn.ampproject.org https://www.googletagmanager.com https://www.google-analytics.com“. Note that ‘script-src-elem’ was not explicitly set, so ‘script-src’ is used as a fallback.
Hmm. Sounds like the site has a content security policy that is blocking the bookmarklet. A content security policy is a set of instructions that a website sends to your browser that says “For my site only accept javascript/css/images/etc for this site from these locations.” It’s a security mechanism meant to protect users of a site from cross site scripting attacks. What site were you trying it on?
Hey Davin, you’re a doll for this. So incredibly useful and helpful, thank you so much for spending your time to make this and share it freely. I appreciate it very much and you’ve inspired me to follow in your footsteps and contribute in such a way to the developer community. I wish you the best!
This saved me hours, thank you.
This is a life saver ..Have been using it for years now ..Thank You.
You are welcome.
awesome !!!
Love love love this tool. We have been using it for years. Question: any idea how to make checkboxes [√] download in some form? It would be nice to have a something like a “1”= checked and “0” = not checked. Anything to differentiate checked vs. not checked.
Thanks for the great tool. Save me a lot of hassle.
Great Tool and Saved me a lot of time. I don’t know why Confluence does not provide this functionality without charging.
Doesn’t work well if you have cells that span multiple cells or “Merge Cells” as it’s called in Excel
Yeah, unfortunately there is no way to do merged cells in CSV files. So that is a limitation that this will not solve.
I was hoping to speak with you about this bookmarklet – it is throwing errors in our dev envt so i can’t get it to work – I also sent you a LinkedIn request so that I could ask you about this. Hopefully you get this reply. Many thanks in advance, Steve Whittle
Excellent! Huge time-saver!
Hi Chris! Just wondering what is the latest version of Confluence you got this working in? .12? Tks
Hi Chris! If you installed this and got it working for yourself, what version of Confluence are you using that the bookmarklet worked with?
Hi,
I am unable to save the link Export to CSV on Confluence page, is it possible to save it permanently or does it required to every time click the book mark when I want to export ?
I am not able to share with my team members to use it due to to this.
any suggestion ?
Thanks
Good Initiative! Thanks
This tool is great! I do have 1-2 people who aren’t seeing the columns properly in the excel spreadsheet (eg. if it’s 3 columns in Confluence, it’s showing all in 1 column in the Excel spreadsheet). Wondering if this has happened to others or if it’s just an importing settings issue in Excel for this person?
This is really great! Thank you for doing it. I’m noticing in the code that the csv file should be named “TableExport.csv” but I’m getting “download.csv”.
This is really great! Thank you for doing it. I’m noticing in the code that the csv file should be named “TableExport.csv” but I’m getting “download.csv”. Am I doing something wrong?
Hi! Just wondering if this bookmarklet works with vers 7.19.12?
Amazing! Thank you so much!
Appreciate this! <3