代码如下:问题是 无法导入int型的数据,速求!!!!!!!!!!先谢谢各位了!!
try
{
//通过Jet OLEDB
string Path = this.txtFilePath.Text;
DataSet ds = null;
string strall = null;
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();//打开connection对象
string strExcel = "";
OleDbDataAdapter myCommand = null;//配置OLEDB适配器
//strExcel = "select * from [Sheet1$]";
if (this.cbxAccount.Checked == true)
strExcel = "select 帐号 from [Sheet1$]";
else if (this.cbxNick.Checked == true)
strExcel = "select 昵称 from [Sheet1$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);//COMMAND对象
ds = new DataSet();
myCommand.Fill(ds);//填充DataSet
paramList.Clear();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i].ItemArray[0].ToString().Trim() != "")
{
//新建DataRow行
paramList.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
}
}
if (paramList.Count == 0)
{
MessageBox.Show("文件错误!");
return;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
我建议楼主可以学习下NPOI,对Excel的操作特别的简单,如果有需要我可以给你发个Demo,就是关于你现在做的这个