internal XlsBiffLabelCell(byte[] bytes, uint offset, ExcelBinaryReader reader) : base(bytes, offset, reader) { m_UseEncoding = reader.DefaultEncoding; xlsString = XlsStringFactory.CreateXlsString(bytes, offset, reader); }
internal XlsBiffBoundSheet(uint startOffset, SheetType type, SheetVisibility visibleState, string name) : base(new byte[32]) { StartOffset = startOffset; Type = type; VisibleState = visibleState; _sheetName = new XlsInternalString(name); }
internal XlsBiffHeaderFooterString(byte[] bytes, int biffVersion) : base(bytes) { if (biffVersion < 8) { _xlsString = new XlsShortByteString(bytes, ContentOffset); } else if (biffVersion == 8) { _xlsString = new XlsUnicodeString(bytes, ContentOffset); } else { throw new ArgumentException("Unexpected BIFF version " + biffVersion, nameof(biffVersion)); } }
internal XlsBiffBoundSheet(byte[] bytes, int biffVersion) : base(bytes) { StartOffset = ReadUInt32(0x0); Type = (SheetType)ReadByte(0x5); VisibleState = (SheetVisibility)ReadByte(0x4); if (biffVersion == 8) { _sheetName = new XlsShortUnicodeString(bytes, ContentOffset + 6); } else if (biffVersion == 5) { _sheetName = new XlsShortByteString(bytes, ContentOffset + 6); } else { throw new ArgumentException("Unexpected BIFF version " + biffVersion, nameof(biffVersion)); } }
internal XlsBiffLabelCell(byte[] bytes, uint offset, int biffVersion) : base(bytes, offset, biffVersion) { if (biffVersion == 2) { // BIFF2 _xlsString = new XlsShortByteString(bytes, offset + 4 + 7); } else if (biffVersion >= 3 && biffVersion <= 5) { // BIFF3-5 _xlsString = new XlsByteString(bytes, offset + 4 + 6); } else if (biffVersion == 8) { // BIFF8 _xlsString = new XlsUnicodeString(bytes, offset + 4 + 6); } else { throw new ArgumentException("Unexpected BIFF version " + biffVersion.ToString(), nameof(biffVersion)); } }
internal XlsBiffFormatString(byte[] bytes, uint offset, int biffVersion) : base(bytes, offset) { if (biffVersion == 2 || biffVersion == 3) { // BIFF2-3 _xlsString = new XlsShortByteString(bytes, offset + 4); } else if (biffVersion == 4 || biffVersion == 5) { // BIFF4-5 _xlsString = new XlsShortByteString(bytes, offset + 4 + 2); } else if (biffVersion == 8) { // BIFF8 _xlsString = new XlsUnicodeString(bytes, offset + 4 + 2); } else { throw new ArgumentException("Unexpected BIFF version " + biffVersion.ToString(), nameof(biffVersion)); } }
internal XlsBiffLabelCell(byte[] bytes, uint offset, int biffVersion) : base(bytes, offset, biffVersion) { if (Id == BIFFRECORDTYPE.LABEL_OLD) { // BIFF2 _xlsString = new XlsShortByteString(bytes, offset + 4 + 7); } else if (biffVersion >= 2 && biffVersion <= 5) { // BIFF3-5, or if there is a newer label record present in a BIFF2 stream _xlsString = new XlsByteString(bytes, offset + 4 + 6); } else if (biffVersion == 8) { // BIFF8 _xlsString = new XlsUnicodeString(bytes, offset + 4 + 6); } else { throw new ArgumentException("Unexpected BIFF version " + biffVersion.ToString(), nameof(biffVersion)); } }
internal XlsBiffFormulaString(byte[] bytes, int biffVersion) : base(bytes) { if (biffVersion == 2) { // BIFF2 _xlsString = new XlsShortByteString(bytes, ContentOffset); } else if (biffVersion >= 3 && biffVersion <= 5) { // BIFF3-5 _xlsString = new XlsByteString(bytes, ContentOffset); } else if (biffVersion == 8) { // BIFF8 _xlsString = new XlsUnicodeString(bytes, ContentOffset); } else { throw new ArgumentException("Unexpected BIFF version " + biffVersion, nameof(biffVersion)); } }
internal XlsBiffFormatString(byte[] bytes, int biffVersion) : base(bytes) { if (Id == BIFFRECORDTYPE.FORMAT_V23) { // BIFF2-3 _xlsString = new XlsShortByteString(bytes, ContentOffset); } else if (biffVersion >= 2 && biffVersion <= 5) { // BIFF4-5, or if there is a newer format record in a BIFF2-3 stream _xlsString = new XlsShortByteString(bytes, ContentOffset + 2); } else if (biffVersion == 8) { // BIFF8 _xlsString = new XlsUnicodeString(bytes, ContentOffset + 2); } else { throw new ArgumentException("Unexpected BIFF version " + biffVersion, nameof(biffVersion)); } }
internal XlsBiffFont(byte[] bytes, uint offset, int biffVersion) : base(bytes, offset) { if (Id == BIFFRECORDTYPE.FONT_V34) { _fontName = new XlsShortByteString(bytes, offset + 4 + 6); } else if (Id == BIFFRECORDTYPE.FONT && biffVersion == 2) { _fontName = new XlsShortByteString(bytes, offset + 4 + 4); } else if (Id == BIFFRECORDTYPE.FONT && biffVersion == 5) { _fontName = new XlsShortByteString(bytes, offset + 4 + 14); } else if (Id == BIFFRECORDTYPE.FONT && biffVersion == 8) { _fontName = new XlsShortUnicodeString(bytes, offset + 4 + 14); } else { _fontName = new XlsInternalString(string.Empty); } if (Id == BIFFRECORDTYPE.FONT && biffVersion >= 5) { // Encodings were mapped by correlating this: // https://docs.microsoft.com/en-us/windows/desktop/intl/code-page-identifiers // with the FONT record character set table here: // https://www.openoffice.org/sc/excelfileformat.pdf var byteStringCharacterSet = ReadByte(12); switch (byteStringCharacterSet) { case 0: // ANSI Latin case 1: // System default ByteStringEncoding = EncodingHelper.GetEncoding(1252); break; case 77: // Apple roman ByteStringEncoding = EncodingHelper.GetEncoding(10000); break; case 128: // ANSI Japanese Shift-JIS ByteStringEncoding = EncodingHelper.GetEncoding(932); break; case 129: // ANSI Korean (Hangul) ByteStringEncoding = EncodingHelper.GetEncoding(949); break; case 130: // ANSI Korean (Johab) ByteStringEncoding = EncodingHelper.GetEncoding(1361); break; case 134: // ANSI Chinese Simplified GBK ByteStringEncoding = EncodingHelper.GetEncoding(936); break; case 136: // ANSI Chinese Traditional BIG5 ByteStringEncoding = EncodingHelper.GetEncoding(950); break; case 161: // ANSI Greek ByteStringEncoding = EncodingHelper.GetEncoding(1253); break; case 162: // ANSI Turkish ByteStringEncoding = EncodingHelper.GetEncoding(1254); break; case 163: // ANSI Vietnamese ByteStringEncoding = EncodingHelper.GetEncoding(1258); break; case 177: // ANSI Hebrew ByteStringEncoding = EncodingHelper.GetEncoding(1255); break; case 178: // ANSI Arabic ByteStringEncoding = EncodingHelper.GetEncoding(1256); break; case 186: // ANSI Baltic ByteStringEncoding = EncodingHelper.GetEncoding(1257); break; case 204: // ANSI Cyrillic ByteStringEncoding = EncodingHelper.GetEncoding(1251); break; case 222: // ANSI Thai ByteStringEncoding = EncodingHelper.GetEncoding(874); break; case 238: // ANSI Latin II ByteStringEncoding = EncodingHelper.GetEncoding(1250); break; case 255: // OEM Latin ByteStringEncoding = EncodingHelper.GetEncoding(850); break; } } }
internal XlsBiffCodeName(byte[] bytes, uint offset) : base(bytes, offset) { // BIFF8 only _xlsString = new XlsUnicodeString(bytes, offset + 4 + 0); }
internal XlsBiffCodeName(byte[] bytes) : base(bytes) { // BIFF8 only _xlsString = new XlsUnicodeString(bytes, ContentOffset); }
private bool TryReadString(out IXlsString result) { if (CurrentState == SstState.StartStringHeader) { if (CurrentRecord.Size - CurrentRecordOffset == 0) { result = null; return(false); } CurrentHeader = new XlsSSTStringHeader(CurrentRecord.Bytes, CurrentRecordOffset); CurrentIsMultiByte = CurrentHeader.IsMultiByte; CurrentHeaderBytes = (int)CurrentHeader.HeadSize; CurrentRemainingCharacters = (int)CurrentHeader.CharacterCount; const int XlsUnicodeStringHeaderSize = 3; CurrentResult = new byte[XlsUnicodeStringHeaderSize + CurrentRemainingCharacters * 2]; CurrentResult[0] = (byte)(CurrentRemainingCharacters & 0x00FF); CurrentResult[1] = (byte)((CurrentRemainingCharacters & 0xFF00) >> 8); CurrentResult[2] = 1; // IsMultiByte = true CurrentResultOffset = XlsUnicodeStringHeaderSize; CurrentState = SstState.StringHeader; } if (CurrentState == SstState.StringHeader) { if (!Advance(CurrentHeaderBytes, out int advanceBytes)) { CurrentHeaderBytes -= advanceBytes; result = null; return(false); } CurrentState = SstState.StringData; if (CurrentRecord.Size - CurrentRecordOffset == 0) { // End of buffer before string data. Return false in StringData state to ensure reading the multibyte flag in the next record result = null; return(false); } } if (CurrentState == SstState.StringData) { var bytesPerCharacter = CurrentIsMultiByte ? 2 : 1; var maxRecordCharacters = (CurrentRecord.Size - CurrentRecordOffset) / bytesPerCharacter; var readCharacters = Math.Min(maxRecordCharacters, CurrentRemainingCharacters); ReadUnicodeBytes(CurrentResult, CurrentResultOffset, readCharacters, CurrentIsMultiByte); CurrentResultOffset += readCharacters * 2; // The result is always multibyte CurrentRemainingCharacters -= readCharacters; if (CurrentIsMultiByte && CurrentRecord.Size - CurrentRecordOffset == 1) { // Skip leftover byte at the end of a multibyte Continue record ReadByte(); } if (CurrentRemainingCharacters > 0 && CurrentRecord.Size - CurrentRecordOffset == 0) { result = null; return(false); } CurrentState = SstState.StringTail; CurrentTailBytes = (int)CurrentHeader.TailSize; } if (CurrentState == SstState.StringTail) { // Skip formatting runs and phonetic/extended data. Can also span // multiple Continue records if (!Advance(CurrentTailBytes, out var advanceBytes)) { result = null; CurrentTailBytes -= advanceBytes; return(false); } CurrentState = SstState.StartStringHeader; result = new XlsUnicodeString(CurrentResult, 0); return(true); } throw new InvalidOperationException("Unexpected state in SST reader"); }