易采站长站为您分析C#实现HTML转WORD及WORD转PDF的方法,涉及C#实现HTML、WORD及PDF等文件格式转换的相关技巧,需要的朋友可以参考下
本文实例讲述了C#实现HTML转WORD及WORD转PDF的方法。。具体如下:
功能:实现HTML转WORD,WORD转PDF
具体代码如下:
- using System; using System.Collections.Generic;
- using System.ComponentModel; using System.Data;
- using System.Drawing; using System.Text;
- using System.Windows.Forms; using Word = Microsoft.Office.Interop.Word;
- using oWord = Microsoft.Office.Interop.Word; using System.Reflection;
- using System.Configuration; using System.Web;
- using System.Web.Security; using System.Web.UI;
- using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls; using Microsoft.Office.Core;
- using System.Text.RegularExpressions; namespace WindowsApplication2
- { public partial class Form1 : Form
- { public Form1()
- { InitializeComponent();
- } private void button1_Click(object sender, EventArgs e)
- { object oMissing = System.Reflection.Missing.Value;
- object oEndOfDoc = "endofdoc"; /* endofdoc is a predefined bookmark */ //Start Word and create a new document.
- Word._Application oWord; Word._Document oDoc;
- oWord = new Word.Application(); oWord.Visible = true;
- oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
- //Insert a paragraph at the beginning of the document. Word.Paragraph oPara1;
- oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing); oPara1.Range.Text = "Heading 1";
- oPara1.Range.Font.Bold = 1; oPara1.Format.SpaceAfter = 24; //24 pt spacing after paragraph.










