asp.net 导出Excel
public bool SaveExcel(GridView paramGridView)
{
if (paramGridView.Rows.Count == 0)
{
return false;
}
//创建Excel对象
Microsoft.Office.Interop.Excel.Application myExcel = new Microsoft.Office.Interop.Excel.Application();
myExcel.Application.Workbooks.Add(true);
myExcel.Visible = true;
//生成字段名称列名
for (int i = 0; i < paramGridView.Columns.Count; i++)
{
//第二行第二列开始录入
myExcel.Cells[2, i + 2] = paramGridView.Columns[i].HeaderText;
}
//填充数据
for (int i = 0; i < paramGridView.Rows.Count; i++)
{
for (int j = 0; j < paramGridView.Columns.Count; j++)
{
if (paramGridView.Rows[i].Cells[j].Text != null)
{
myExcel.Cells[i + 3, j + 2] = "'" + paramGridView.Rows[i].Cells[j].Text.ToString();
}
}
}
return true;
}
protected void btnPrint_Click(object sender, EventArgs e)
{
SaveExcel(grdvMessage);
}
相关文档:
1.打开新的窗口并传送参数:
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="++"')</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.为按钮添加对话框
Button1.Attributes.Add("onclick","return ......
前前后后收到过一些学生的来信,询问ASP.NET的学习顺序问题,在此就向打算系统学习ASP.NET技术的初学者谈谈我的建议。
如果你已经有较多的面向对象开发经验,跳过以下这两步:
第一步 掌握一门.NET面向对象语言,C#或VB.NET。
我强烈反对在没系统学过一门面向对象(OO) ......
Asp.net页面中调用以SOAP头作验证的web services操作步骤:
第一步:用来作SOAP验证的类必须从SoapHeader类派生,类中Public的属性将出现在自动产生XML节点中,即:
<soap:Header>
<UserSoapHeader xmlns="http://tempuri.org/">
<UserName>strin ......
C# ASP.NET里@的妙用
ASP.NET C# string 字符串的前面可以加 @ 可以将转义字符(\)当作普通字符对待。
比如:string str = @"C:\Windows";
如果我们不用 @ 的话,应该是:string str = "C:\\Windows";
@ 字符串中,我们用两个连续英文双引号表示一个英文双引号,如下字符串的实际内容为:="=,字符串长度为 3 ......
需求:
A域有页面a.html,其中有iframe包含B域的页面b.html,现在要通过a.html上的一个按钮,来把a.html页面上一个文本框的值传递到b.html页面的文本框。
注:这里b.html是html网页,不能接收其他网站post过来的值,所以不能用直接post的方法来传值,但是,如果接收页面是b.aspx或者b.asp 呢,那不是可以直接post了么?答 ......