页面保存

来源:百度知道 编辑:UC知道 时间:2024/05/28 19:23:11
A.aspx页面显示某用户信息,点击Button按钮,把页面保存为.doc格式文件并存到指定路径下。要求一个.net的详细代码。点击按钮时不要出现什么对话框之类的。

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