I'm new to this field.
I have a table in an Excel file (xlsx). Using C#, I save it as html:
`worksheet.SaveToHtml("the html file path destination");`
Then I read the html file:
`String htmlCode = File.ReadAllText("the html file path", Encoding.Default);`
Then I just put it to the email body like this:
mail.Body = "<BR/><font size=2 ...." + htmlCode + ".... </body>";
The table is supposed to look this way:
But when the email is opened in Outlook, it looks like this:
The columns are significantly smaller in width.
How to fix this? I don't want to directly code the html in the C#.
UPDATE
This is how the html using WorkSheet.SaveToHtml looks like. I need to find what to change/add to make this table look right in Outlook.
<html>
<head>
<style type="text/css">table{border-collapse:collapse;table-layout:fixed;border-spacing:0;empty-cells:show}
.X0{color:rgb(0,32,96);font-family:Calibri;font-size:11pt;background-color:rgb(218,238,243);border-top-color:000000;border-top-style:solid;border-top-width:2;border-bottom-color:000000;border-bottom-style:solid;border-bottom-width:2;border-left-color:000000;border-left-style:solid;border-left-width:2;border-right-color:000000;border-right-style:solid;border-right-width:2;font-weight:bold;vertical-align:center;text-align:center;word-wrap:break-word;height:21;}
.X1{color:rgb(0,32,96);font-family:Calibri;font-size:11pt;background-color:rgb(218,238,243);border-right-style:solid;border-right-width:2;border-right-color:000000;border-top-color:000000;border-top-style:solid;border-top-width:2;border-bottom-color:000000;border-bottom-style:solid;border-bottom-width:2;border-left-color:000000;border-left-style:solid;border-left-width:2;font-weight:bold;vertical-align:center;text-align:center;word-wrap:break-word;height:21;}
.X2{color:rgb(0,32,96);font-family:Calibri;font-size:11pt;background-color:rgb(218,238,243);border-top-color:000000;border-top-style:solid;border-top-width:2;border-bottom-color:000000;border-bottom-style:solid;border-bottom-width:2;border-right-color:000000;border-right-style:solid;border-right-width:2;font-weight:bold;vertical-align:center;text-align:center;word-wrap:break-word;height:21;}
.X3{color:rgb(0,32,96);font-family:Calibri;font-size:11pt;background-color:rgb(218,238,243);border-bottom-style:solid;border-bottom-width:2;border-bottom-color:000000;border-top-color:000000;border-top-style:solid;border-top-width:2;border-left-color:000000;border-left-style:solid;border-left-width:2;border-right-color:000000;border-right-style:solid;border-right-width:2;font-weight:bold;vertical-align:center;text-align:center;word-wrap:break-word;height:21;}
.X4{color:rgb(0,32,96);font-family:Calibri;font-size:11pt;background-color:rgb(218,238,243);border-bottom-color:000000;border-bottom-style:solid;border-bottom-width:2;border-left-color:000000;border-left-style:solid;border-left-width:2;border-right-color:000000;border-right-style:solid;border-right-width:2;font-weight:bold;vertical-align:center;text-align:center;word-wrap:break-word;height:21;}
.X5{color:rgb(0,32,96);font-family:Calibri;font-size:11pt;background-color:rgb(218,238,243);border-bottom-color:000000;border-bottom-style:solid;border-bottom-width:2;border-right-color:000000;border-right-style:solid;border-right-width:2;font-weight:bold;vertical-align:center;text-align:center;word-wrap:break-word;height:21;}
.X6{color:rgb(0,32,96);font-family:Calibri;font-size:11pt;background-color:rgb(255,255,255);border-bottom-color:000000;border-bottom-style:solid;border-bottom-width:2;border-left-color:000000;border-left-style:solid;border-left-width:2;border-right-color:000000;border-right-style:solid;border-right-width:2;vertical-align:center;text-align:general;word-wrap:break-word;height:21;}
.X7{color:rgb(0,32,96);font-family:Calibri;font-size:11pt;background-color:rgb(255,255,255);border-bottom-color:000000;border-bottom-style:solid;border-bottom-width:2;border-right-color:000000;border-right-style:solid;border-right-width:2;vertical-align:center;text-align:right;word-wrap:break-word;height:21;}</style>
</head>
<body>
<table cellspacing="0">
<Col width="167" />
<Col width="109" />
<Col width="104" />
<Col width="91" />
<Col width="85" />
<Col width="65" />
<tr>
<td class="X0">
<div style="width:163px !Important;width:167px;" />
</td>
<td COLSPAN="2" class="X1">11 11 11</td>
<td ROWSPAN="2" class="X3">11 11</td>
<td COLSPAN="2" class="X1">11 11</td>
</tr>
<tr>
<td class="X4">
<div style="width:163px !Important;width:167px;" />
</td>
<td class="X5">11</td>
<td class="X5">11</td>
<td class="X5">11</td>
<td class="X5">11</td>
</tr>
<tr>
<td class="X6">a aa</td>
<td class="X7">b</td>
<td class="X7">b</td>
<td class="X7">b</td>
<td class="X7">b</td>
<td class="X7">b</td>
</tr>
<tr>
<td class="X6">c cc ccc</td>
<td class="X7">d</td>
<td class="X7">d</td>
<td class="X7">d</td>
<td class="X7">d</td>
<td class="X7">d</td>
</tr>
<tr>
<td class="X6">e ee eee</td>
<td class="X7">f</td>
<td class="X7">f</td>
<td class="X7">f</td>
<td class="X7">1f</td>
<td class="X7">f</td>
</tr>
</table>
</body>
</html>
Thanks for all the comments.
I finally got the desired table in Outlook using Save As in Excel. Save as type Web Page (htm, html). Both htm and html work.
But by default the table align was center. I just need to change it to left and everything's perfect.
Here's the html table that renders correctly in both Outlook and WLM (I haven't tested it in other email)