我有代码工作将网格导出到Excel工作表。要求在excel表中向下滚动时保持静态静态标题。我如何使用.net实现这一目标?或者我需要去第三部分组件(如aspose)?
HtmlForm form = new HtmlForm();
string attachment = "attachment; filename=" + "StaleReport" + ".xls";
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", attachment);
Response.ClearContent();
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
StringWriter _stringWriter = new StringWriter();
HtmlTextWriter _htmlTextWriter = new HtmlTextWriter(_stringWriter);
gView.AllowPaging = false;
gView.AllowSorting = false;
dt = new DataTable();
dt = SelectDataandgetallthedata();
gView.DataSource = dt;
gView.ShowHeader = true;
this.Controls.Add(gView);
gView.DataBind();
gView.AllowPaging = true;
gView.AllowSorting = true;
form.Controls.Add(gView);
this.Controls.Add(form);
string style = @"<style> .textmode { } </style>";
Response.Write(style);
form.RenderControl(_htmlTextWriter);
Response.Write(_stringWriter.ToString());
Response.Flush();
Response.End();
答案 0 :(得分:0)
好吧,在excel vba中,它将是:
ActiveWindow.FreezePanes = True
然而,在.net(快速谷歌之后 - 不太熟悉.net :)) 你试过这个:
sheet.FreezePanes(2, 1);