Exemplo n.º 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);
                _sheetReadersByInteger.Add(sheetNumber, sheetReader);
                return(sheetReader);
            }
        }
Exemplo n.º 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 LightweightExcelReaderSheetNotFoundException(sheetName);
                }

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

                var sheetReader = new SheetReader(_zippedXlsxFile.GetWorksheetStream(sheetNumber.Value),
                                                  _zippedXlsxFile.SharedStringsStream, _zippedXlsxFile.IsDateTimeStream);
                _sheetReadersByInteger.Add(sheetNumber.Value, sheetReader);
                return(sheetReader);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }