Ale*_*lex 0 c# asp.net grid export-to-word
我在c#中有一个填充数据的网格.该网格中的一列包含按字母顺序排序的字母(后跟数字),如下所示:
A124
A256
A756
B463
B978
D322
etc.
Run Code Online (Sandbox Code Playgroud)
我需要以word文档(.doc或.docx格式)导出此数据.这是我导出一个signle网格所做的:
var dt = FuntionThatReturnsDatatables();
var gd = new GridView
{
DataSource = dt
};
gd.DataBind();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;
filename=" + "List" + DateTime.Now.ToString("dd.MM.yyyy") + ".doc");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-word";
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
var oStringWriter = new StringWriter();
var oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
gd.RenderControl(oHtmlTextWriter);
HttpContext.Current.Response.Output.Write(oStringWriter.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
Run Code Online (Sandbox Code Playgroud)
但是现在我必须遵循这样的逻辑: - 对于网格中的每个字母,应该创建一个带有标题的新表,如下所示:
Table A:
A124
A256
A756
Run Code Online (Sandbox Code Playgroud)


每个新表应该从一个新页面开始,如下所示:
表A:A124,A256,A756,//新页面
表B:B463,B978,//新页面
表D:D322等
该word文档中的页面需要编号.
有没有办法在c#中编写代码来执行此操作,还是有一些库/插件可以完成此任务?
一些例子将不胜感激.
您应该能够使用Microsoft的OpenXML SDK来实现这一目标.
参考:http://msdn.microsoft.com/en-us/library/bb448854.aspx
参考样本:
| 归档时间: |
|
| 查看次数: |
11213 次 |
| 最近记录: |