mHelpMe
mHelpMe

Reputation: 6668

create html table and have table header span more than one column

I am sending an e-mail from excel using outlook. For the body of the e-mail I am making use of HTML.

I had a table which was working fine. However I have been asked to add a header above the current header of my table. The header is called "Premium / (Discount)". So the code below does that fine. However I would like for this header to span across two columns and centre.

I am using the line below but it is not working, why?

"<th colspan='2'>Premium /(Discount)</th>


msg = "<table style='font-size: 12pt;'><tr><th>&nbsp</th><th>&nbsp</th><th>&nbsp</th><th>&nbsp</th><th>&nbsp</th><th>&nbsp</th>" & _
    "<th colspan='2'>Premium /(Discount)</th><th>&nbsp</th><th>&nbsp</th><th>&nbsp</th><th>&nbsp</th></tr>" & _
    "<tr><th align='left'>Fund</th><th>&nbsp;</th>" & _
    "<th align='left'>Market Spread %</th><th>&nbsp;</th>" & _
    "<th align='left'>Tolerance</th><th>&nbsp;</th>" & _
    "<th align='left'>Bid %</th><th>&nbsp;</th>" & _
    "<th align='left'>Ask %</th><th>&nbsp;</th>" & _
    "<th align='left'>Tolerance</th><th>&nbsp;</th>" & _
    "<th align='left'>Extra Notes</th><th>&nbsp;</th></tr>"

Upvotes: 0

Views: 355

Answers (2)

Anshul
Anshul

Reputation: 92

<html>
<body><table style='font-size: 12pt;'><tr>
    <th></th><th></th><th></th><th colspan='2'>Premium /(Discount)</th><th></th><th></th></tr>
    <tr><th align='left'>Fund</th>
    <th align='left'>Market Spread %</th>
    <th align='left'>Tolerance</th>
    <th align='left'>Bid %</th>
    <th align='left'>Ask %</th>
    <th align='left'>Tolerance</th>
    <th align='left'>Extra Notes</th></tr>
</table>
</body>
</html>

This will help "Premium / (Discount)" header to centre over the Bid % and Ask % column headers no matter the width of the columns.

NOTE: It won't center it the whole table.

Upvotes: 1

ZeusInTexas
ZeusInTexas

Reputation: 307

According to your code, your table has a total of 14 columns, so your colspan should be of 14 instead of 2.

Also, you're using some of these columns as space : <th>&nbsp;</th>. Note that you can do it better by adding a cell-padding value (in pixels) to your <table>, so your table will look like this : http://cssdeck.com/labs/qyh7ytdi.

Here is the code that should do the trick:

msg = "<table style='font-size: 12pt;' cellpadding='5'>" & _
      "<tr><th colspan='3'></th><th colspan='2'>Premium /(Discount)</th></tr>" & _
      "<tr><th align='left'>Fund</th>" & _
      "<th align='left'>Market Spread %</th>" & _
      "<th align='left'>Tolerance</th>" & _
      "<th align='left'>Bid %</th>" & _
      "<th align='left'>Ask %</th>" & _
      "<th align='left'>Tolerance</th>" & _
      "<th align='left'>Extra Notes</th></tr>"

Upvotes: 2

Related Questions