添加自定义标题到Excel文件 [英] Adding Custom header to the excel file
本文介绍了添加自定义标题到Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以自定义头添加到Excel中,而在ASP.NET导出的DataSet
到Excel?
我有这样一个要求。我可以在的DataSet
导出到Excel的成功。但我不能添加自定义标题。请帮助我,如果任何人有解决方案。先谢谢了。
Is it possible to add a custom header to the Excel while exporting a DataSet
to Excel in ASP.NET?
I have one requirement like this. I can export the DataSet
to the Excel successfully. But I can't add the custom header. Please help me if anybody have the solution. Thanks in advance.
推荐答案
如果您使用的是的Response.Write
来导出Excel中。
你可以使用下面的代码以最小的努力和标题
只要你想可定制,就像HTML头。
IF you are using Response.Write
to Export the Excel.
You can use the following code with minimal effort and the Header
can be customized as you want, just like HTML headers.
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=test.xls;");
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
dgrExport.DataSource = dtExport;
dgrExport.DataBind();
dgrExport.RenderControl(htmlWrite);
string headerTable = @"<Table><tr><td>Report Header</td></tr><tr><td><img src=""D:\\Folder\\Report Header.jpg"" \></td></tr></Table>";
Response.Write(headerTable);
Response.Write(stringWrite.ToString());
Response.End();
Mac上,您是否正在寻找相同?
Mac, Are you looking for the same?
这篇关于添加自定义标题到Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文