易截截图软件、单文件、免安装、纯绿色、仅160KB

asp.net 导出Excel方法汇总

第一种:需要引用com :microsoft.excel.11.0.
//生成Excel文件的代码
protected void ExportExcel()
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wb = excel.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet); // 创建工作簿
Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1]; // 创建工作页
DataSet ds = GetData();
int iMaxRow = ds.Tables["rsData"].Rows.Count;
int iMaxCol = ds.Tables["rsData"].Columns.Count;
// 设置格式
ws.get_Range(ws.Cells[1, 1], ws.Cells[1, iMaxCol]).Font.Name = "黑体";
ws.get_Range(ws.Cells[1, 1], ws.Cells[1, iMaxCol]).Font.Bold = true;
ws.get_Range(ws.Cells[1, 1], ws.Cells[iMaxRow + 1, iMaxCol]).Borders.LineStyle = 1;
// 设置标题
excel.Cells[1, 1] = "班级";
excel.Cells[1, 2] = "学号";
excel.Cells[1, 3] = "姓名";
excel.Cells[1, 4] = "性别";
// 填充数据
for (int iRow = 0; iRow < iMaxRow; iRow++)
{
for (int iCol = 0; iCol < iMaxCol; iCol++)
{
excel.Cells[iRow + 2, iCol + 1] = ds.Tables["rsData"].Rows[iRow][iCol].ToString();
}
}
// 保存Excel
excel.Save("学生基础信息");
// 打开Excel
excel.Visible = true;
}
 第二种:利用 System.IO
public void CreateExcel(DataSet ds, string typeid, string FileName)
{
HttpResponse resp;
resp = Page.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.ContentType = "application/ms-excel";
resp.AddHeader("Content-Dispositi


相关文档:

ASP.NET中常用的三十三种代码

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("o ......

asp.net中的异步页面


要想了解asp.net 2.0的异步页的处理过程,先列出页面的生命周期:
1 :Init 事件: 页面初始化 ,初始化设置。
2: LoadViewState方法: 加载视图状态, 填充ViewState属性。
3 :LoadPostData方法: 处理回发数据, 处理传入窗体数据。
4: Load 事件: 加载页面 ,页面控件初始化完成并反映了客户端的数据。
5 :Ra ......

ASP.NET页面跳转的三大方法详解

ASP.NET页面跳转有什么方法呢?,现在给大家介绍三种方法,他们的区别是什么呢?让我们开始吧:
ASP.NET页面跳转1、response.redirect 这个跳转页面的方法跳转的速度不快,因为它要走2个来回(2次postback),但他可以跳转到任何页面,没有站点页面限制(即可以由雅虎跳到新浪),同时不能跳过登录保护。但速度慢是其最大缺陷! ......

ASP.NET 2.0服务器控件开发 控件生命周期


ASP.NET 2.0服务器控件开发----控件生命周期
服务器控件生命周期简介
  服务器控件的生命周期是创建服务器控件最重要的概念。作为开发人员,必须对服务器控件生命周期深刻理解。当然,这不是一朝一夕就可以做到的。对于学习控件开发技术的初学者,可以不必掌握得非常详细深入,只需对服务器控件的生命周期中的不同 ......

将jQuery应用于Asp.net Ajax时,应避免的3个错误

3 mistakes to avoid when using jQuery with ASP.NET AJAX
AJAX, ASP.NET, JavaScript, jQuery By Dave Ward on June 5th, 2008
Over the past few weeks, I think I have definitely embodied Jeff Atwood’s claim that we’re all amateurs, learning together. Despite my best efforts to thoroughly tes ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号