首页 | 互联网 | IT动态 | IT培训 | Cisco | Windows | Linux | Java | .Net | Oracle | 软件测试 | C/C++ | 嵌入式开发 | 存储世界 | 服务器
网络设备 | IDC | 安全 | 求职招聘 | 数字网校 | 网页设计 | 平面设计 | 技术专题 | 电子书下载 | 教学视频 | 源码下载 | 搜索 | 博客 | 论坛
中国IT实验室Dotnet频道
中国IT教育
Google
首页 ASP.NET  C#  XML/WebService ADO.NET VC.NET VB.NET .NET 资讯动态 专题 RSS订阅 讨论 下载
您现在的位置: 中国IT实验室 >> Dotnet >> C# >> 正文

C# 开发和使用中的23个技巧

  15.怎样把键盘输入的‘+’符号变成‘A’?
  textBox的KeyPress事件中

  if(e.KeyChar == '+')

  {

  SendKeys.Send("A"); 

  e.Handled = true; 

  } 

  16.怎样使Winform启动时直接最大化?

  this.WindowState = FormWindowState.Maximized;  

 
  17.c#怎样获取当前日期及时间,在sql语句里又是什么?

  c#: DateTime.Now

  sql server: GetDate()

  18.怎样访问winform DataGrid的某一行某一列,或每一行每一列?

  dataGrid[row,col]

  19.怎样为DataTable进行汇总,比如DataTable的某列值‘延吉'的列为多少?

  dt.Select("城市='延吉'").Length; 

  20.DataGrid数据导出到Excel后0212等会变成212。怎样使它导出后继续显示为0212?

  range.NumberFormat = "0000"; 

  21.

  ① 怎样把DataGrid的数据导出到Excel以供打印?

  ② 之前已经为DataGrid设置了TableStyle,即自定义了列标题和要显示的列,如果想以自定义的视图导出数据该怎么办?

  ③ 把数据导出到Excel后,怎样为它设置边框啊?

  ④ 怎样使从DataGrid导出到Excel的某个列居中对齐?

  ⑤ 数据从DataGrid导出到Excel后,怎样使标题行在打印时出现在每一页?

  ⑥ DataGrid数据导出到Excel后打印时每一页显示’当前页/共几页’,怎样实现?

  ①

  private void button1_Click(object sender, System.EventArgs e)
  {
  int row_index, col_index; 
  row_index = 1; 
  col_index = 1; 
  Excel.ApplicationClass excel = new Excel.ApplicationClass(); 
  excel.Workbooks.Add(true); 
  DataTable dt = ds.Tables["table"]; 
  foreach(DataColumn dcHeader in dt.Columns)
  excel.Cells[row_index, col_index++] = dcHeader.ColumnName; 
  foreach(DataRow dr in dt.Rows)
  {
  col_index = 0; 
  foreach(DataColumn dc in dt.Columns)
  {
  excel.Cells[row_index+1, col_index+1] = dr[dc]; 
  col_index++; 
  }
  row_index++; 
  }
  excel.Visible = true; 
  }

  private void Form1_Load(object sender, System.EventArgs e)
  {
  SqlConnection conn = new SqlConnection("server=tao; uid=sa; pwd=; database=pubs"); 
  conn.Open(); 

  SqlDataAdapter da = new SqlDataAdapter("select * from authors", conn); 
  ds = new DataSet(); 
  da.Fill(ds, "table"); 
  dataGrid1.DataSource = ds; 
  dataGrid1.DataMember = "table"; 
  }  


  ②dataGrid1.TableStyles[0].GridColumnStyles[index].HeaderText; //index可以从0~dataGrid1.TableStyles[0].GridColumnStyles.Count遍历。

  ③ Excel.Range range; 

  range=worksheet.get_Range(worksheet.Cells[1,1],xSt.Cells[ds.Tables[0].Rows.Count+1,ds.Tables[0].Columns.Count]); 

  range.BorderAround(Excel.XlLineStyle.xlContinuous,Excel.XlBorderWeight.xlThin,Excel.XlColorIndex.xlColorIndexAutomatic,null); 

  range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic; 

  range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle =Excel.XlLineStyle.xlContinuous; 

  range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].Weight =Excel.XlBorderWeight.xlThin; 

  range.Borders[Excel.XlBordersIndex.xlInsideVertical].ColorIndex =Excel.XlColorIndex.xlColorIndexAutomatic; 

  range.Borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlContinuous; 

  range.Borders[Excel.XlBordersIndex.xlInsideVertical].Weight = Excel.XlBorderWeight.xlThin; 

  ④ range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter

  ⑤ worksheet.PageSetup.PrintTitleRows = "$1:$1"; 

  ⑥ worksheet.PageSetup.CenterFooter = "第&P页 / 共&N页"; 

上一页  [1] [2] [3] [4] [5] [6] 下一页

【责编:Peng】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·WEB程序开发--ASP.NET和PHP、JSP究竟学哪个?
 ·五步带你入门XML
 ·关于Java框架技术专题
 ·XML全攻略技术专题
 ·JAVA开源技术介绍专题
 ·Java嵌入式开发之J2ME技术专题
 ·超前体验 Oracle 11g的5个新特性…
 ·揭密使用VB.NET的五个实用技巧
 ·Oracle和SQL Server常用函数对比专题…
 ·展现C#世界 C#程序设计专题…
 今日更新
 社区讨论
 博客论点
 频道精选
 Dotnet频道相关导航