Пример #1
0
        /// <summary>
        /// Get a SheetReader instance representing the worksheet at the given zero-based index
        /// </summary>
        /// <param name="sheetNumber">The zero-based index of the worksheet</param>
        public SheetReader this[int sheetNumber]
        {
            get
            {
                if (_sheetReadersByInteger == null)
                {
                    _sheetReadersByInteger = new Dictionary <int, SheetReader>();
                }

                if (_sheetReadersByInteger.ContainsKey(sheetNumber))
                {
                    return(_sheetReadersByInteger[sheetNumber]);
                }

                if (_zippedXlsxFile == null)
                {
                    _zippedXlsxFile = new ZippedXlsxFile(_filePath);
                }

                var sheetReader = new SheetReader(_zippedXlsxFile.GetWorksheetStream(sheetNumber),
                                                  _zippedXlsxFile.SharedStringsStream, _zippedXlsxFile.IsDateTimeStream, ReadNextBehaviour);
                _sheetReadersByInteger.Add(sheetNumber, sheetReader);
                return(sheetReader);
            }
        }
Пример #2
0
        /// <summary>
        /// Get a SheetReader instance representing the worksheet with the given name
        /// </summary>
        /// <param name="sheetName">The name of the worksheet</param>
        /// <exception cref="IndexOutOfRangeException">Will throw if the worksheet does not exist</exception>
        public SheetReader this[string sheetName]
        {
            get
            {
                if (_sheetnameLookup == null)
                {
                    _sheetnameLookup = new Dictionary <string, int>();
                }

                if (_zippedXlsxFile == null)
                {
                    _zippedXlsxFile = new ZippedXlsxFile(_filePath);
                }

                if (_sheetReadersByInteger == null)
                {
                    _sheetReadersByInteger = new Dictionary <int, SheetReader>();
                }

                int?sheetNumber;
                if (_sheetnameLookup.ContainsKey(sheetName))
                {
                    sheetNumber = _sheetnameLookup[sheetName];
                }
                else
                {
                    sheetNumber = ReadSheetNumberFromXml(sheetName);
                }

                if (!sheetNumber.HasValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(sheetName), $"Sheet with name '{sheetName}' was not found in the workbook");
                }

                if (_sheetReadersByInteger.ContainsKey(sheetNumber.Value))
                {
                    var existingSheet = _sheetReadersByInteger[sheetNumber.Value];
                    return(existingSheet);
                }

                var sheetReader = new SheetReader(_zippedXlsxFile.GetWorksheetStream(sheetNumber.Value),
                                                  _zippedXlsxFile.SharedStringsStream, _zippedXlsxFile.IsDateTimeStream, ReadNextBehaviour);
                _sheetReadersByInteger.Add(sheetNumber.Value, sheetReader);
                return(sheetReader);
            }
        }
Пример #3
0
 /// <summary>
 /// Construct an ExcelReader from a Stream
 /// </summary>
 /// <param name="stream">A stream pointing towards an xlsx format workbook</param>
 public ExcelReader(Stream stream)
 {
     _zippedXlsxFile = new ZippedXlsxFile(stream);
 }
Пример #4
0
 /// <summary>
 /// Construct an ExcelReader from a file path
 /// </summary>
 /// <param name="filePath">A file path pointing towards an xlsx format workbok</param>
 public ExcelReader(string filePath)
 {
     _filePath       = filePath;
     _zippedXlsxFile = new ZippedXlsxFile(filePath);
 }