我正在处理带有gridview 的asp.net 页面。我需要将gridview导出到excel,但需要在导出前修改colmnns数据。我正在使用以下代码导出:
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.ContentType = "application/vnd.xls";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gvLogs.RenderControl(hw);
gvLogs.AllowPaging = false;
gvLogs.DataBind(); // bind data
Response.Output.Write(sw.ToString());
//need to call Flush and End methods
Response.Flush();
Response.End();
它可以工作,但它将网格导出到具有与网格相同的列数据的 excel,如下所示:
asif@cc.com my company1aa viewed profile abc@gmail.com my name Company views profile 7/24/2013 11:18
asif@cc.com my company1aa viewed profile cv3@cc.com cv 3 Company views profile 7/24/2013 11:18
asif@cc.com my company1aa viewed profile cv2@cc.com cv 2 Company views profile 7/24/2013 11:17
asif@cc.com my company1aa viewed profile cv4@cc.com cv 4 Company views profile 7/24/2013 11:17
asif@cc.com my company1aa viewed profile CV1@cc.com cv 1 Company views profile 7/24/2013 11:16
我想将第一列分成 4 列,这样(在第一行的情况下)
Employer email = asif@cc.com
company name = my company1aa
Registrant email = abc@gmail.com
Full name = my name
and then remaining 2 columns as it is
Action = Compnay view Profile
Date = 7/24/2013 11:18
请建议我该怎么做。我正在使用对象数据源进行绑定,但我可以获得数据表:
HRActionLog actionLog = new HRActionLog();
DataTable dt = actionLog.GetList(Action,DateFrom,DateTo,CompanyId,RegistrantId,VacancyId,CurrentLanguage);
我是否需要创建一个带有其他列的新数据表并从 dt 填充它?
请建议