2011-02-01 87 views
0

我创建一个从C#中的Excel文件与数据验证,它似乎像组合与choosen可能性如何在C#读取Excel文件中的数据

string mList1 = "=ProductCode"; 
       oRng = oSheet.get_Range("H8", "H9"); 
       oRng.Name = "ProductCode"; 
       int t = dt.Rows.Count + 2; 
       string st = "F" + t; 
       oRng = oSheet.get_Range("F2", st); 
       oRng.Validation.Add(XlDVType.xlValidateList, 
        XlDVAlertStyle.xlValidAlertStop, 
        Missing.Value, mList1, Missing.Value); 

现在我想读取Excel文件,并选择的项从组合 我seccues读取所有数据,但数据验证

在不同势列中读取数据 -

Microsoft.Office.Interop.Excel.Application ExcelObj = null; 
      ExcelObj = new Microsoft.Office.Interop.Excel.Application(); 
      Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open("C:\\Documents and Settings\\rachelg\\My Documents\\xxx.xls" 
      ,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); 

      Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets; 
      Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1); 
      for(int x = 1; x <= 5; x++) 
      { 
      string sd = ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[x, 1]).Text.ToString(); 
       System.Console.WriteLine(sd);//this one column 
} 

我有数据validati但我不知道进入它 你能帮助我吗? 紧急!!!!!

+0

紧急?如果你没有修复它,那么没有核弹会熄灭吗? – 2011-02-01 17:28:54

回答

0

对于很大程度上简单的操作来说,这似乎有点多。

虽然没有直接回答你的问题,但是我回来的这篇文章可能有帮助:accessing data record from Excel in VB.NET

+0

它如何帮助我? – user598790 2011-02-07 10:01:21