Oledb跳过excel文件的第一列。第一列是空的

时间:2013-06-26 15:37:16

标签: c# excel oledb xls oledbcommand

问题是第一列是空的,无法读取。 enter image description here

为了阅读该文件,我编写了以下代码:

            MyConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "'" + filename + "'" + ";Extended Properties=\"Excel 8.0;IMEX=1;HDR=NO;TypeGuessRows=0\"");

            DtSet = new DataSet();
            MyConnection.Open();
            var dt = MyConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

                MyCommand = new OleDbDataAdapter("select * from [$first]", MyConnection);
                MyCommand.Fill(DtSet); // filldata

                dataExcel.AddRange(fillData(DtSet.Tables["Table"]).Select(info => info.ToList())); 
            }

List<List<string>> fillData(DataTable DtSet) //reader
        {
            List<List<string>> data = new List<List<string>>();
            foreach (DataRow item in DtSet.Rows)
            {
                if (item == null) continue;
                List<string> gettedData = new List<string>();
                int i = 0;
                foreach (var columnitem in item.ItemArray)
                {
                    if (i == 0 && columnitem.ToString() == "") ;
                    else gettedData.Add(columnitem.ToString()); //add data

                    i++;
                }
                data.Add(gettedData);
            }
            return data;
        }

此代码可以工作,但第一列,他没有看到。谢谢!

0 个答案:

没有答案