public
static
void
DataTable1Excel(System.Data.DataTable dtData)
{
System.Web.UI.WebControls.GridView gvExport =
null
;
System.Web.HttpContext curContext = System.Web.HttpContext.Current;
System.IO.StringWriter strWriter =
null
;
System.Web.UI.HtmlTextWriter htmlWriter =
null
;
if
(dtData !=
null
)
{
curContext.Response.ContentType =
"application/vnd.ms-excel"
;
curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding(
"gb2312"
);
curContext.Response.Charset =
"utf-8"
;
strWriter =
new
System.IO.StringWriter();
htmlWriter =
new
System.Web.UI.HtmlTextWriter(strWriter);
gvExport =
new
System.Web.UI.WebControls.GridView();
dtData.Columns[
"id"
].ColumnName =
"编号"
;
dtData.Columns[
"deptName"
].ColumnName =
"部门名称"
;
dtData.Columns[
"trueName"
].ColumnName =
"员工姓名"
;
dtData.Columns[
"sname"
].ColumnName =
"工作量名称"
;
dtData.Columns[
"writeDate"
].ColumnName =
"录入日期"
;
dtData.Columns[
"selectDate"
].ColumnName =
"业务时间"
;
dtData.Columns[
"workloadYear"
].ColumnName =
"年份"
;
dtData.Columns[
"workloadMonth"
].ColumnName =
"期数"
;
dtData.Columns[
"pc"
].ColumnName =
"批次"
;
dtData.Columns[
"trueValue"
].ColumnName =
"工作量(单位次)"
;
gvExport.DataSource = dtData.DefaultView;
gvExport.AllowPaging =
false
;
gvExport.DataBind();
gvExport.RenderControl(htmlWriter);
curContext.Response.Write(
"<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />"
+ strWriter.ToString());
curContext.Response.End();
}
}