gpt4 book ai didi

c# - 将gridview数据导出到doc文件时添加标题

转载 作者:搜寻专家 更新时间:2023-10-30 19:49:09 25 4
gpt4 key购买 nike

我有一些 Sql Server 数据库,我用这个方法返回数据:

protected DataTable GetProductsData()
{
if (ddTipRaport.SelectedItem.Text == "Toate Cerintele")
{ DataTable dt = new DataTable();
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(
"Data Source=BOGDAN-PC\\BOGDAN;Initial Catalog=ePlanning;Integrated Security=SSPI;Connect Timeout=10;TrustServerCertificate=True ");
System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand();
comm.CommandText = "Select PS.titlu_cerinta as 'Categorie Cerinta', P.id_subcerinta as 'ID',p.titlu_subcerinta as 'Titlu Cerinta',p.data_crearii as 'Data Crearii',p.autor as 'Autor',p.revizuita as'Revizuita',p.revizuitor as'Revizuitor',p.prioritate as 'Prioritate(Importanta)',p.acoperire as 'Stare Acoperire' from subCerinteProiect P inner join cerinteProiect PS on P.id_cerinta=PS.id_cerinta where PS.id_proiect = " + (Request.QueryString["proiect"]).ToString() + " order by PS.id_cerinta desc";
comm.Connection = con;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(comm);

da.Fill(dt);
con.Close();
return dt;
}

然后我用这个方法把它全部写在一个文档中:

  protected void ExportDataTableToWord()
{
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.ms-word";
Response.AddHeader("content-disposition", "attachment;filename=Raport_"+ DateTime.Now.ToShortDateString()+"_"+DateTime.Now.ToShortTimeString()+".doc");

StringWriter sWriter = new StringWriter();

HtmlTextWriter hWriter = new HtmlTextWriter(sWriter);

GridView GridView1 = new GridView();
GridView1.RowStyle.HorizontalAlign = HorizontalAlign.Center;
GridView1.DataSource = GetProductsData();
GridView1.DataBind();
GridView1.RenderControl(hWriter);

Response.Write(sWriter.ToString());

Response.End();
}

我的问题是,如何在导出的 gridview 上方添加标题,谢谢!

最佳答案

您要查找的属性称为标题 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.caption.aspx

例如

GridView1.Caption = "StackOverFlow Grid...";

关于c# - 将gridview数据导出到doc文件时添加标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11513075/

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