到处exl 求:分页到处exl 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); HtmlTextWriter htw = new HtmlTextWriter(sw); Page page = new Page(); HtmlForm form = new HtmlForm(); MyGridView.EnableViewState = false; page.EnableEventValidation = false; page.DesignerInitialize(); page.Controls.Add(form); form.Controls.Add(MyGridView); page.RenderControl(htw); Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName.Trim(), System.Text.Encoding.UTF8).ToString() + ".xls"); Response.Charset = "UTF-8"; Response.ContentEncoding = Encoding.Default; Response.Write(sb.ToString()); Response.End(); 1.using System; 2.using System.Collections.Generic; 3.using System.ComponentModel; 4.using System.Data; 5.using System.Drawing; 6.using System.Text; 7.using System.Windows.Forms; 8.using System.Data.Sql; 9.using System.Data.SqlClient; 10.namespace excelform 11.{ 12. public partial class Form1 : Form 13. { 14. public Form1() 15. { 16. InitializeComponent(); 17. } 18. 19. /// <summary> 20. /// 将DataGridView控件中数据导出到Excel 21. /// </summary> 22. /// <param name="gridView">DataGridView对象</param> 23. /// <param name="isShowExcle">是否显示Excel界面</param> 24. /// <returns></returns> 25. public bool ExportDataGridview(DataGridView gridView, bool isShowExcle) 26. { 27. if (gridView.Rows.Count == 0) 28. return false; 29. //建立Excel对象 30. Excel.Application excel = new Excel.Application(); 31. excel.Application.Workbooks.Add(true); 32. excel.Visible = isShowExcle; 33. //生成字段名称 34. for (int i = 0; i < gridView.ColumnCount; i++) 35. { 36. excel.Cells[1, i + 1] = gridView.Columns[i].HeaderText; 37. } 38. //填充数据 39. for (int i = 0; i < gridView.RowCount - 1; i++) //循环行 40. { 41. 42. for (int j = 0; j < gridView.ColumnCount; j++) //循环列 43. { 44. if (gridView[j, i].ValueType == typeof(string)) //判断DataGirdView中数据的类型 45. { 46. excel.Cells[i + 2, j + 1] = "'" + gridView[j, i].Value.ToString(); 47. } 48. else 49. { 50. excel.Cells[i + 2, j + 1] = gridView[j, i].Value.ToString(); 51. } 52. } 53. } 54. return true; 55. } 56. private void button1_Click(object sender, EventArgs e) 57. { 58. this.ExportDataGridview(dataGridView1, true); 59. } 60. private void Form1_Load(object sender, EventArgs e) 61. { 62. SqlConnection con = new SqlConnection("Server=.;uid=sa;pwd=123;DataBase=accp;"); 63. SqlDataAdapter dap = new SqlDataAdapter("select * from userInfo", con); 64. DataSet ds = new DataSet(); 65. dap.Fill(ds); 66. dataGridView1.DataSource = ds.Tables[0].DefaultView; 67. } 68. 69. } 70.} 安装DISCUZ3.1论坛的问题 关于URL重写生成伪静态的问题,求助 fusionchart控件的设置 一个正则问题 还是一个div填充的问题 简单问题,关于 求以下无KEY的JSON数据反序列化 加入收藏的代码 在线等待,立即结账 有多个解决方案,每个解决方案里面有多个项目,如何部署打包这样的一个工程呢?大家给点意见! 在web页的DataGrid控件的temploate列中,加入DataGrid子控件,引用DataGrid子控件的属性与值!!! COOKIE保存出错 请教浮动菜单设计
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw); Page page = new Page();
HtmlForm form = new HtmlForm(); MyGridView.EnableViewState = false;
page.EnableEventValidation = false;
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(MyGridView);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName.Trim(), System.Text.Encoding.UTF8).ToString() + ".xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
Response.Write(sb.ToString());
Response.End();
2.using System.Collections.Generic;
3.using System.ComponentModel;
4.using System.Data;
5.using System.Drawing;
6.using System.Text;
7.using System.Windows.Forms;
8.using System.Data.Sql;
9.using System.Data.SqlClient;
10.namespace excelform
11.{
12. public partial class Form1 : Form 13. {
14. public Form1() 15. {
16. InitializeComponent();
17. }
18.
19. /// <summary> 20. /// 将DataGridView控件中数据导出到Excel 21. /// </summary> 22. /// <param name="gridView">DataGridView对象</param> 23. /// <param name="isShowExcle">是否显示Excel界面</param> 24. /// <returns></returns> 25. public bool ExportDataGridview(DataGridView gridView, bool isShowExcle) 26. {
27. if (gridView.Rows.Count == 0) 28. return false; 29. //建立Excel对象 30. Excel.Application excel = new Excel.Application(); 31. excel.Application.Workbooks.Add(true); 32. excel.Visible = isShowExcle;
33. //生成字段名称 34. for (int i = 0; i < gridView.ColumnCount; i++) 35. {
36. excel.Cells[1, i + 1] = gridView.Columns[i].HeaderText; 37. }
38. //填充数据 39. for (int i = 0; i < gridView.RowCount - 1; i++) //循环行 40. {
41.
42. for (int j = 0; j < gridView.ColumnCount; j++) //循环列 43. {
44. if (gridView[j, i].ValueType == typeof(string)) //判断DataGirdView中数据的类型 45. {
46. excel.Cells[i + 2, j + 1] = "'" + gridView[j, i].Value.ToString(); 47. }
48. else 49. {
50. excel.Cells[i + 2, j + 1] = gridView[j, i].Value.ToString(); 51. }
52. }
53. }
54. return true; 55. }
56. private void button1_Click(object sender, EventArgs e) 57. {
58. this.ExportDataGridview(dataGridView1, true); 59. }
60. private void Form1_Load(object sender, EventArgs e) 61. {
62. SqlConnection con = new SqlConnection("Server=.;uid=sa;pwd=123;DataBase=accp;"); 63. SqlDataAdapter dap = new SqlDataAdapter("select * from userInfo", con); 64. DataSet ds = new DataSet(); 65. dap.Fill(ds);
66. dataGridView1.DataSource = ds.Tables[0].DefaultView; 67. }
68.
69. }
70.}