Copy Table in Excel and Paste as a Markdown Table

copy-excel-paste-markdown
Copy a table from Excel or Google Sheets and paste it into the text box below to create a Markdown table. This online tool is made possible by Jonathan Hoyt’s innovative copy-excel-paste-markdown code. I’ve also modified his code to create a version that supports column alignments as explained below. Here are the steps:

  1. In Excel or Google Sheets, select a range of cells and press Ctrl+C to copy.
  2. Paste (Ctrl+V) into the text box below to create a Markdown table.

Additional Notes

  • If your table is wide, the resulting text in the text box will appear to be wrapped and misaligned; however, everything will align properly when you copy it from the text box and paste it into your Markdown editor/text editor.
  • I have written an article on using Markdown with Visual Studio Code if you are looking for a good Markdown editor.

Column Alignments

You can optionally specify column alignment information by prepending one of the following to the column heading names in Excel:

  • ^c – center alignment
  • ^r – right alignment
  • ^l – left alignment (the default)

For example: enter the following in Excel to right-align the second column and center-align the third column:

animal ^rweight ^ccolor
dog 30lb tan
dog 85lb black
cat 18lb calico

This will produce the following markdown table when pasted:

| animal | weight | color  |
|--------|-------:|:------:|
| dog    | 30lb   | tan    |
| dog    | 85lb   | black  |
| cat    | 18lb   | calico |

Enjoy!

Additional articles

Build an Amazing Markdown Editor Using Visual Studio Code and Pandoc
Guide to Installing Node.js on a Raspberry Pi
Debian apt Command Cheat Sheet
Consuming JSON Web Data Using Google Sheets

Follow @thisDaveJ (Dave Johnson) on Twitter to stay up to date with the latest tutorials and tech articles.

Share

55 thoughts on “Copy Table in Excel and Paste as a Markdown Table

  1. Hi,
    this seems very useful tool. THX! However, am I right assuming that you have a certain limit on number of rows and columns? I have 20×12 table, but when I try to paste nothing happens. Or are there other reasons why pasting the clipboard isnät possible?

    Thanks in advance, renzo

    1. Renzo, make sure your last field in the selection has some content, the trimming of data that is performed in this script, removes the last cell if it’s empty.

    1. I’m not aware of any specific limit, but I’m sure there’s a practical limit somewhere. Let me know if you find it!

    1. Beej, that’s an interesting edge case – thanks for sharing. I tested and see that the tool can handle blank columns if they are in the middle of the table. It will ignore blank columns if they are the outermost left or right columns. As a workaround, if you wish to include a blank outermost left column, for example, temporarily include a single character such as “x” in any cell in the left column in Excel/Sheets before pasting it into the textbox on this web page. You can then remove the “x” in the resulting markdown syntax and you will have achieved a blank left column.

  2. Thank you for this great tool, but it doesn’t work with me, why? I’m using google spreadsheets on firefox, and I copyed and paste and nothing happens.

    1. That would be a cool feature. Unfortunately, the information copied to the clipboard from Excel/Sheets does not contain formatting such as bold/italic or embedded URLs from links. Everything is copied as plain text. Bold/italics/links can be accomplished using Markdown syntax in Excel/Sheets before copying over. For example, enter “**bold text**” in an Excel cell before copying the cells over and pasting into the text box.

  3. I also works when copying from SQL Server Management Studio (SSMS) results, including “Copy with Headers”.

    1. Oren, thanks for sharing! The code works with anything pasted from the clipboard that utilizes a TSV (tab-separated value) format so it’s good to know that SSMS results are included in that category too.

  4. Hi Dave –

    First, this has been a massively useful tool – I don’t understand why this function isn’t native to Excel.

    Is it possible to get the table header row formatted with ||’s somehow, such as:

    || Name || Title || Email Address ||
    |————–|——-|—————-|
    | Jane Atler | CEO | [email protected] |
    | John Doherty | CTO | [email protected] |
    | Sally Smith | CFO | [email protected] |

    1. I don’t quite understand what you are trying to achieve with the double pipe characters. Feel free to expand on your use case/end objective. In markdown, you can escape pipe characters using “\|”, to ensure they appear, for example, when the markdown is rendered as HTML. By adding “\|” (without the quotes) at the desired locations in Excel or Google Sheets, the tool on this page will ensure they appear when pasted into the textbox.

  5. Many, many thanks … I had a pit in my stomach when the boss said “Oh, just stick that on the wiki page” … but thankfully the first hit on the search was your page, and it worked a treat.

    I’ve mega-impressed with this

    1. Steve – thanks for the positive feedback. Jonathan Hoyt deserves most of the credit here since he created the original version and I’m doing my small part by adding a couple features and hosting it. Glad it’s adding value for you!

  6. Greetings from the city of San Diego, and thank you for your positive contribution to developer tools on the web!

Leave a Reply

Your email address will not be published. Required fields are marked *