页面保存
来源:百度知道 编辑:UC知道 时间:2024/05/28 19:23:11
web.config里配置
<assemblies>
<add assembly="Microsoft.Office.Interop.Word, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
</assemblies>
然后页面代码
try
{
Object Nothing = System.Reflection.Missing.Value;
Directory.CreateDirectory(@"C:\"); //创建文件所在目录
string name = "a.doc";
object filename = @"C:\" +name; //文件保存路径
//创建Word文档
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//添加页眉
WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHead