Beispiel #1
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.
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void WriteLocalFile(IDataStream DataStream, string value, ref int NewPos)
        {
            int i = 0;

            while (i + 3 <= value.Length && value.Substring(i, 3) == ".." + Path.DirectorySeparatorChar)
            {
                i += 3;
            }
            value = value.Substring(i);

            bool IsCompressed = !StrOps.IsWide(value);
            int  WideDataLen  = 0;

            byte[] ByteStr = null;
            if (!IsCompressed)
            {
                ByteStr     = Encoding.Unicode.GetBytes(value);
                WideDataLen = 4 + 2 + ByteStr.Length;
            }

            NewPos += 2 + 4 + value.Length + 1 + 24 + 4 + WideDataLen;
            if (DataStream == null)
            {
                return;
            }


            DataStream.Write16((UInt16)(i / 3));

            DataStream.Write32((UInt32)(value.Length + 1));

            byte[] NewData = new byte[value.Length + 1];
            StrOps.CompressBestUnicode(value, NewData, 0);

            DataStream.Write(NewData, NewData.Length);


            DataStream.Write32(0xDEADFFFF);
            NewData = new byte[20];
            DataStream.Write(NewData, NewData.Length);

            if (IsCompressed)
            {
                DataStream.Write32(0);
                return;
            }
            else
            {
                DataStream.Write32((UInt32)(4 + 2 + ByteStr.Length));
            }

            DataStream.Write32((UInt32)ByteStr.Length);
            DataStream.Write16(0x0003);

            DataStream.Write(ByteStr, ByteStr.Length);
        }
Beispiel #3
0
        private void WriteString(IDataStream DataStream, string value, ref int NewPos, int ByteSize)
        {
            if (value == null || value.Length == 0)
            {
                return;
            }
            byte[] ByteStr = Encoding.Unicode.GetBytes(value);

            if (DataStream != null)
            {
                DataStream.Write32((UInt32)((ByteStr.Length + 2) / ByteSize));
            }
            NewPos += 4;

            if (DataStream != null)
            {
                DataStream.Write(ByteStr, ByteStr.Length);
            }
            NewPos += ByteStr.Length;

            if (DataStream != null)
            {
                DataStream.Write16(0);
            }
            NewPos += 2;
        }
Beispiel #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));
 }
Beispiel #5
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);
        }
Beispiel #6
0
 internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
 {
     base.SaveToStream(Workbook, SaveData, Row);
     Workbook.Write32(pSSTEntry.PosInTable);
 }
Beispiel #7
0
        internal void SaveBiff8Data(IDataStream DataStream, bool SaveCoords, out int Len)
        {
            if (DataStream != null)
            {
                if (SaveCoords)
                {
                    DataStream.WriteRow(FirstRow);
                    DataStream.WriteRow(LastRow);
                    DataStream.WriteCol(FirstCol);
                    DataStream.WriteCol(LastCol);
                }

                //CLSID
                DataStream.Write32(0x79EAC9D0);
                DataStream.Write32(0x11CEBAF9);
                DataStream.Write32(0xAA00828C);
                DataStream.Write32(0x0BA94B00);

                //Starts HyperLink Object - MS-OSHARED
                DataStream.Write32(0x02);
                DataStream.Write32(OptionFlags);
            }

            Len = 32;

            WriteString(DataStream, FDescription, ref Len);
            WriteString(DataStream, FTargetFrame, ref Len);

            //This part of the structure is different depending on the type of link.
            switch (FLinkType)
            {
            case THyperLinkType.URL:
                if (DataStream != null)
                {
                    DataStream.Write(URLGUID, URLGUID.Length);
                }
                Len += URLGUID.Length;
                WriteString(DataStream, FText, ref Len, 1);
                break;

            case THyperLinkType.LocalFile:
                if (DataStream != null)
                {
                    DataStream.Write(FILEGUID, FILEGUID.Length);
                }
                Len += FILEGUID.Length;
                WriteLocalFile(DataStream, FText, ref Len);
                break;

            case THyperLinkType.UNC:
                //String Moniker
                WriteString(DataStream, FText, ref Len);
                break;

            case THyperLinkType.CurrentWorkbook:
                //CurrentWorkbook doesn't have monikers.
                break;

            default:
                XlsMessages.ThrowException(XlsErr.ErrInvalidHyperLinkType, (int)FLinkType);
                break;
            }


            WriteString(DataStream, FTextMark, ref Len);
        }