如何使用C#编程将数据导出到Word Doc .. [英] How to Export data into Word Doc using C# programming..
本文介绍了如何使用C#编程将数据导出到Word Doc ..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用C#编码将数据导出到MS-Word文档.
详细来说,我想创建新的Word文档并导出徽标,免责声明等数据
以及Word文档特定位置的其他数据.
我找不到这样的例子.
请任何人帮忙...
欢迎任何解决方案,链接,提示和建议.
在此先感谢..
Hi,
I want to export data into MS-Word document using C# coding.
In detail-I want to create new word document and export data like logo,disclaimer
and other data at specific location of word doc.
I not found as such any example.
Pls.,can anybody help...
Any solution,link,hint and suggestion is welcome..
Thanks in advance..
推荐答案
您应该始终从MSDN引用开始.他们总是有很好的例子,您通常可以根据自己的需要进行更改. Office Interop的操作方法 [
You should always start with the MSDN references. They always have pretty good examples that you can generally alter to fit what you want. Office Interop How To[^] should get you started.
该示例可能会对您有所帮助.
对于您而言,不是从数据库中获取数据,而只是在最后用所需的数据创建一个数据表.
This example may help you.
In your case instead of taking data from database just make a datatable at your end with your required data.
protected void ExportToWord()
{
//Get the data from database into datatable
string strQuery = "select CustomerID, ContactName, City, PostalCode" +
" from customers";
SqlCommand cmd = new SqlCommand(strQuery);
DataTable dt = GetData(cmd);
//Create a dummy GridView
GridView GridView1 = new GridView();
GridView1.AllowPaging = false;
GridView1.DataSource = dt;
GridView1.DataBind();
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=DataTable.doc");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-word ";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
从此链接获取最佳示例; 点击此处 [ ^ ]
Hi,
Get the best example from this link;Click Here[^]
这篇关于如何使用C#编程将数据导出到Word Doc ..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文