2016-06-07 69 views
2

我试图将html文件转换为MS word(docx)文件。 使用Microsoft.Office.Interop.Word我能够从HTML转换为Word,但字体大小不一样的文件的HTML和Word格式。 无论我在HTML中做什么格式(字体大小)都在Word文件中丢失。任何人都可以帮助我保留相同的字体大小。字体大小不一样,当html转换为Word使用Microsoft.Office.Interop.Word

下面是代码:

Microsoft.Office.Interop.Word.Document wordDoc = new Microsoft.Office.Interop.Word.Document(); 

wordDoc = wordApp.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 = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault; 

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

使用的代码转换

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);