请问怎么用select * from读取一个excel工作溥内N个sheet(表)的数据?
选择一个表的示例: "select * from [Sheet1$]";但一个文件内有未知个Sheet,该怎么做。
using System; using Microsoft.Office.Interop.Excel; namespace TestOffice { class Program { static void Main(string[] args) { Application excel = new Application(); Workbook workbook = excel.Workbooks.Open(@"C:\tmp\test\test.xls"); for (int i = 1; i <= workbook.Sheets.Count; ++i) { Worksheet sheet = workbook.Sheets[i]; Range firstCell = sheet.UsedRange[1, 1]; object[,] data = sheet.UsedRange.get_Value(); if (data != null) { for (int row = 1; row <= data.GetLength(0); ++row) { for (int column = 1; column <= data.GetLength(1); ++column) { if (data[row, column] != null) { Console.WriteLine("Found data in sheet {0} at row {1} and column {2} : {3}", sheet.Name, row + firstCell.Row - 1, column + firstCell.Column - 1, data[row, column]); } } } } } Console.ReadLine(); } } }(上面的代码可能不是正确...)