它不是很漂亮,但你可以使用COM互操作到Excel應用程序讀入紙。
這將允許您訪問任何您喜歡的單元格,但更容易出錯。
System.Reflection.Missing ms = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
xlApp.Visible = true;
Microsoft.Office.Interop.Excel.Workbook xlBook = xlApp.Workbooks.Open(@"C:\Demo.xlsx", ms, ms, ms, ms, ms, ms, ms, ms, ms, ms, ms, ms, ms, ms);
Microsoft.Office.Interop.Excel.Worksheet xlSheet = xlBook.Sheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
Microsoft.Office.Interop.Excel.Range rng = xlSheet.Cells[1, 1] as Microsoft.Office.Interop.Excel.Range;
System.Console.WriteLine(String.Format("{0} {1} {2}", rng.Value2, rng.Text, rng.NumberFormat));
xlBook.Close(false, ms, ms);
xlApp.Quit();
System.Console.ReadLine();
謝謝,但這些都不解決我的問題。我知道如何使用OleDB連接到Excel,但我得到的數據是不完整的,因爲我不知道每個單元格的格式類型。 – idophir 2009-09-16 13:09:10
OP確實要求確定單元格格式(指問題中的樣式),而不是如何通過OLEDB進行連接。雖然如果你閱讀米奇提供的4個鏈接,這也會給你答案。 – 2010-12-19 22:15:55