在aspx代码中,我设置了GridLines="None"
如何在将grid-view导出为excel文件时从代码中显示GridLines。
protected void btnexcel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=UsersReport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gridusers.DataBind();
gridusers.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
答案 0 :(得分:1)
在功能开始时,设置:
grdAdslCompanyAdvisers.GridLines = GridLines.Both;
再次出口后
grdAdslCompanyAdvisers.GridLines = GridLines.None;
希望这会有所帮助或给你一个想法。