提供两种方法:一个是直接打开excel文件,然后逐行读取,速度较慢;还有一种方法是通过OleDb连接,把excel文件作为数据源来读取
方法一:这种直接读取单元格的方法释放很重要。
Excel.Application excel = null;
Excel.Workbooks wbs = null;
Excel.Workbook wb = null;
Excel.Worksheet ws = null;
Excel.Range range1 = null;
object Nothing = System.Reflection.Missing.Value;
try
{
excel = new Excel.Application();
excel.UserControl = true;
excel.DisplayAlerts = false;
excel.Application.Workbooks.Open(this.FilePath,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing ) ;
wbs = excel.Workbooks;
wb = wbs[1];
ws = (Excel.Worksheet)wb.Work