它不是很漂亮,但你可以使用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