Example #1
0
        // TODO make this class into a record aggregate

        private static ExternSheetRecord ReadExtSheetRecord(RecordStream rs)
        {
            List<ExternSheetRecord> temp = new List<ExternSheetRecord>(2);
            while (rs.PeekNextClass() == typeof(ExternSheetRecord))
            {
                temp.Add((ExternSheetRecord)rs.GetNext());
            }

            int nItems = temp.Count;
            if (nItems < 1)
            {
                throw new Exception("Expected an EXTERNSHEET record but got ("
                        + rs.PeekNextClass().Name + ")");
            }
            if (nItems == 1)
            {
                // this is the normal case. There should be just one ExternSheetRecord
                return temp[0];
            }
            // Some apps generate multiple ExternSheetRecords (see bug 45698).
            // It seems like the best thing to do might be to combine these into one
            ExternSheetRecord[] esrs = new ExternSheetRecord[nItems];
            esrs = temp.ToArray();
            return ExternSheetRecord.Combine(esrs);
        }
        /// <summary>
        /// Creates a stub Workbook from the supplied records,
        /// suitable for use with the {@link HSSFFormulaParser}
        /// </summary>
        /// <param name="externs">The ExternSheetRecords in your file</param>
        /// <param name="bounds">The BoundSheetRecords in your file</param>
        /// <param name="sst">TThe SSTRecord in your file.</param>
        /// <returns>A stub Workbook suitable for use with HSSFFormulaParser</returns>
        public static InternalWorkbook CreateStubWorkbook(ExternSheetRecord[] externs,
                BoundSheetRecord[] bounds, SSTRecord sst)
        {
            List<Record> wbRecords = new List<Record>();

            // Core Workbook records go first
            if (bounds != null)
            {
                for (int i = 0; i < bounds.Length; i++)
                {
                    wbRecords.Add(bounds[i]);
                }
            }
            if (sst != null)
            {
                wbRecords.Add(sst);
            }

            // Now we can have the ExternSheetRecords,
            //  preceded by a SupBookRecord
            if (externs != null)
            {
                wbRecords.Add(SupBookRecord.CreateInternalReferences(
                        (short)externs.Length));
                for (int i = 0; i < externs.Length; i++)
                {
                    wbRecords.Add(externs[i]);
                }
            }

            // Finally we need an EoF record
            wbRecords.Add(EOFRecord.instance);

            return InternalWorkbook.CreateWorkbook(wbRecords);
        }
Example #3
0
        public static ExternSheetRecord Combine(ExternSheetRecord[] esrs)
        {
            ExternSheetRecord result = new ExternSheetRecord();

            for (int i = 0; i < esrs.Length; i++)
            {
                ExternSheetRecord esr = esrs[i];
                int nRefs             = esr.NumOfREFRecords;
                for (int j = 0; j < nRefs; j++)
                {
                    result.AddREFRecord(esr.GetRef(j));
                }
            }
            return(result);
        }
 /// <summary>
 /// Creates a stub workbook from the supplied records,
 /// suitable for use with the HSSFFormulaParser
 /// </summary>
 /// <param name="externs">The ExternSheetRecords in your file</param>
 /// <param name="bounds">A stub Workbook suitable for use with HSSFFormulaParser</param>
 /// <returns>A stub Workbook suitable for use with {@link HSSFFormulaParser}</returns>
 public static InternalWorkbook CreateStubWorkbook(ExternSheetRecord[] externs,
         BoundSheetRecord[] bounds)
 {
     return CreateStubWorkbook(externs, bounds, null);
 }
 public static ExternSheetRecord Combine(ExternSheetRecord[] esrs)
 {
     ExternSheetRecord result = new ExternSheetRecord();
     for (int i = 0; i < esrs.Length; i++)
     {
         ExternSheetRecord esr = esrs[i];
         int nRefs = esr.NumOfREFRecords;
         for (int j = 0; j < nRefs; j++)
         {
             result.AddREFRecord(esr.GetRef(j));
         }
     }
     return result;
 }
Example #6
0
        public LinkTable(int numberOfSheets, WorkbookRecordList workbookRecordList)
        {
            _workbookRecordList = workbookRecordList;
            _definedNames = new List<NameRecord>();
            _externalBookBlocks = new ExternalBookBlock[] {
				new ExternalBookBlock(numberOfSheets),
		    };
            _externSheetRecord = new ExternSheetRecord();
            _recordCount = 2;

            // tell _workbookRecordList about the 2 new records

            SupBookRecord supbook = _externalBookBlocks[0].GetExternalBookRecord();

            int idx = FindFirstRecordLocBySid(CountryRecord.sid);
            if (idx < 0)
            {
                throw new Exception("CountryRecord not found");
            }
            _workbookRecordList.Add(idx + 1, _externSheetRecord);
            _workbookRecordList.Add(idx + 1, supbook);
        }
Example #7
0
        private WorkbookRecordList _workbookRecordList; // TODO - would be nice to Remove this

        public LinkTable(List<Record> inputList, int startIndex, WorkbookRecordList workbookRecordList, Dictionary<String, NameCommentRecord> commentRecords)
        {

            _workbookRecordList = workbookRecordList;
            RecordStream rs = new RecordStream(inputList, startIndex);

            ArrayList temp = new ArrayList();
            while (rs.PeekNextClass() == typeof(SupBookRecord))
            {
                temp.Add(new ExternalBookBlock(rs));
            }

            //_externalBookBlocks = new ExternalBookBlock[temp.Count];
            _externalBookBlocks = (ExternalBookBlock[])temp.ToArray(typeof(ExternalBookBlock));
            temp.Clear();

            if (_externalBookBlocks.Length > 0)
            {
                // If any ExternalBookBlock present, there is always 1 of ExternSheetRecord
                if (rs.PeekNextClass() != typeof(ExternSheetRecord))
                {
                    // not quite - if written by google docs
                    _externSheetRecord = null;
                }
                else
                {
                    _externSheetRecord = ReadExtSheetRecord(rs);
                }
            }
            else
            {
                _externSheetRecord = null;
            }

            _definedNames = new List<NameRecord>();
            // collect zero or more DEFINEDNAMEs id=0x18
            while (true)
            {

                Type nextClass = rs.PeekNextClass();
                if (nextClass == typeof(NameRecord))
                {
                    NameRecord nr = (NameRecord)rs.GetNext();
                    _definedNames.Add(nr);
                }
                else if (nextClass == typeof(NameCommentRecord))
                {
                    NameCommentRecord ncr = (NameCommentRecord)rs.GetNext();
                    commentRecords.Add(ncr.NameText, ncr);
                }
                else
                {
                    break;
                }
            }

            _recordCount = rs.GetCountRead();
            for (int i = startIndex; i < startIndex + _recordCount; i++)
            {
                _workbookRecordList.Records.Add(inputList[i]);
            }

        }