/// <summary> /// 加载表单(使用缓存机制提高效率) /// </summary> /// <param name="path"></param> /// <returns></returns> private static DataTable LoadSheet(string path) { DataTable sheet = null; sheet = DataMemory.GetSheet(path); if (sheet != null) { return(sheet); } else { try { FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); excelReader.IsFirstRowAsColumnNames = true; DataSet datSet = excelReader.AsDataSet(); if (datSet.Tables.Count < 1) { throw new Exception("Excel not found sheet: " + path); } sheet = datSet.Tables[0]; if (sheet.Rows.Count <= 0) { throw new Exception("Excel sheet not data: " + path); } DataMemory.SetSheet(path, sheet); excelReader.Close(); } catch (System.Exception ex) { throw new Exception(ex.StackTrace); } return(sheet); } }