关于导出到excel的问题 http://www.cnblogs.com/summer_adai/archive/2010/09/15/1827101.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用第三方组件导出..而不是直接拿html中的数据.. 否则你有分页你如何导出??百度搜索 myxls 或者 npoi直接循环结果集写入数据就行了.. 你这个Repeater 是在后台做了数据绑定,你可以直接在后台把数据导出来。 protected void Button1_Click(object sender, EventArgs e) { string sql = "select id,code from eban_summary "; string[] arr = { "编号", "设备号" }; string file = uploadPathCreate("数据导出"); if (!Directory.Exists(file)) { Directory.CreateDirectory(file); } DataSet ds = Comm.BLLBase.DBHelper.ExecuteDataSet(sql); string filename = Comm.ExcelUtils.ExportToExcel(ds, file, ".xls", arr, ""); Response.Redirect(file + filename); } public string uploadPaths(string type) { return "~\\Upfile\\Excel\\" + type + "\\" + getDateString() + "\\"; } public string uploadPathCreate(string type) { return HttpContext.Current.Request.PhysicalApplicationPath + @"Upfile\Excel\" + type + "\\" + getDateString() + "\\"; } public string getDateString() { return string.Format("" + DateTime.Now.ToShortDateString() + "", "yyyy-mm-dd").Replace("-", "").Replace("/", "").Replace(".", ""); }诸如此类的导出方法,网上还是有很多案例的 楼上正解, 返回一个excel 响应就行,通过excel Com组件 自己用组件导出来呀,用html导出格式会比较乱 将数据集绑定到Repeater上面,然后又在上面去找 。何必呢直接在数据集上面导 不通过repeater、datalist之类的数据绑定控件导出,直接查询导出,输出excel类型文件,或者通过第三方组件如NPOI导出 把Sql Server数据导出到Excel private void btn_Excel_Click(object sender, EventArgs e) { if (dgv_Info.Rows.Count == 0)//判断是否有数据 return;//返回 Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();//实例化Excel对象 excel.Application.Workbooks.Add(true);//在Excel中添加一个工作簿 excel.Visible = true;//设置Excel显示 //生成字段名称 for (int i = 0; i < dgv_Info.ColumnCount; i++) { excel.Cells[1, i + 1] = dgv_Info.Columns[i].HeaderText;//将数据表格控件中的列表头填充到Excel中 } //填充数据 for (int i = 0; i < dgv_Info.RowCount - 1; i++)//遍历数据表格控件的所有行 { for (int j = 0; j < dgv_Info.ColumnCount; j++)//遍历数据表格控件的所有列 { if (dgv_Info[j, i].ValueType == typeof(string))//判断遍历到的数据是否是字符串类型 { excel.Cells[i + 2, j + 1] = "'" + dgv_Info[j, i].Value.ToString();//填充Excel表格 } else { excel.Cells[i + 2, j + 1] = dgv_Info[j, i].Value.ToString();//填充Excel表格 } } } } Asp.net网站加入谷歌地图怎么做?求详细代码 弹出层对数据进行操作 用ajax 实现上传图片,怎么操作 ? 这样的代码我们要如何处理呢?有没有高手指点一下@指个路也行! 关于页面缓存的问题 gridview 选择行的问题 图片显示不出来,是不是因为没有加response.contype? 我是大三的学生,正在学习.net以后想到北京发展,想看看北京.net薪水大概多少!!谢谢大家啦! html代码过滤问题 两个疑难问题,待解决!! Datalist分页 关于绑定gridview的升序降序问题,为嘛只能升序没法降序呢?有代码
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "select id,code from eban_summary ";
string[] arr = { "编号", "设备号" };
string file = uploadPathCreate("数据导出");
if (!Directory.Exists(file))
{
Directory.CreateDirectory(file);
}
DataSet ds = Comm.BLLBase.DBHelper.ExecuteDataSet(sql);
string filename = Comm.ExcelUtils.ExportToExcel(ds, file, ".xls", arr, "");
Response.Redirect(file + filename);
}
public string uploadPaths(string type)
{
return "~\\Upfile\\Excel\\" + type + "\\" + getDateString() + "\\";
}
public string uploadPathCreate(string type)
{
return HttpContext.Current.Request.PhysicalApplicationPath + @"Upfile\Excel\" + type + "\\" + getDateString() + "\\";
}
public string getDateString()
{
return string.Format("" + DateTime.Now.ToShortDateString() + "", "yyyy-mm-dd").Replace("-", "").Replace("/", "").Replace(".", "");
}
诸如此类的导出方法,网上还是有很多案例的
private void btn_Excel_Click(object sender, EventArgs e)
{
if (dgv_Info.Rows.Count == 0)//判断是否有数据
return;//返回
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();//实例化Excel对象
excel.Application.Workbooks.Add(true);//在Excel中添加一个工作簿
excel.Visible = true;//设置Excel显示
//生成字段名称
for (int i = 0; i < dgv_Info.ColumnCount; i++)
{
excel.Cells[1, i + 1] = dgv_Info.Columns[i].HeaderText;//将数据表格控件中的列表头填充到Excel中
}
//填充数据
for (int i = 0; i < dgv_Info.RowCount - 1; i++)//遍历数据表格控件的所有行
{
for (int j = 0; j < dgv_Info.ColumnCount; j++)//遍历数据表格控件的所有列
{
if (dgv_Info[j, i].ValueType == typeof(string))//判断遍历到的数据是否是字符串类型
{
excel.Cells[i + 2, j + 1] = "'" + dgv_Info[j, i].Value.ToString();//填充Excel表格
}
else
{
excel.Cells[i + 2, j + 1] = dgv_Info[j, i].Value.ToString();//填充Excel表格
}
}
}
}