コード例 #1
0
        public ExcelOperationAspose(string excelFile, int columnHeaderRow = 0, int readNumberOfRows = 0, string worksheet = "", bool loadAllSheets = false)
        {
            File.Exists(excelFile).Should()
            .BeTrue($"The file requested for excel read is not found in the file system. File path {excelFile}");

            _xBook  = new Workbook(excelFile);
            _sheets = new ExcelSheets();

            if (loadAllSheets)
            {
                foreach (Worksheet sheet in _xBook.Worksheets)
                {
                    _sheets.Set(sheet.Name, new ExcelOperationSheetAspose(sheet, columnHeaderRow, readNumberOfRows));
                }
            }
            else
            {
                if (string.IsNullOrEmpty(worksheet))
                {
                    if (!WorksheetNames.Any())
                    {
                        throw new Exception("There is no worksheet to load");
                    }

                    _sheets.Set(_xBook.Worksheets[0].Name, new ExcelOperationSheetAspose(_xBook.Worksheets[0], columnHeaderRow, readNumberOfRows));
                }
                else
                {
                    if (!WorksheetNames.Contains(worksheet))
                    {
                        throw new Exception("The worksheet specified does not exist in the excel file");
                    }

                    _sheets.Set(worksheet, new ExcelOperationSheetAspose(_xBook.Worksheets[worksheet], columnHeaderRow, readNumberOfRows));
                }
            }
        }
コード例 #2
0
 public void Dispose()
 {
     _xBook  = null;
     _sheets = null;
 }