如何生成word文档的源码
2006-11-15 19:45
471 查看
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Word;
namespace WebApplication2
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox SaveAs;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label result;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox wordText;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
Object Nothing=System.Reflection.Missing.Value;
object filename=@SaveAs.Text;
Word.Application WordApp=new Word.ApplicationClass();
Word.Document WordDoc=WordApp.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing);
Word.Table table=WordDoc.Tables.Add(WordApp.Selection.Range,1,1,ref Nothing,ref Nothing);
table.Cell(1,1).Range.Text=wordText.Text;
WordDoc.Paragraphs.Last.Range.Text="Wellcome To Aspxcn.Com";
WordDoc.SaveAs(ref filename,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
result.Text="文档路径:<a href='"+SaveAs.Text+"'>"+SaveAs.Text+"</a>(点击链接查看)<br>生成结果:成功!";
}
}
}
在web.config中要设置权限。
windows+R----->......
windows+R----->dcomcnfg------>我的电脑----->microsoft word文档------>属性------>安全性------>访问控制
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Word;
namespace WebApplication2
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox SaveAs;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label result;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox wordText;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
Object Nothing=System.Reflection.Missing.Value;
object filename=@SaveAs.Text;
Word.Application WordApp=new Word.ApplicationClass();
Word.Document WordDoc=WordApp.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing);
Word.Table table=WordDoc.Tables.Add(WordApp.Selection.Range,1,1,ref Nothing,ref Nothing);
table.Cell(1,1).Range.Text=wordText.Text;
WordDoc.Paragraphs.Last.Range.Text="Wellcome To Aspxcn.Com";
WordDoc.SaveAs(ref filename,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
result.Text="文档路径:<a href='"+SaveAs.Text+"'>"+SaveAs.Text+"</a>(点击链接查看)<br>生成结果:成功!";
}
}
}
在web.config中要设置权限。
windows+R----->......
windows+R----->dcomcnfg------>我的电脑----->microsoft word文档------>属性------>安全性------>访问控制
相关文章推荐
- 如何生成word文档的源码
- 如何生成word文档的源码
- 如何生成word文档的源码
- 如何生成word文档的源码
- php中如何把html中的内容生成到word文档
- PageOffice如何实现从零开始动态生成图文并茂的Word文档
- 如何在不安装Word的情况下生成Word文档
- 如何在线生成Word文档?一种极简,极强大的方法,支持图片表格等各种格式
- word文档如何自动生成目录
- 如何能让Java生成复杂Word文档(1)
- 如何用C#编程实现动态生成Word文档并填充数据?
- word如何自动生成目录-----如何写软件文档
- 如何能让Java生成复杂Word文档
- 如何在不安装Word的情况下生成Word文档 ——转【陈希章】
- 使用Java生成word文档(附源码) 推荐
- 如何在不安装Word的情况下生成Word文档
- 使用Java生成word文档(附源码)
- 如何能让Java生成复杂Word文档(2)
- Word文档如何自动生成文献摘要?
- OGRE学习之路02:手把手教你如何通过Doxygen从源码生成OGRE 1.10.11 的离线API文档