读到一个Excel文件

我正在尝试使用C#读取Excel表,并将每行存储到数组中。 我能够打开文件,但我正在使用的代码读取到“2D对象”数组,但我想阅读信息到1Dstring数组。

static void Main(string[] args) { // Reference to Excel Application. Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(Path.GetFullPath("excelpractice1.xlsx")); // Get the first worksheet. Excel.Worksheet xlWorksheet = (Excel.Worksheet)xlWorkbook.Sheets.get_Item(1); // Get the range of cells which has data. Excel.Range xlRange = xlWorksheet.UsedRange; // Get an object array of all of the cells in the worksheet with their values. object[,] valueArray = (object[,])xlRange.get_Value(Excel.XlRangeValueDataType.xlRangeValueDefault); // Close the Workbook. xlWorkbook.Close(false); // Relase COM Object by decrementing the reference count. Marshal.ReleaseComObject(xlWorkbook); // Close Excel application. xlApp.Quit(); // Release COM object. Marshal.FinalReleaseComObject(xlApp); Console.ReadLine(); } } } 

`

对不起,我只是想评论。 = X但是它为你工作吗? LinqToExcel是一个伟大的库操作电子表格! 请让我知道如果有任何疑问呢。

=)