日期:2014-05-18  浏览次数:20747 次

在线等待,关于读取Excel表中数据的问题!!! 急急急!!
我用,Excel的com写了,读取excel的程序.
已经取得了当前的worksheet,我现在想要取当前worksheet中一共有多少行,多少列,就没办法了.........

请各位帮帮我啊!!谢谢了
在线等待!!

------解决方案--------------------
遍历行列,直到值为null
------解决方案--------------------
如果把excel 作为数据源 读入 DataSet中,想操作数据表一样来操作,不是更容易么
------解决方案--------------------
用个dataGrid 存储读取的数据就行了

#region 打开选中的Excel表
private void GetConnect()
{
string Inxls = this.txtExcel.Text;
string strConn = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = ' " + Inxls.ToString() + " ';Extended Properties = Excel 8.0 ";
OleDbConnection myconn = new OleDbConnection(strConn);
string strCom = "select * from [Sheet1$] ";
myconn.Open();
OleDbDataAdapter mycommand = new OleDbDataAdapter(strCom, myconn);
myDataSet = new DataSet();
mycommand.Fill(myDataSet, "[Sheet1$] ");
myconn.Close();
}


//将数据表读取到DataGridView中

this.DataGrid1.Columns.Clear();
GetConnect();
DataGrid1.DataMember = "[Sheet1$] ";
DataGrid1.DataSource = myDataSet;


读取列数 this.DataGrid1.ColumnCount.ToString()
读取行数 this.DataGrid1.RowCount.ToString()

不知道这样符不符合 你的意思
------解决方案--------------------
无论是否规范,只要放在DataSet里面,以后就好操作。