各位大哥问个问题:asp.net 如何在服务器生成word文件? 并提供下载?

我用vs2008 asp.net C#做了一个问卷调查系统,想把页面上显示的问卷转成word文档提供给用户下载,请问这个需要怎么做,有现成的代码吗?

第1个回答  2010-09-01
***
DataTable、GridView、DataList导出至Word或Excel而对Repeater不行!因为DataGrid和DataList都是继承自WebControl类,

而Repeater则是继承自Control类

***
使用时,先引入名称空间:using Insus.NET。此Dll的类别名称为:ExportToFile

***这代码要加上去!不然会出现错误!
public override void VerifyRenderingInServerForm(Control control)
{

}

成功CODE:

using System.Data.SqlClient;
using Insus.NET;//引入空间

public partial class firstdaytwo : System.Web.UI.Page
{
ExportToFile ojfile = new ExportToFile();//实例化一定要
public override void VerifyRenderingInServerForm(Control control)//这个方法要加上不然出错
{

}
protected void Page_Load(object sender, EventArgs e)
{
bindData();
}
public void bindData()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Container"].ConnectionString);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from Sgird", con);
DataSet ds = new DataSet();
da.Fill(ds);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();

}
protected void Button1_Click(object sender, EventArgs e)
{
ojfile.ToWord(GridView1, "ssss");//ssss是你要取的文件名!可以用个textbox让它动态的改名,ojfile是上面的实例
}
}

你要下一个DLL引入:ExportToFile.dll 实例就上面都说明的
第2个回答  2010-09-02
我的想法是:
用word组件,实例化一个word对象,然后后台代码里填充word的内容和设置相应的样式,用户点下载就输出给用户。
第3个回答  2010-09-02
我做过这样一个系统,不过是生成csv文件,这样可以用excel打开,本回答被提问者采纳
相似回答