Ejemplo n.º 1
0
        internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
        {
            if ((SaveData.ExcludedRecords & TExcludedRecords.Version) != 0)
            {
                return;                                                             //Note that this will invalidate the size, but it doesn't matter as this is not saved for real use. We could write blanks here if we wanted to keep the offsets right.
            }
            byte[] ExcelBuild; byte[] ExcelVersion;
            if (SaveData.BiffVersion == TXlsBiffVersion.Excel2003)
            {
                ExcelBuild   = Excel2003Build;
                ExcelVersion = Excel2003Version;
            }
            else
            {
                ExcelBuild   = Excel2007Build;
                ExcelVersion = Excel2007Version;
            }

            Workbook.WriteHeader((UInt16)Id, (UInt16)Data.Length);
            Workbook.WriteRaw(Data, 4);
            Workbook.WriteRaw(ExcelBuild, ExcelBuild.Length);

            Workbook.WriteRaw(ExcelVersion, 1);
            Workbook.WriteRaw(Data, 14, Data.Length - 14);
        }
Ejemplo n.º 2
0
 internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
 {
     Workbook.WriteHeader((UInt16)Id, (UInt16)Data.Length);
     byte[] Pos = new byte[4];
     Array.Copy(Data, 0, Pos, 0, 4);
     Workbook.WriteRaw(Pos, Pos.Length);
     Workbook.Write(Data, 4, Data.Length - 4);
 }
Ejemplo n.º 3
0
        internal void WriteExtSST(IDataStream DataStream, bool Repeatable)
        {
            // Calc number of strings per hash bucket
            UInt16 n = (UInt16)((Data.Count / 128) + 1);

            if (n < 8)
            {
                n = 8;
            }

            int nBuckets = 0;

            if (Data.Count == 0)
            {
                nBuckets = 0;
            }
            else
            {
                nBuckets = (Data.Count - 1) / n + 1;
            }

            DataStream.WriteHeader((UInt16)xlr.EXTSST, (UInt16)(2 + 8 * nBuckets));
            DataStream.Write16(n);


            if (Repeatable)
            {
                //REPEATABLEWRITES
                TSSTEntry[] SortedEntries = new TSSTEntry[Data.Count];
                Data.Keys.CopyTo(SortedEntries, 0);
                Array.Sort(SortedEntries);
                int i = 0;
                while (i < SortedEntries.Length)
                {
                    TSSTEntry e = SortedEntries[i];
                    DataStream.Write32((UInt32)e.AbsStreamPos);
                    DataStream.Write32(e.RecordStreamPos);
                    i += n;
                }
            }
            else
            {
                Dictionary <TSSTEntry, TSSTEntry> .Enumerator myEnumerator = Data.GetEnumerator();
                while (myEnumerator.MoveNext())
                {
                    TSSTEntry e = myEnumerator.Current.Key;
                    DataStream.Write32((UInt32)e.AbsStreamPos);
                    DataStream.Write32(e.RecordStreamPos);
                    for (int i = 0; i < n - 1; i++)
                    {
                        if (!myEnumerator.MoveNext())
                        {
                            return;                            //the if is needed to fix a bug in mono.
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 internal override void SaveFirstMul(IDataStream Workbook, TSaveData SaveData, int Row, int JoinedRecordSize)
 {
     unchecked
     {
         Workbook.WriteHeader((UInt16)xlr.MULBLANK, (UInt16)(JoinedRecordSize - XlsConsts.SizeOfTRecordHeader));
         Workbook.Write32((UInt32)((UInt16)Row + (((UInt16)Col) << 16)));
     }
     Workbook.Write16(SaveData.GetBiff8FromCellXF(XF));
 }
Ejemplo n.º 5
0
 internal void SaveStandardWidth(IDataStream DataStream)
 {
     if (!AllowStandardWidth || DefColWidthChars256 < 0)
     {
         return;
     }
     DataStream.WriteHeader((UInt16)xlr.STANDARDWIDTH, 2);
     DataStream.Write16((UInt16)DefColWidthChars256);
 }
Ejemplo n.º 6
0
 private void SaveOneRecord(int i, int k, IDataStream DataStream, TSaveData SaveData)
 {
     DataStream.WriteHeader((UInt16)xlr.COLINFO, (UInt16)TColInfoRecord.Length);
     DataStream.Write16((UInt16)i);
     DataStream.Write16((UInt16)k);
     DataStream.Write16((UInt16)this[i].Width);
     DataStream.Write16(SaveData.GetBiff8FromCellXF(this[i].XF));
     DataStream.Write16((UInt16)(this[i].Options));
     DataStream.Write16(0);
 }
Ejemplo n.º 7
0
 internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
 {
     Workbook.WriteHeader((UInt16)Id, (UInt16)CalcBiff8Len());
     SaveBiff8Data(Workbook, true);
     if (Hint != null)
     {
         Hint.FirstRow = FirstRow;
         Hint.FirstCol = FirstCol;
         Hint.LastRow  = LastRow;
         Hint.LastCol  = LastCol;
         Hint.SaveToStream(Workbook, SaveData, Row);
     }
 }
Ejemplo n.º 8
0
        internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
        {
            //We can't check for ColSplit/RowSplit since we don't know what it is. It doesn't really matter either.
            Biff8Utils.CheckRow(FirstVisibleRow);
            Biff8Utils.CheckCol(FirstVisibleCol);

            Workbook.WriteHeader((UInt16)Id, (UInt16)TotalSizeNoHeaders());
            Workbook.Write16((UInt16)ColSplit);
            Workbook.Write16((UInt16)RowSplit);
            Workbook.Write16((UInt16)FirstVisibleRow);
            Workbook.Write16((UInt16)FirstVisibleCol);
            Workbook.Write16((UInt16)ActivePane);
        }
Ejemplo n.º 9
0
 internal void SaveTabIds(IDataStream DataStream)
 {
     CheckTabId();
     if (FTabList.Count > XlsConsts.MaxTabIdCount || FTabList.Count != FBoundSheets.Count)
     {
         return;
     }
     DataStream.WriteHeader((UInt16)xlr.TABID, (UInt16)(2 * FTabList.Count));
     for (int i = 0; i < FTabList.Count; i++)
     {
         DataStream.Write16((UInt16)FTabList[i]);
     }
 }
Ejemplo n.º 10
0
 private static void AddContinue(IDataStream DataStream, byte[] Buffer, ref int BufferPos, ref long BeginRecordPos, ref long TotalSize)
 {
     if (DataStream != null)
     {
         Array.Copy(BitConverter.GetBytes((UInt16)(BufferPos - 4)), 0, Buffer, 2, 2);                 //Adapt the record size before writing it.
         DataStream.WriteHeader((UInt16)(Buffer[0] + (Buffer[1] << 8)), (UInt16)(Buffer[2] + (Buffer[3] << 8)));
         DataStream.Write(Buffer, 4, BufferPos - 4);
         BeginRecordPos = DataStream.Position;
         Array.Copy(BitConverter.GetBytes((UInt16)xlr.CONTINUE), 0, Buffer, 0, 2);
         Buffer[4] = 0; Buffer[5] = 0;             //Clear the OptionFlags.
     }
     TotalSize += BufferPos;
     BufferPos  = 4;
 }
Ejemplo n.º 11
0
        private void SaveToStreamExt(IDataStream DataStream, TSaveData SaveData, int FirstRecord, int RecordCount)
        {
            if (RecordCount > 0)
            {
                Sort(); //just in case...
                int MyRecordCount = RecordCount;

                DataStream.WriteHeader((UInt16)RecordId, (UInt16)(2 + RecordCount * TPageBreak.Biff8Length));
                DataStream.Write16((UInt16)MyRecordCount);
                for (int i = FirstRecord; i < FirstRecord + RecordCount; i++)
                {
                    DataStream.Write(FList[i].Biff8Data(), TPageBreak.Biff8Length);
                }
            }
        }
Ejemplo n.º 12
0
        internal void SaveToStream(IDataStream DataStream, TSaveData SaveData)
        {
            long BeginRecordPos = DataStream.Position;

            byte[] Buffer = new byte[XlsConsts.MaxRecordDataSize + 4];
            Array.Copy(BitConverter.GetBytes((UInt16)xlr.SST), 0, Buffer, 0, 2);

            bool   Repeatable = SaveData.Repeatable;
            UInt32 TotalRefs;
            IEnumerator <KeyValuePair <TSSTEntry, TSSTEntry> > myEnumerator;

            TSSTEntry[] SortedEntries;
            PrepareToSave(Repeatable, out TotalRefs, out myEnumerator, out SortedEntries);

            Array.Copy(BitConverter.GetBytes(TotalRefs), 0, Buffer, 4, 4);
            Array.Copy(BitConverter.GetBytes((UInt32)Data.Count), 0, Buffer, 8, 4);

            int  BufferPos = 4 + 8;
            long TotalSize = 0;

            if (Repeatable)
            {
                //REPEATABLEWRITES
                foreach (TSSTEntry Se in SortedEntries)
                {
                    Se.SaveToStream(DataStream, Buffer, ref BufferPos, ref BeginRecordPos, ref TotalSize);
                }
            }
            else
            {
                myEnumerator.Reset();
                while (myEnumerator.MoveNext())
                {
                    myEnumerator.Current.Key.SaveToStream(DataStream, Buffer, ref BufferPos, ref BeginRecordPos, ref TotalSize);
                }
            }

            //Flush the buffer.
            Array.Copy(BitConverter.GetBytes((UInt16)(BufferPos - 4)), 0, Buffer, 2, 2);  //Adapt the record size before writing it.
            DataStream.WriteHeader((UInt16)(Buffer[0] + (Buffer[1] << 8)), (UInt16)(Buffer[2] + (Buffer[3] << 8)));
            DataStream.Write(Buffer, 4, BufferPos - 4);
            TotalSize += BufferPos;


            WriteExtSST(DataStream, Repeatable);
        }
Ejemplo n.º 13
0
        internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
        {
            if (FText == null || FText.Length == 0)
            {
                return;
            }

            byte[] b = Encoding.Unicode.GetBytes(TrimmedText);

            Workbook.WriteHeader((UInt16)Id, (UInt16)(b.Length + 12));
            Workbook.Write16(0x0800); //record id
            Workbook.WriteRow(FirstRow);
            Workbook.WriteRow(LastRow);
            Workbook.WriteCol(FirstCol);
            Workbook.WriteCol(LastCol);

            Workbook.Write(b, b.Length);
            Workbook.Write16(0); //null terminated.
        }
Ejemplo n.º 14
0
        internal void SaveToStream(IDataStream DataStream, TSaveData SaveData, byte PanePos)
        {
            if (SelectedCells == null || SelectedCells.Length == 0)
            {
                return;
            }

            if ((SaveData.ExcludedRecords & TExcludedRecords.CellSelection) != 0)
            {
                return;                                                                   //Note that this will invalidate the size, but it doesnt matter as this is not saved for real use. We could write blanks here if we wanted to keep the offsets right.
            }
            byte[] ppos = new byte[1]; ppos[0] = PanePos;

            int CurrentPos = 0;

            do
            {
                int    OldPos     = CurrentPos;
                UInt16 RecordSize = ActualRecordSize(ref CurrentPos);
                DataStream.WriteHeader((UInt16)xlr.SELECTION, (UInt16)(RecordSize - XlsConsts.SizeOfTRecordHeader));
                DataStream.Write(ppos, ppos.Length);

                DataStream.WriteRow(ActiveRow);
                DataStream.WriteCol(ActiveCol);

                DataStream.Write16((UInt16)ActiveSel);

                int len = CurrentPos - OldPos;
                DataStream.Write16((UInt16)len);

                unchecked
                {
                    for (int i = 0; i < len; i++)
                    {
                        DataStream.WriteRow(SelectedCells[i].Top);
                        DataStream.WriteRow(SelectedCells[i].Bottom);
                        DataStream.WriteColByte(SelectedCells[i].Left);
                        DataStream.WriteColByte(SelectedCells[i].Right);
                    }
                }
            }while (CurrentPos < SelectedCells.Length);
        }
Ejemplo n.º 15
0
        internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
        {
            Workbook.WriteHeader((UInt16)Id, (UInt16)TotalSizeNoHeaders());

            Workbook.Write16((UInt16)Id); //FrtHeader
            Workbook.Write(new byte[10], 10);

            Workbook.Write32((UInt32)TotalSizeNoHeaders());


            int ic = SheetColor.GetBiff8ColorIndex(SaveData.Palette, TAutomaticColor.SheetTab);

            if (ic < 0x08 || ic > 0x3f)
            {
                ic = 0x7f;
            }
            Workbook.Write32((UInt32)ic);

            UInt32 ic2 = (UInt32)ic;

            if (CondFmtCalc)
            {
                ic2 |= 0x80;
            }
            if (NotPublished)
            {
                ic2 |= 0x100;
            }
            Workbook.Write32(ic2);

            switch (SheetColor.ColorType)
            {
            case TColorType.RGB:
                Workbook.Write32(0x02);
                UInt32 RGB = (UInt32)(SheetColor.RGB);
                UInt32 BGR = 0xFF000000 | (RGB & 0x00FF00) | ((RGB & 0xFF0000) >> 16) | ((RGB & 0x0000FF) << 16);

                Workbook.Write32(BGR);
                break;

            case TColorType.Automatic:
                Workbook.Write32(0x00);
                Workbook.Write32(0x00);
                break;

            case TColorType.Theme:
                Workbook.Write32(0x03);
                Workbook.Write32((UInt32)SheetColor.Theme);
                break;

            case TColorType.Indexed:
                Workbook.Write32(0x01);
                Workbook.Write32((UInt32)ic);
                break;

            default:
                XlsMessages.ThrowException(XlsErr.ErrExcelInvalid);
                break;
            }

            Workbook.Write(BitConverter.GetBytes(SheetColor.Tint), 8);
        }
Ejemplo n.º 16
0
 internal static void SaveDSF(IDataStream DataStream)
 {
     DataStream.WriteHeader((UInt16)xlr.DSF, 2);
     DataStream.Write16(0); //we won't use double stream files, as the content in the other stream will probably be out of date.
 }
Ejemplo n.º 17
0
 internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
 {
     Workbook.WriteHeader((UInt16)Id, (UInt16)Data.Length);
     Workbook.WriteRaw(Data, Data.Length);
 }
Ejemplo n.º 18
0
 internal static void SaveNewRecord(IDataStream Workbook)
 {
     Workbook.WriteHeader((UInt16)xlr.TEMPLATE, 0);
 }