我有两个数据表。我想为每个人制作两个网格视图。然后我想在一个excel文件中渲染这些网格视图,但是作为两个单独的工作表。我搜索过这个,但没有得到任何我想要的东西。任何人都可以指路吗?
以下是使用一个gridview的单个工作表的示例代码:
DataTable dt = createDataTbl(); // creating a datatable
grid.DataSource = dt;
grid.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("content-disposition", "attachment; filename=sample.xls");
Response.Charset = "";
StringWriter sw = new StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
grid.HeaderRow.Style.Add("background-color", "#007ACC");
grid.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
byte[] fileContents = System.Text.Encoding.UTF8.GetBytes(Response.ToString());
return new FileContentResult(fileContents, "application/vnd.ms-excel");