Outlook и Windows Live Mail по-разному отображают HTML-таблицу (Outlook показывает нежелательную, WLM показывает желаемую) - PullRequest
0 голосов
/ 19 сентября 2018

Я новичок в этой области.

У меня есть таблица в файле Excel (xlsx).Используя C #, я сохраняю его как html:

`worksheet.SaveToHtml("the html file path destination");`  

Затем я читаю html-файл:

`String htmlCode = File.ReadAllText("the html file path", Encoding.Default);`  

Затем я просто помещаю его в тело письма следующим образом:

mail.Body = "<BR/><font size=2 ...." + htmlCode + ".... </body>";

Таблица должна выглядеть следующим образом:

the desired (how it looks in Excel and WLM)

Но когда электронное письмо открывается в Outlook, оно выглядит так:

how it looks in Outlook

Ширина столбцов значительно меньше.
Как это исправить?Я не хочу напрямую кодировать HTML в C #.

UPDATE
Вот так выглядит HTML с использованием WorkSheet.SaveToHtml.Мне нужно найти, что изменить / добавить, чтобы эта таблица выглядела правильно в 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&nbsp;11&nbsp;11</td>
        <td ROWSPAN="2" class="X3">11&nbsp;&nbsp;11</td>
        <td COLSPAN="2" class="X1">11&nbsp;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&nbsp;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&nbsp;cc&nbsp;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&nbsp;ee&nbsp;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>

1 Ответ

0 голосов
/ 20 сентября 2018

Спасибо за все комментарии.
Я наконец-то получил нужную таблицу в Outlook, используя Save As в Excel.Сохранить как тип веб-страницы (htm, html).Оба htm и html работают.
Но по умолчанию выравнивание таблицы было по центру.Мне просто нужно изменить его влево, и все идеально.

Вот HTML-таблица, которая корректно отображается как в Outlook, так и в WLM (я не проверял ее в другой электронной почте)

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

<head>
  <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
  <meta name=ProgId content=Excel.Sheet>
  <meta name=Generator content="Microsoft Excel 14">
  <link rel=File-List href="tabel_transaksi_saham_copy_files/filelist.xml">
  <style id="tabel_transaksi_saham_copy_879_Styles">
    <!--table {
      mso-displayed-decimal-separator: "\.";
      mso-displayed-thousand-separator: "\,";
    }
    
    .xl15879 {
      padding-top: 1px;
      padding-right: 1px;
      padding-left: 1px;
      mso-ignore: padding;
      color: black;
      font-size: 11.0pt;
      font-weight: 400;
      font-style: normal;
      text-decoration: none;
      font-family: Calibri, sans-serif;
      mso-font-charset: 0;
      mso-number-format: General;
      text-align: general;
      vertical-align: bottom;
      mso-background-source: auto;
      mso-pattern: auto;
      white-space: nowrap;
    }
    
    .xl63879 {
      padding-top: 1px;
      padding-right: 1px;
      padding-left: 1px;
      mso-ignore: padding;
      color: #002060;
      font-size: 11.0pt;
      font-weight: 700;
      font-style: normal;
      text-decoration: none;
      font-family: Calibri, sans-serif;
      mso-font-charset: 0;
      mso-number-format: General;
      text-align: center;
      vertical-align: middle;
      border: 1.0pt solid windowtext;
      background: #DAEEF3;
      mso-pattern: black none;
      white-space: normal;
    }
    
    .xl64879 {
      padding-top: 1px;
      padding-right: 1px;
      padding-left: 1px;
      mso-ignore: padding;
      color: #002060;
      font-size: 11.0pt;
      font-weight: 700;
      font-style: normal;
      text-decoration: none;
      font-family: Calibri, sans-serif;
      mso-font-charset: 0;
      mso-number-format: General;
      text-align: center;
      vertical-align: middle;
      border-top: none;
      border-right: 1.0pt solid windowtext;
      border-bottom: 1.0pt solid windowtext;
      border-left: 1.0pt solid windowtext;
      background: #DAEEF3;
      mso-pattern: black none;
      white-space: normal;
    }
    
    .xl65879 {
      padding-top: 1px;
      padding-right: 1px;
      padding-left: 1px;
      mso-ignore: padding;
      color: #002060;
      font-size: 11.0pt;
      font-weight: 700;
      font-style: normal;
      text-decoration: none;
      font-family: Calibri, sans-serif;
      mso-font-charset: 0;
      mso-number-format: General;
      text-align: center;
      vertical-align: middle;
      border-top: none;
      border-right: 1.0pt solid windowtext;
      border-bottom: 1.0pt solid windowtext;
      border-left: none;
      background: #DAEEF3;
      mso-pattern: black none;
      white-space: normal;
    }
    
    .xl66879 {
      padding-top: 1px;
      padding-right: 1px;
      padding-left: 1px;
      mso-ignore: padding;
      color: #002060;
      font-size: 11.0pt;
      font-weight: 400;
      font-style: normal;
      text-decoration: none;
      font-family: Calibri, sans-serif;
      mso-font-charset: 0;
      mso-number-format: General;
      text-align: general;
      vertical-align: middle;
      border-top: none;
      border-right: 1.0pt solid windowtext;
      border-bottom: 1.0pt solid windowtext;
      border-left: 1.0pt solid windowtext;
      mso-background-source: auto;
      mso-pattern: auto;
      white-space: normal;
    }
    
    .xl67879 {
      padding-top: 1px;
      padding-right: 1px;
      padding-left: 1px;
      mso-ignore: padding;
      color: #002060;
      font-size: 11.0pt;
      font-weight: 700;
      font-style: normal;
      text-decoration: none;
      font-family: Calibri, sans-serif;
      mso-font-charset: 0;
      mso-number-format: General;
      text-align: center;
      vertical-align: middle;
      border-top: 1.0pt solid windowtext;
      border-right: none;
      border-bottom: 1.0pt solid windowtext;
      border-left: 1.0pt solid windowtext;
      background: #DAEEF3;
      mso-pattern: black none;
      white-space: normal;
    }
    
    .xl68879 {
      padding-top: 1px;
      padding-right: 1px;
      padding-left: 1px;
      mso-ignore: padding;
      color: #002060;
      font-size: 11.0pt;
      font-weight: 700;
      font-style: normal;
      text-decoration: none;
      font-family: Calibri, sans-serif;
      mso-font-charset: 0;
      mso-number-format: General;
      text-align: center;
      vertical-align: middle;
      border-top: 1.0pt solid windowtext;
      border-right: 1.0pt solid windowtext;
      border-bottom: 1.0pt solid windowtext;
      border-left: none;
      background: #DAEEF3;
      mso-pattern: black none;
      white-space: normal;
    }
    
    .xl69879 {
      padding-top: 1px;
      padding-right: 1px;
      padding-left: 1px;
      mso-ignore: padding;
      color: #002060;
      font-size: 11.0pt;
      font-weight: 700;
      font-style: normal;
      text-decoration: none;
      font-family: Calibri, sans-serif;
      mso-font-charset: 0;
      mso-number-format: General;
      text-align: center;
      vertical-align: middle;
      border-top: 1.0pt solid windowtext;
      border-right: 1.0pt solid windowtext;
      border-bottom: none;
      border-left: 1.0pt solid windowtext;
      background: #DAEEF3;
      mso-pattern: black none;
      white-space: normal;
    }
    
    -->
  </style>
</head>

<body>
  <!--[if !excel]>&nbsp;&nbsp;<![endif]-->
  <!--The following information was generated by Microsoft Excel's Publish as Web
Page wizard.-->
  <!--If the same item is republished from Excel, all information between the DIV
tags will be replaced.-->
  <!----------------------------->
  <!--START OF OUTPUT FROM EXCEL PUBLISH AS WEB PAGE WIZARD -->
  <!----------------------------->

  <div id="tabel_transaksi_saham_copy_879" align=left x:publishsource="Excel">

    <table border=0 cellpadding=0 cellspacing=0 width=615 style='border-collapse:
 collapse;table-layout:fixed;width:462pt'>
      <col width=166 style='mso-width-source:userset;mso-width-alt:6070;width:125pt'>
      <col width=108 style='mso-width-source:userset;mso-width-alt:3949;width:81pt'>
      <col width=103 style='mso-width-source:userset;mso-width-alt:3766;width:77pt'>
      <col width=90 style='mso-width-source:userset;mso-width-alt:3291;width:68pt'>
      <col width=84 style='mso-width-source:userset;mso-width-alt:3072;width:63pt'>
      <col width=64 style='width:48pt'>
      <tr height=21 style='height:15.75pt'>
        <td height=21 class=xl63879 width=166 style='height:15.75pt;width:125pt'>&nbsp;</td>
        <td colspan=2 class=xl67879 width=211 style='border-right:1.0pt solid black;
  border-left:none;width:158pt'>11</td>
        <td rowspan=2 class=xl69879 width=90 style='border-bottom:1.0pt solid black;
  width:68pt'>11</td>
        <td colspan=2 class=xl67879 width=148 style='border-right:1.0pt solid black;
  border-left:none;width:158pt'>11</td>
      </tr>
      <tr height=21 style='height:15.75pt'>
        <td height=21 class=xl64879 width=166 style='height:15.75pt;width:125pt'>&nbsp;</td>
        <td class=xl65879 width=108 style='width:81pt'>11</td>
        <td class=xl65879 width=103 style='width:77pt'>11</td>
        <td class=xl65879 width=84 style='width:63pt'>11</td>
        <td class=xl65879 width=64 style='width:48pt'>11</td>
      </tr>
      <tr height=21 style='height:15.75pt'>
        <td height=21 class=xl66879 align=right width=166 style='height:15.75pt;
  width:125pt'>11</td>
        <td class=xl66879 align=right width=108 style='border-left:none;width:81pt'>11</td>
        <td class=xl66879 align=right width=103 style='border-left:none;width:77pt'>11</td>
        <td class=xl66879 align=right width=90 style='border-left:none;width:68pt'>11</td>
        <td class=xl66879 align=right width=84 style='border-left:none;width:63pt'>11</td>
        <td class=xl66879 align=right width=64 style='border-left:none;width:48pt'>11</td>
      </tr>
      <tr height=21 style='mso-height-source:userset;height:15.75pt'>
        <td height=21 class=xl66879 align=right width=166 style='height:15.75pt;
  width:125pt'>11</td>
        <td class=xl66879 align=right width=108 style='border-left:none;width:81pt'>11</td>
        <td class=xl66879 align=right width=103 style='border-left:none;width:77pt'>11</td>
        <td class=xl66879 align=right width=90 style='border-left:none;width:68pt'>11</td>
        <td class=xl66879 align=right width=84 style='border-left:none;width:63pt'>11</td>
        <td class=xl66879 align=right width=64 style='border-left:none;width:48pt'>11</td>
      </tr>
      <tr height=21 style='height:15.75pt'>
        <td height=21 class=xl66879 align=right width=166 style='height:15.75pt;
  width:125pt'>11</td>
        <td class=xl66879 align=right width=108 style='border-left:none;width:81pt'>11</td>
        <td class=xl66879 align=right width=103 style='border-left:none;width:77pt'>11</td>
        <td class=xl66879 align=right width=90 style='border-left:none;width:68pt'>11</td>
        <td class=xl66879 align=right width=84 style='border-left:none;width:63pt'>11</td>
        <td class=xl66879 align=right width=64 style='border-left:none;width:48pt'>11</td>
      </tr>
      <![if supportMisalignedColumns]>
      <tr height=0 style='display:none'>
        <td width=166 style='width:125pt'></td>
        <td width=108 style='width:81pt'></td>
        <td width=103 style='width:77pt'></td>
        <td width=90 style='width:68pt'></td>
        <td width=84 style='width:63pt'></td>
        <td width=64 style='width:48pt'></td>
      </tr>
      <![endif]>
    </table>

  </div>


  <!----------------------------->
  <!--END OF OUTPUT FROM EXCEL PUBLISH AS WEB PAGE WIZARD-->
  <!----------------------------->
</body>

</html>
...