Swap the rows and columns of an HTML table

Recently I found myself converting a PDF into an EPUB. One challenge of such a task is to make the tables more compact to be able to fit in small screens. Sometimes, the best solution was to invert the rows and the columns of the table.

I looked on the web how to quickly swap rows and columns but most of the solutions involved CSS. The EPUB format does not handle CSS very well and I preferred to convert the table in pure HTML. The only solution I found was in this SO post. I added support for the TH tag, wrapped the algorithm into a nice page and published it as a ready-to-use tool.

So if you need a quick way get the transpose of an table in pure HTML, try my HTML table swapper! Note that it does not support “colspan” and “rowspan” yet.

You can also have a look at the source code.

About Nicolas Form

I'm Nicolas Form, multi-skill programmer, aesthete and joyful French guy. On this blog I share my tips and tutorials about programming and IT in general. I am freelance, so you can also contact me about a website, an Android app or any other software you need. Check my portfolio and drop me a line!
This entry was posted in Various. Bookmark the permalink.

Leave a Reply

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


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Swap the rows and columns of an HTML table

by Nicolas Form time to read: 1 min
0