예제 #1
0
        /// <summary>
        /// given a POI POIFSFileSystem object, and a specific directory
        /// within it, Read in its Workbook and populate the high and
        /// low level models.  If you're Reading in a workbook...start here.
        /// </summary>
        /// <param name="directory">the POI filesystem directory to Process from</param>
        /// <param name="fs">the POI filesystem that Contains the Workbook stream.</param>
        /// <param name="preserveNodes">whether to preseve other nodes, such as
        /// macros.  This takes more memory, so only say yes if you
        /// need to. If Set, will store all of the POIFSFileSystem
        /// in memory</param>
        public HSSFWorkbook(DirectoryNode directory, POIFSFileSystem fs, bool preserveNodes)
            : base(directory, fs)
        {

            String workbookName = GetWorkbookDirEntryName(directory);

            this.preserveNodes = preserveNodes;

            // If we're not preserving nodes, don't track the
            //  POIFS any more
            if (!preserveNodes)
            {
                this.filesystem = null;
                this.directory = null;
            }

            _sheets = new ArrayList(INITIAL_CAPACITY);
            names = new ArrayList(INITIAL_CAPACITY);

            // Grab the data from the workbook stream, however
            //  it happens to be spelled.
            Stream stream = directory.CreatePOIFSDocumentReader(workbookName);


            IList records = RecordFactory.CreateRecords(stream);

            workbook = Workbook.CreateWorkbook(records);
            SetPropertiesFromWorkbook(workbook);
            int recOffset = workbook.NumRecords;

            // Convert all LabelRecord records to LabelSSTRecord
            ConvertLabelRecords(records, recOffset);
            RecordStream rs = new RecordStream(records, recOffset);
            while (rs.HasNext())
            {
                Sheet sheet = Sheet.CreateSheet(rs);
                _sheets.Add(new HSSFSheet(this, sheet));
            }

            for (int i = 0; i < workbook.NumNames; ++i)
            {
                HSSFName name = new HSSFName(this, workbook.GetNameRecord(i));
                names.Add(name);
            }
        }