C#实现HTML转WORD及WORD转PDF的方法

2019-12-26 13:37:47王旭

易采站长站为您分析C#实现HTML转WORD及WORD转PDF的方法,涉及C#实现HTML、WORD及PDF等文件格式转换的相关技巧,需要的朋友可以参考下

本文实例讲述了C#实现HTML转WORD及WORD转PDF的方法。。具体如下:

功能:实现HTML转WORD,WORD转PDF

具体代码如下:

 

 
  1. using System;  using System.Collections.Generic; 
  2. using System.ComponentModel;  using System.Data; 
  3. using System.Drawing;  using System.Text; 
  4. using System.Windows.Forms;  using Word = Microsoft.Office.Interop.Word; 
  5. using oWord = Microsoft.Office.Interop.Word;  using System.Reflection; 
  6. using System.Configuration;  using System.Web; 
  7. using System.Web.Security;  using System.Web.UI; 
  8. using System.Web.UI.WebControls;  using System.Web.UI.WebControls.WebParts; 
  9. using System.Web.UI.HtmlControls;  using Microsoft.Office.Core; 
  10. using System.Text.RegularExpressions;  namespace WindowsApplication2 
  11. {  public partial class Form1 : Form 
  12. {  public Form1() 
  13. {  InitializeComponent(); 
  14. }  private void button1_Click(object sender, EventArgs e) 
  15. {  object oMissing = System.Reflection.Missing.Value; 
  16. object oEndOfDoc = "endofdoc"; /* endofdoc is a predefined bookmark */  //Start Word and create a new document. 
  17. Word._Application oWord;  Word._Document oDoc; 
  18. oWord = new Word.Application();  oWord.Visible = true; 
  19. oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,  ref oMissing, ref oMissing); 
  20. //Insert a paragraph at the beginning of the document.  Word.Paragraph oPara1; 
  21. oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);  oPara1.Range.Text = "Heading 1"; 
  22. oPara1.Range.Font.Bold = 1;  oPara1.Format.SpaceAfter = 24; //24 pt spacing after paragraph.