gpt4 book ai didi

c# - 如何在将数据集导出到 excel 时使标题字体加粗?

转载 作者:太空狗 更新时间:2023-10-29 22:23:35 25 4
gpt4 key购买 nike

我在这里将数据集中的数据表导出到 excel。如何单独使数据表的标题字体看起来很粗。这是我的代码

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + "");
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter);
DataGrid dataExportExcel = new DataGrid();
foreach (DataTable table in dtInputParameters.Tables)
{
dataExportExcel.DataSource = table;
dataExportExcel.DataBind();
dataExportExcel.RenderControl(htmlWrite);
htmlWrite.WriteLine("<br/>");
// htmlWrite.AddStyleAttribute(System.Web.UI.HtmlTextWriterStyle.FontWeight, "bold");
}
StringBuilder sbResponseString = new StringBuilder();
sbResponseString.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"> <head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1252\"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>" + worksheetName + "</x:Name><x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head> <body>");
sbResponseString.Append(stringWriter + "<table width='800' height='100' align='center' style='text-align:center'");
sbResponseString.Append("</table></body></html>");
HttpContext.Current.Response.Write(sbResponseString.ToString());
HttpContext.Current.Response.End();

有什么建议吗?

最佳答案

您需要在 DataGrid 上设置 HeaderStyle 才能使用粗体。就这样。

dataExportExcel.HeaderStyle.Font.Bold=true;

关于c# - 如何在将数据集导出到 excel 时使标题字体加粗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11207297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com