2016-07-25 15 views
1

私はMicrosoft.Office.Interop.Wordを使用してhtmlを単語に変換しています。ローカルマシン上にhtmlファイルを作成してからword file.Butに変換すると、正しい形式が表示されません。それは単にイメージを表示しています。私はstackoverflowの質問を参照しました。しかし、私は運が見つかりませんでした。以下に示すように マイサンプルHTMLファイルがある: -htmlを単語に変換する#

<!doctype html> 
 
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'> 
 

 
<head> 
 
    <title="Device Information" /> 
 
    <style> 
 
    table.main { 
 
     width: 700px; 
 
     height: 450px; 
 
     background: radial-gradient(#1367AB 0%, #154075 60%); 
 
    } 
 
    td.firsttablerow1 { 
 
     width: 190px; 
 
    } 
 
    td.firsttablerow2 { 
 
     width: auto; 
 
     color: white; 
 
    } 
 
    tr.image1 { 
 
     margin: "15px,20px,30px,40px"; 
 
     align-items: stretch; 
 
     height: 100px; 
 
    } 
 
    tr.image2 { 
 
     margin: "0px,20px,30px,40px"; 
 
     align-items: stretch; 
 
    } 
 
    tr.text1 { 
 
     color: #DDE9F2; 
 
     align-items: flex-end; 
 
     font-size: 9; 
 
    } 
 
    </style> 
 
</head> 
 

 
<body> 
 
    <table align="center" class="main"> 
 
    <tr> 
 
     <td class="firsttablerow1"> 
 
     <table> 
 
      <tr class="image1"> 
 
      <td> 
 
       <img src='C:\Jellyfish.jpg' width='200' height='90'> 
 
      </td> 
 
      </tr> 
 
      <tr class="image2"> 
 
      <td> 
 
       <img src='C:\Desert.jpg' width='150' height='90'> 
 
      </td> 
 
      </tr> 
 
      <tr class="text1"> 
 
      <td>"abc"</td> 
 
      </tr> 
 
     </table> 
 
     </td> 
 
     <td class="firsttablerow2">"xyz"</td> 
 
    </tr> 
 
    </table> 
 

 
</body> 
 

 
</html>

単語にHTMLに変換するマイC#コードを以下に示す通りです。

MSWord.Application word = new MSWord.Application { Visible = false }; 
     word.Documents.Open("htmlfilename", Format: WdOpenFormat.wdOpenFormatWebPages); 
     MSWord.Document doc = word.Documents[@"htmlfilename"]; 
     doc.SaveAs2(@"wordFileName", WdSaveFormat.wdFormatDocument); 
     doc.Close(); 
     doc = null; 
     word.Quit(); 
     word = null; 

編集:さらに調査-after、私は放射状の背景を追加するための他の方法を放射状の勾配.Isを使用して背景を変更することができない.But、その単語が作成取得されましたか?

答えて

0

は試すことができます。この

Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); 
      Microsoft.Office.Interop.Word.Document wordDoc = new Microsoft.Office.Interop.Word.Document(); 
      Object oMissing = System.Reflection.Missing.Value; 
      wordDoc = word.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); 
      word.Visible = false; 
      Object filepath = "c:\\page.html"; 
      Object confirmconversion = System.Reflection.Missing.Value; 
      Object readOnly = false; 
      Object saveto = "c:\\doc.pdf"; 
      Object oallowsubstitution = System.Reflection.Missing.Value; 

      wordDoc = word.Documents.Open(ref filepath, ref confirmconversion, ref readOnly, ref oMissing, 
              ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
              ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
              ref oMissing, ref oMissing, ref oMissing, ref oMissing); 
      object fileFormat = WdSaveFormat.wdFormatPDF; 
      wordDoc.SaveAs(ref saveto, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, 
          ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
          ref oMissing, ref oMissing, ref oMissing, ref oallowsubstitution, ref oMissing, 
          ref oMissing); 
+0

私はこのコードを試してみましたが、私は同じoutput.only画像が表示されている取得しています。 – Alex

関連する問題