Exemplo n.º 1
0
		/// <summary>
		/// The constructor for the record.
		/// </summary>
		/// <param name="biff">The GenericBiff record that should contain the correct type and data for the FORMULA record.</param>
		/// <param name="recordsStream">The stream into the records to which the FORMULA record belongs to. The record stream must be positioned just after the FORMULA record.</param>
		/// <exception cref="InvalidRecordIdException">
		/// An InvalidRecordIdException is thrown if biff contains an invalid type or invalid data.
		/// </exception>
		public FormulaRecord(GenericBiff biff, Stream recordsStream)
		{
			if(biff.Id == (ushort)RecordType.Formula)
			{
				Stream stream = biff.GetDataStream();
				BinaryReader reader = new BinaryReader(stream);
				
				ReadRowColXf(reader);
				FormulaValue val = new FormulaValue(reader.ReadDouble());
				
				_options = reader.ReadUInt16();
				_reserved = reader.ReadUInt32();
				_formulaLen = reader.ReadUInt16();
				_formulaData = reader.ReadBytes((int)(stream.Length - stream.Position));

				if(val.StringFollows)
				{
					GenericBiff r = new GenericBiff(recordsStream);
					while(r.Id != (ushort)RecordType.String)
					{
						r = new GenericBiff(recordsStream);
					}

					StringValueRecord stringValue = new StringValueRecord(r);
					_value = stringValue.Value;
				}
				else
					_value = val.Value;
			}
			else
				throw new InvalidRecordIdException(biff.Id, RecordType.Formula);
		}
Exemplo n.º 2
0
        /// <summary>
        /// The constructor for the record.
        /// </summary>
        /// <param name="biff">The GenericBiff record that should contain the correct type and data for the FORMULA record.</param>
        /// <param name="recordsStream">The stream into the records to which the FORMULA record belongs to. The record stream must be positioned just after the FORMULA record.</param>
        /// <exception cref="InvalidRecordIdException">
        /// An InvalidRecordIdException is thrown if biff contains an invalid type or invalid data.
        /// </exception>
        public FormulaRecord(GenericBiff biff, Stream recordsStream)
        {
            if (biff.Id == (ushort)RecordType.Formula)
            {
                Stream       stream = biff.GetDataStream();
                BinaryReader reader = new BinaryReader(stream);

                ReadRowColXf(reader);
                FormulaValue val = new FormulaValue(reader.ReadDouble());

                _options     = reader.ReadUInt16();
                _reserved    = reader.ReadUInt32();
                _formulaLen  = reader.ReadUInt16();
                _formulaData = reader.ReadBytes((int)(stream.Length - stream.Position));

                if (val.StringFollows)
                {
                    GenericBiff r = new GenericBiff(recordsStream);
                    while (r.Id != (ushort)RecordType.String)
                    {
                        r = new GenericBiff(recordsStream);
                    }

                    StringValueRecord stringValue = new StringValueRecord(r);
                    _value = stringValue.Value;
                }
                else
                {
                    _value = val.Value;
                }
            }
            else
            {
                throw new InvalidRecordIdException(biff.Id, RecordType.Formula);
            }
        }
Exemplo n.º 3
0
        private Biff GetCorrectRecord(GenericBiff record, Stream stream, SstRecord sst)
        {
            Biff ret = record;
            switch (record.Id)
            {
                case (ushort)RecordType.Bof:
                    BofRecord bof = new BofRecord(record);
                    if (bof.Version < 0x0600)
                        throw new Exception("Versions below Excel 97/2000 are currently not supported.");

                    ret = bof;
                    break;
                case (ushort)RecordType.Boundsheet:
                    ret = new BoundSheetRecord(record);
                    break;
                case (ushort)RecordType.Index:
                    ret = new IndexRecord(record);
                    break;
                case (ushort)RecordType.DbCell:
                    ret = new DbCellRecord(record);
                    break;
                case (ushort)RecordType.Row:
                    ret = new RowRecord(record);
                    break;
                case (ushort)RecordType.Continue:
                    ret = new ContinueRecord(record);
                    break;
                case (ushort)RecordType.Blank:
                    ret = new BlankRecord(record);
                    break;
                case (ushort)RecordType.BoolErr:
                    ret = new BoolErrRecord(record);
                    break;
                case (ushort)RecordType.Formula:
                    ret = new FormulaRecord(record, stream);
                    break;
                case (ushort)RecordType.Label:
                    ret = new LabelRecord(record);
                    break;
                case (ushort)RecordType.LabelSst:
                    ret = new LabelSstRecord(record, sst);
                    break;
                case (ushort)RecordType.MulBlank:
                    ret = new MulBlankRecord(record);
                    break;
                case (ushort)RecordType.MulRk:
                    ret = new MulRkRecord(record);
                    break;
                case (ushort)RecordType.String:
                    ret = new StringValueRecord(record);
                    break;
                case (ushort)RecordType.Xf:
                    ret = new XfRecord(record);
                    break;
                case (ushort)RecordType.Rk:
                    ret = new RkRecord(record);
                    break;
                case (ushort)RecordType.Number:
                    ret = new NumberRecord(record);
                    break;
                case (ushort)RecordType.Array:
                    ret = new ArrayRecord(record);
                    break;
                case (ushort)RecordType.ShrFmla:
                    ret = new SharedFormulaRecord(record);
                    break;
                case (ushort)RecordType.Table:
                    ret = new TableRecord(record);
                    break;
                case (ushort)RecordType.Sst:
                    ret = new SstRecord(record, stream);
                    break;
                case (ushort)RecordType.Eof:
                    ret = new EofRecord(record);
                    break;
                case (ushort)RecordType.Font:
                    ret = new FontRecord(record);
                    break;
                case (ushort)RecordType.Format:
                    ret = new Net.SourceForge.Koogra.Excel.Records.FormatRecord(record);
                    break;
                case (ushort)RecordType.Palette:
                    ret = new PaletteRecord(record);
                    break;
                case (ushort)RecordType.Hyperlink:
                    ret = new HyperLinkRecord(record);
                    break;
            }

            return ret;
        }