GridView 导出成Excel 死活找不到问题所在
导出的excel在Header下面无缘无故多出来一行
关键方法
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Attributes.Add("style", "vnd.ms-excel.numberformat:@;");
}
switch (e.Row.RowType)
{
case DataControlRowType.Header:
//第一行的表头
TableCellCollection tcHeader = e.Row.Cells;//retrun TablecellCollection get a collection of TableCell object that represents the cells of a row (in a Table Control)
tcHeader.Clear();
tcHeader.Add(new TableHeaderCell());
tcHeader[0].Attributes.Add("colspan", "4"); //跨Column
tcHeader[0].Text = "CheckList for AMS Information -LCL";
tcHeader.Add(new TableHeaderCell());
tcHeader[1].Attributes.Add("colspan", "1");
tcHeader[1].Text = "Date:" + DateTime.Now.ToString("MMM.dd", new System.Globalization.CultureInfo("en-GB")) + "</th></tr><tr>";// + "</th></tr><tr>";加?
break;
case DataControlRowType.DataRow:
TableCell tc = new TableCell();
//tc.Attributes.Add("colspan", "2");
tc.Attributes.Add("colspan", "3");//
//tc.AssociatedHeaderCellID = ;
tc.Text = "Vessel/Voyage";
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FFC080'");
e.Row.HorizontalAlign =HorizontalAlign.Center;
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
break;
}//Switch End()
}//GridView1_RowDataBound End()