W3CHINA Blog首页    管理页面    写新日志    退出


«December 2025»
123456
78910111213
14151617181920
21222324252627
28293031

 

公告

Back Today!

Hold on~ 

Come on~

最新日志

正规判断email
文件md5值
javascript:操作url参数的函
C#淡出淡入窗体
VSS 6 admin用户的密码破解
没用过的东东(sql)
初学ajax(C#)
页面开发的准则一
textbox忽略html验证
这点破东东,老是记不住,nnd!

最近的评论

回复:初学ajax(C#)
回复:C#淡出淡入窗体
回复:ivr的部分动作
回复:textbox忽略html验证
回复:VSS 6 admin用户的密码破
回复:VSS 6 admin用户的密码破
回复:VSS 6 admin用户的密码破
回复:VSS 6 admin用户的密码破
回复:excel中的工作表名sheetn
回复:VSS 6 admin用户的密码破

连接




专题

首页(39)
IVR(4)
SQLSERVER(12)
AJAX(0)
.net(13)
小技巧(4)
english(2)

留言

签写新留言

请教

统计

blog名称:执著
日志总数:39
评论数量:43
留言数量:0
访问次数:247560
建立时间:2005年3月4日

[.net]操作excel的类
执著 发表于 2005/8/24 11:44:19

using System;using System.Data;using System.Data.OleDb;using Excel;using System.Collections.Specialized; namespace winapp_test{ /// <summary> /// class_excel 的摘要说明。 /// </summary> public class class_excel {  private string _filename;  Excel.ApplicationClass app = new ApplicationClass();  Excel.Workbook excel_wb;  public class_excel(string f)  {   //   // TODO: 在此处添加构造函数逻辑   //   _filename = f;   excel_wb = app.Workbooks.Open(_filename,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);  }   public StringCollection countexcel() //返回工作表名  {   if(System.IO.File.Exists(_filename))   {    StringCollection a = new StringCollection();    for(int i = 1;i<=excel_wb.Worksheets.Count;i++)    {     a.Add(((Excel.Worksheet)excel_wb.Worksheets[i]).Name);    }    return a;   }   else   {    return null;   }  }   public DataSet proces() //用datset返回整个excel  {   string strConn  = "Provider=Microsoft.Jet.OleDb.4.0;";    strConn += "data source=" + _filename + ";";    strConn += "Extended Properties=Excel 8.0;";     strConn += "HDR=Yes;IMEX=1";      OleDbConnection objConn = new OleDbConnection(strConn);   DataSet ds = new DataSet();   OleDbDataAdapter oldda = new OleDbDataAdapter();    foreach(string sheetname in countexcel())   {    string a = "select * from ";    a += sheetname;    oldda.SelectCommand.CommandText = a;    oldda.Fill(ds,sheetname);   }   return ds;  }   public int rowcount(string sheetname) //行数  {   return ((Excel.Worksheet)excel_wb.Worksheets.get_Item(sheetname)).UsedRange.Rows.Count;  }  public int colcount(string sheetname) //列数  {   return ((Excel.Worksheet)excel_wb.Worksheets.get_Item(sheetname)).UsedRange.Columns.Count;  }   public string range(string sheetname,int row,int col) //返回指定单元格的文本  {   Excel.Worksheet ws = (Excel.Worksheet)excel_wb.Worksheets.get_Item(sheetname);   Excel.Range r = (Excel.Range)(ws.Cells[row,col]);   return r.Text.ToString();  }   public void close() //关闭  {   app.Workbooks.Close();   app.Quit();   app = null;  } }} 自己写的,水平实在有限

阅读全文(2552) | 回复(0) | 编辑 | 精华


发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



 

 

 


站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.469 second(s), page refreshed 144799208 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号