How to convert a table from an Excel file into a HTML table without poor data formatting?

Let’s say you have an Excel file you need to convert to HTML to put it on the web site. Below I’ll present some reasons why copy & paste or saving as HTML (hypertext markup language) simply doesn’t work fine and a solution to do convert it fine.

The situation described here implies that you have a HTML page, a table that only changes its data (so it doesn’t change table header or anything else in the page, just the numbers inside the table) and you need to make a lot of changes fast.

Sure, the easy option would be saving the file in Microsoft Excel software, and dealing with the way it looks afterwards. Or just a copy & paste from Excel to a CMS (Content Management System).

Say we have this file.

Unfortunately, whether you do copy & paste from Excel or you save as HTML, the result is this.

As you can see, a lot specifications and numbers, which make the tables difficult to manipulate:
<td align=”right”>1</td>
<tr height=”21″>
<td width=”47″>Losses</td>

Saving the file in Excel as HTML doesn’t yield any better results.

The code looks even uglier:
<tr height=20 style=’height:15.0pt’>
<td height=20 style=’height:15.0pt’></td>
<td>Game A</td>
<td align=right>2</td>
<td align=right>1</td>
<td align=right>1</td>
<td align=right>3</td>
<td align=right>0</td>
<td align=right>4</td>

What to do?

One solution would be taking the code and using a solution to strip the unnecessary code (a HTML editor, a search & replace macro in Word, etc.).

The solution below is different: I will take the data in Excel, place it in Word, run a macro, and get a valid code.

The very first thing to do is open up this file. You should either allow macros to run if you’re on Microsoft Office 2007, or set the proper security level to allow macros (Tools => Options => Security => Macro Security will work for 2003 version).

Then you should copy the macros that are attached to the file to your local computer. How to do that?

In Word 2003: Tools => Macro => Macros => Organizer
In Word 2007: View => Macros => View macros => Organizer

Here you copy from left to right:

That’s it, now you have macros in your Word software.

(optional) You can assign an icon to the toolbar for fast launch of the macro you’ve just copied. For this, click the drop-down option in the ribbon, and select More commands (for Office 2007):

Or right-click a toolbar and select „Customize toolbars”;

For Office 2007, see below:

and just copy from left to right and assign an icon;

For Office 2003, you go to Commands, then macros, and via drag & drop, you drag the macro to the toolbar, rename it and give it an icon.

Details here.

So, after the macro has been installed, see the solution:
1. Select the table in Microsoft Excel and Copy;

2. In Microsoft Word either do Paste (a small arrow underneath the button) => Paste Special in Microsoft Word 2007 or Edit => Paste Special … in earlier versions; Ctrl + Alt + V also works just fine;

Select Unformatted text, Ok;

3. Launch the macro via either the toolbar button or View => Macros => View macros => Select „Replace_table” => Run (for Office 2007) or Tools => Macros => Macro => Select the macro => Run (for Office 2003);

4. Copy the code into the CMS.

The code will look like this:

And this is how I would make a code based on an Excel file.

Share on WhatsAppLinks giving error?

Lasă un comentariu

Rules for commenters »

Puteți folosi Gravatar pentru a adăuga avatar (imagine comentarii).