Beispiel #1
0
    /// <summary>
    /// 加载
    /// </summary>
    public bool Load()
    {
        try
        {
            _stream = new FileStream(ExcelPath, FileMode.Open, FileAccess.Read);

            if (ExcelPath.IndexOf(".xlsx") > 0)
            {
                _workbook = new XSSFWorkbook(_stream);
            }
            else if (ExcelPath.IndexOf(".xls") > 0)
            {
                _workbook = new HSSFWorkbook(_stream);
            }

            for (int i = 0; i < _workbook.NumberOfSheets; i++)
            {
                ISheet sheet = _workbook.GetSheetAt(i);
                if (sheet.SheetName.StartsWith(StrSheetLabel))
                {
                    SheetData sheetData = new SheetData(sheet.SheetName);
                    sheetData.Parase(sheet);
                    _sheetDataList.Add(sheetData);
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"Load Error:{ex}");
            return(false);
        }

        //如果没有找到有效的工作页
        if (_sheetDataList.Count == 0)
        {
            MessageBox.Show(string.Format("Not found include 't_' sheet in the excel file : {0}", ExcelName));
            return(false);
        }

        return(true);        //加载成功
    }