我现在做了个gridview显示数据,有N条,分了很多页面,但是现在要用一个导出按钮把数据全部导出到Excel表格中,不要只导出一个页面的数据,我在网上找的解决方法全是只导出一个页面的数据,
如何解决!
如何解决!
解决方案 »
- javascript:window.opener提交给母版页中的内容页时遇到的问题!
- history.go(-1),返回上一頁時出現網頁過期,謝謝
- VS2005调试时出现“与WEB服务器通信时出现身份验证错误”
- 我想把图片的路径存到数据库中,然后读出来的时候把相应的图片显示?谢谢了
- 高分求一正则表达式!!!!
- 在做个安装盘的时候,想作个当安装盘放入光驱的时候能够自动运行
- 这样的要求.我该如何实现???100分!!各位帮忙!!!!急急急!!
- 关于dropdownlist的问题
- 原创代码,翻页自定义控件
- Temporary ASP.NET Files文件的问题,望高手指点
- objectDataSource 参数传入问题
- win2003下配置asp.net2.0的问题
public static void ExportToExcel(DataSet ds, string fileStrName) { Excel.Application excel = new Excel.ApplicationClass(); if (excel == null) { MessageBox.Show("Excel无法启动", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } int rowindex = 2; int colindex = 0; excel.Application.Workbooks.Add(true); DataTable dt = ds.Tables[0]; Excel.Range range = excel.get_Range(excel.Cells[1, 1], excel.Cells[1, dt.Columns .Count]); range.MergeCells = true; excel.ActiveCell.FormulaR1C1 =fileStrName; excel.ActiveCell.Font.Size = 18; excel.ActiveCell.Font.Bold = true; foreach (DataColumn col in dt.Columns) { colindex=colindex +1; excel.Cells[2, colindex] = col.ColumnName; } foreach (DataRow row in dt.Rows) { colindex = 0; rowindex++; foreach (DataColumn col in dt.Columns) { colindex++; excel.Cells[rowindex, colindex] = row[col.ColumnName].ToString(); } } excel.get_Range(excel.Cells[1, 1], excel.Cells[1, dt.Columns.Count]).Font.Bold = true; excel.get_Range(excel.Cells[1, 1], excel.Cells[rowindex, colindex]).Borders.LineStyle = 0; excel.Cells.EntireColumn.AutoFit(); excel.Cells.VerticalAlignment = Excel.Constants.xlCenter; excel.Cells.HorizontalAlignment = Excel.Constants.xlCenter; try { excel.Visible = false; excel.Save("Sheet1"); } catch { } finally { excel.Quit(); excel = null; } }