示例#1
0
        /// <summary>
        /// Reads strings from BIFF stream into SST array
        /// </summary>
        public void ReadStrings()
        {
            uint offset       = (uint)m_readoffset + 8;
            uint last         = (uint)m_readoffset + RecordSize;
            int  lastcontinue = 0;
            uint count        = UniqueCount;

            while (offset < last)
            {
                XlsFormattedUnicodeString str = new XlsFormattedUnicodeString(m_bytes, offset);
                uint prefix  = str.HeadSize;
                uint postfix = str.TailSize;
                uint len     = str.CharacterCount;
                uint size    = prefix + postfix + len + ((str.IsMultiByte) ? len : 0);
                if (offset + size > last)
                {
                    if (lastcontinue >= continues.Count)
                    {
                        break;
                    }
                    uint   contoffset = continues[lastcontinue];
                    byte   encoding   = Buffer.GetByte(m_bytes, (int)contoffset + 4);
                    byte[] buff       = new byte[size * 2];
                    Buffer.BlockCopy(m_bytes, (int)offset, buff, 0, (int)(last - offset));
                    if (encoding == 0 && str.IsMultiByte)
                    {
                        len -= (last - prefix - offset) / 2;
                        string temp = Encoding.Default.GetString(m_bytes,
                                                                 (int)contoffset + 5,
                                                                 (int)len);
                        byte[] tempbytes = Encoding.Unicode.GetBytes(temp);
                        Buffer.BlockCopy(tempbytes, 0, buff, (int)(last - offset), tempbytes.Length);
                        Buffer.BlockCopy(m_bytes, (int)(contoffset + 5 + len), buff, (int)(last - offset + len + len), (int)postfix);
                        offset = contoffset + 5 + len + postfix;
                    }
                    else if (encoding == 1 && str.IsMultiByte == false)
                    {
                        len -= (last - offset - prefix);
                        string temp = Encoding.Unicode.GetString(m_bytes,
                                                                 (int)contoffset + 5,
                                                                 (int)(len + len));
                        byte[] tempbytes = Encoding.Default.GetBytes(temp);
                        Buffer.BlockCopy(tempbytes, 0, buff, (int)(last - offset), tempbytes.Length);
                        Buffer.BlockCopy(m_bytes, (int)(contoffset + 5 + len + len), buff, (int)(last - offset + len), (int)postfix);
                        offset = contoffset + 5 + len + len + postfix;
                    }
                    else
                    {
                        Buffer.BlockCopy(m_bytes, (int)contoffset + 5, buff, (int)(last - offset), (int)(size - last + offset));
                        offset = contoffset + 5 + size - last + offset;
                    }
                    last = contoffset + 4 + BitConverter.ToUInt16(m_bytes, (int)contoffset + 2);
                    lastcontinue++;

                    str = new XlsFormattedUnicodeString(buff, 0);
                }
                else
                {
                    offset += size;
                    if (offset == last)
                    {
                        if (lastcontinue < continues.Count)
                        {
                            uint contoffset = continues[lastcontinue];
                            offset = contoffset + 4;
                            last   = offset + BitConverter.ToUInt16(m_bytes, (int)contoffset + 2);
                            lastcontinue++;
                        }
                        else
                        {
                            count = 1;
                        }
                    }
                }
                m_strings.Add(str.Value);
                count--;
                if (count == 0)
                {
                    break;
                }
            }
        }
		/// <summary>
		/// Reads strings from BIFF stream into SST array
		/// </summary>
		public void ReadStrings()
		{
			uint offset = (uint)m_readoffset + 8;
			uint last = (uint)m_readoffset + RecordSize;
			int lastcontinue = 0;
			uint count = UniqueCount;
			while (offset < last)
			{
				XlsFormattedUnicodeString str = new XlsFormattedUnicodeString(m_bytes, offset);
				uint prefix = str.HeadSize;
				uint postfix = str.TailSize;
				uint len = str.CharacterCount;
				uint size = prefix + postfix + len + ((str.IsMultiByte) ? len : 0);
				if (offset + size > last)
				{
					if (lastcontinue >= continues.Count)
						break;
					uint contoffset = continues[lastcontinue];
					byte encoding = Buffer.GetByte(m_bytes, (int)contoffset + 4);
					byte[] buff = new byte[size * 2];
					Buffer.BlockCopy(m_bytes, (int)offset, buff, 0, (int)(last - offset));
					if (encoding == 0 && str.IsMultiByte)
					{
						len -= (last - prefix - offset) / 2;
						string temp = Encoding.Default.GetString(m_bytes,
																 (int)contoffset + 5,
																 (int)len);
						byte[] tempbytes = Encoding.Unicode.GetBytes(temp);
						Buffer.BlockCopy(tempbytes, 0, buff, (int)(last - offset), tempbytes.Length);
						Buffer.BlockCopy(m_bytes, (int)(contoffset + 5 + len), buff, (int)(last - offset + len + len), (int)postfix);
						offset = contoffset + 5 + len + postfix;
					}
					else if (encoding == 1 && str.IsMultiByte == false)
					{
						len -= (last - offset - prefix);
						string temp = Encoding.Unicode.GetString(m_bytes,
																 (int)contoffset + 5,
																 (int)(len + len));
						byte[] tempbytes = Encoding.Default.GetBytes(temp);
						Buffer.BlockCopy(tempbytes, 0, buff, (int)(last - offset), tempbytes.Length);
						Buffer.BlockCopy(m_bytes, (int)(contoffset + 5 + len + len), buff, (int)(last - offset + len), (int)postfix);
						offset = contoffset + 5 + len + len + postfix;
					}
					else
					{
						Buffer.BlockCopy(m_bytes, (int)contoffset + 5, buff, (int)(last - offset), (int)(size - last + offset));
						offset = contoffset + 5 + size - last + offset;
					}
					last = contoffset + 4 + BitConverter.ToUInt16(m_bytes, (int)contoffset + 2);
					lastcontinue++;

					str = new XlsFormattedUnicodeString(buff, 0);
				}
				else
				{
					offset += size;
					if (offset == last)
					{
						if (lastcontinue < continues.Count)
						{
							uint contoffset = continues[lastcontinue];
							offset = contoffset + 4;
							last = offset + BitConverter.ToUInt16(m_bytes, (int)contoffset + 2);
							lastcontinue++;
						}
						else
							count = 1;
					}
				}
				m_strings.Add(str.Value);
				count--;
				if (count == 0)
					break;
			}
		}
示例#3
0
        public void ReadStrings()
        {
            uint offset      = (uint)(base.m_readoffset + 8);
            uint num2        = (uint)(base.m_readoffset + base.RecordSize);
            int  num3        = 0;
            uint uniqueCount = this.UniqueCount;

            while (offset < num2)
            {
                XlsFormattedUnicodeString str = new XlsFormattedUnicodeString(base.m_bytes, offset);
                uint headSize       = str.HeadSize;
                uint tailSize       = str.TailSize;
                uint characterCount = str.CharacterCount;
                uint num8           = ((headSize + tailSize) + characterCount) + (str.IsMultiByte ? characterCount : 0);
                if ((offset + num8) > num2)
                {
                    if (num3 >= this.continues.Count)
                    {
                        return;
                    }
                    uint   num9  = this.continues[num3];
                    byte   @byte = Buffer.GetByte(base.m_bytes, ((int)num9) + 4);
                    byte[] dst   = new byte[num8 * 2];
                    Buffer.BlockCopy(base.m_bytes, (int)offset, dst, 0, (int)(num2 - offset));
                    if ((@byte == 0) && str.IsMultiByte)
                    {
                        characterCount -= ((num2 - headSize) - offset) / 2;
                        string s     = Encoding.Default.GetString(base.m_bytes, ((int)num9) + 5, (int)characterCount);
                        byte[] bytes = Encoding.Unicode.GetBytes(s);
                        Buffer.BlockCopy(bytes, 0, dst, (int)(num2 - offset), bytes.Length);
                        Buffer.BlockCopy(base.m_bytes, (int)((num9 + 5) + characterCount), dst, (int)(((num2 - offset) + characterCount) + characterCount), (int)tailSize);
                        offset = ((num9 + 5) + characterCount) + tailSize;
                    }
                    else if ((@byte == 1) && !str.IsMultiByte)
                    {
                        characterCount -= (num2 - offset) - headSize;
                        string str3 = Encoding.Unicode.GetString(base.m_bytes, ((int)num9) + 5, (int)(characterCount + characterCount));
                        byte[] src  = Encoding.Default.GetBytes(str3);
                        Buffer.BlockCopy(src, 0, dst, (int)(num2 - offset), src.Length);
                        Buffer.BlockCopy(base.m_bytes, (int)(((num9 + 5) + characterCount) + characterCount), dst, (int)((num2 - offset) + characterCount), (int)tailSize);
                        offset = (((num9 + 5) + characterCount) + characterCount) + tailSize;
                    }
                    else
                    {
                        Buffer.BlockCopy(base.m_bytes, ((int)num9) + 5, dst, (int)(num2 - offset), (int)((num8 - num2) + offset));
                        offset = (((num9 + 5) + num8) - num2) + offset;
                    }
                    num2 = (num9 + 4) + BitConverter.ToUInt16(base.m_bytes, ((int)num9) + 2);
                    num3++;
                    str = new XlsFormattedUnicodeString(dst, 0);
                }
                else
                {
                    offset += num8;
                    if (offset == num2)
                    {
                        if (num3 < this.continues.Count)
                        {
                            uint num11 = this.continues[num3];
                            offset = num11 + 4;
                            num2   = offset + BitConverter.ToUInt16(base.m_bytes, ((int)num11) + 2);
                            num3++;
                        }
                        else
                        {
                            uniqueCount = 1;
                        }
                    }
                }
                this.m_strings.Add(str.Value);
                uniqueCount--;
                if (uniqueCount == 0)
                {
                    return;
                }
            }
        }