在项目开发中用到将MemoryStream 转pdf,在转化过程中需要建了一个.dom格式的模板,先保存为.doc文件,然后再转换为.pdf。
有一个插件感觉好不错,给大家推荐一下。
dll下载链接
http://pan.baidu.com/s/1skWPBAX
提取码:
fu4r
重点内容
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
using Word = Microsoft.Office.Interop.Word;
namespace MyTools
{
public class WordHelper
{
private Word.Document wDoc = null;
private Word.Application wApp = null;
public Word.Document Document
{
get { return wDoc; }
set { wDoc = value; }
}
public Word.Application Application
{
get { return wApp; }
set { wApp = value; }
}
#region 从模板创建新的Word文档
/// <summary>
/// 从模板创建新的Word文档
/// </summary>
/// <param name="templateName">模板文件名</param>
/// <returns></returns>
public bool CreateNewWordDocument(string templateName)
{
try
{
return CreateNewWordDocument(templateName, ref wDoc, ref wApp);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 从模板创建新的Word文档,并且返回对象Document,Application
/// <summary>
/// 从模板创建新的Word文档,
/// </summary>
/// <param name="templateName">模板文件名</param>
/// <param name="wDoc">返回的Word.Document对象</param>
/// <param name="WApp">返回的Word.Application对象</param>
/// <returns></returns>
public static bool CreateNewWordDocument(string templateName, ref Word.Document wDoc, ref Word.Application WApp)
{
Word.Document thisDocument = null;
Word.Application thisApplication = new Word.ApplicationClass();
thisApplication.Visible = false;
thisApplication.Caption = "";
thisApplication.Options.CheckSpellingAsYouType = false;
thisApplication.Options.CheckGrammarAsYouType = false;
Object Template = templateName;// Optional Object. The name of the template to be used for the new document. If this argument is omitted, the Normal template is used.
Object NewTemplate = false;// Optional Object. True to open the document as a template. The default value is False.
Object DocumentType = Word.WdNewDocumentType.wdNewBlankDocument; // Optional Object. Can be one of the following WdNewDocumentType constants: wdNewBlankDocument, wdNewEmailMessage, wdNewFrameset, or wdNewWebPage. The default constant is wdNewBlankDocument.
Object Visible = true;