using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using Biff8Excel.Interfaces; namespace Biff8Excel.Records { [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)] struct RecordExtendedFormat { public ushort opcode; public ushort length; public ushort fontIndex; public ushort formatIndex; public ushort cellOptions; [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte alignmentOptions; [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte rotationOptions; [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte indentationOpions; [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte usedAttribute; public uint borderOptions1; public uint borderOptions2; public ushort fillPalleteOptions; } internal class ExtendedFormat : IRecords { byte mHAlign; byte mWrapText; byte mVAlign; uint mLeftLineStyle; uint mRightLineStyle; uint mTopLineStyle; uint mBottomLineStyle; uint mLeftColourIndex; uint mRightColourIndex; uint mDiagTLBR; uint mDiagTRBL; uint mTopColourIndex; uint mBottomColourIndex; uint mDiagColourIndex; uint mDiagLineStyle; uint mFillPattern; ushort mPatternFore ; ushort mPatternBack; RecordExtendedFormat extendedformat; public ExtendedFormat() { extendedformat.opcode = 0xE0; extendedformat.length = 0x14; } public ushort ID { get { return extendedformat.opcode; } } public ushort RecordSize { get { return 24; } } public ushort FontIndex { set { extendedformat.fontIndex = value; } } public ushort FormatIndex { set { extendedformat.formatIndex = value; } } public bool CellIsLocked { set { if (value) extendedformat.cellOptions |= 0x1; else //extendedformat.cellOptions &= ~0x1; extendedformat.cellOptions = (ushort)(extendedformat.cellOptions & (~0x1)); } } public bool FormulaHidden { set { if (value) extendedformat.cellOptions |= 0x2; else //extendedformat.cellOptions &= ~0x2; extendedformat.cellOptions = (ushort)(extendedformat.cellOptions & (~0x2)); } } public byte StyleType { set { if (value == 0x1) //SheetStyle { extendedformat.cellOptions |= 0x4; extendedformat.cellOptions = (ushort)(extendedformat.cellOptions | 0xFFF0); //extendedformat.cellOptions |= -16; } else { //extendedformat.cellOptions &= ~0x4; extendedformat.cellOptions = (ushort)(extendedformat.cellOptions & (~0x4)); } } } void SetAlignment() { extendedformat.alignmentOptions = 0; extendedformat.alignmentOptions |= mHAlign; extendedformat.alignmentOptions |= mWrapText; extendedformat.alignmentOptions |= mVAlign; } public byte HorizontalAlignment { set { mHAlign = value; this.SetAlignment(); } } public bool WrapText { set { mWrapText = (byte)(value ? 0x8 : 0x0); this.SetAlignment(); } } public byte VerticalAlignment { set { mVAlign = value; //mVAlign = mVAlign * Math.Pow(2,4) mVAlign *= 16; this.SetAlignment(); } } public byte TextRoationAngle { set { extendedformat.rotationOptions = value; } } public bool StackText { set { if (value) extendedformat.rotationOptions = 0xFF; } } public byte UsedAttribute { set { extendedformat.usedAttribute = value; } } void SetBorderOptions1() { extendedformat.borderOptions1 = 0; extendedformat.borderOptions1 |= mLeftLineStyle; extendedformat.borderOptions1 |= mRightLineStyle; extendedformat.borderOptions1 |= mTopLineStyle; extendedformat.borderOptions1 |= mBottomLineStyle; extendedformat.borderOptions1 |= mLeftColourIndex; extendedformat.borderOptions1 |= mRightColourIndex; extendedformat.borderOptions1 |= mDiagTLBR; extendedformat.borderOptions1 |= mDiagTRBL; } public byte LeftLineStyle { set { mLeftLineStyle = value; extendedformat.usedAttribute |= (0x8 << 2 ); this.SetBorderOptions1(); } } public byte LeftLineColour { set { // mLeftColourIndex = CLng(vData) * (2 ^ 16) mLeftColourIndex = (uint)(value << 16); this.SetBorderOptions1(); } } public byte RightLineStyle { set { // mRightLineStyle = CLng(vData) * (2 ^ 4) mRightLineStyle = (uint)(value << 4); extendedformat.usedAttribute |= (0x8 << 2); this.SetBorderOptions1(); } } public byte RightLineColour { set { // mRightColourIndex = CLng(vData) * (2 ^ 23) mRightColourIndex = (uint)(value << 23); this.SetBorderOptions1(); } } public byte TopLineStyle { set { // mTopLineStyle = CLng(vData) * (2 ^ 8) mTopLineStyle = (uint)(value << 8); // field_6_used_Attribute = field_6_used_Attribute Or (&H8 * (2 ^ 2)) extendedformat.usedAttribute |= (0x8 << 2); this.SetBorderOptions1(); } } public byte TopLineColour { set { // mTopColourIndex = CLng(vData) * (2 ^ 0) mTopColourIndex = value; this.SetBorderOptions2(); } } public byte BottomLineStyle { set { // mBottomLineStyle = CLng(vData) * (2 ^ 12) mBottomLineStyle = (uint)(value << 12); // field_6_used_Attribute = field_6_used_Attribute Or (&H8 * (2 ^ 2)) extendedformat.usedAttribute |= (0x8 << 2); this.SetBorderOptions1(); } } void SetBorderOptions2() { extendedformat.borderOptions2 = 0; extendedformat.borderOptions2 |= mTopColourIndex; extendedformat.borderOptions2 |= mBottomColourIndex; extendedformat.borderOptions2 |= mDiagColourIndex; extendedformat.borderOptions2 |= mDiagLineStyle; extendedformat.borderOptions2 |= mFillPattern; } public byte BottomLineColour { set { // mBottomColourIndex = CLng(vData) * (2 ^ 7) mBottomColourIndex = (uint)(value << 7); this.SetBorderOptions2(); } } public byte DiagLineTopLeftToBottonRight { set { // mDiagTLBR = CLng(vData) * (2 ^ 30) mDiagTLBR = (uint)(value << 30); // field_6_used_Attribute = field_6_used_Attribute Or (&H8 * (2 ^ 2)) extendedformat.usedAttribute |= (0x8 << 2); this.SetBorderOptions1(); } } public byte DiagLineTopRightToBottonLeft { set { mDiagTRBL = (uint)(value << 31); // field_6_used_Attribute = field_6_used_Attribute Or (&H8 * (2 ^ 2)) extendedformat.usedAttribute |= (0x8 << 2); this.SetBorderOptions1(); } } public byte DiagLineStyle { set { mDiagLineStyle = (uint)(value << 21); extendedformat.usedAttribute |= (0x8 << 2); this.SetBorderOptions2(); } } public byte DiagLineColour { set { mDiagColourIndex = (uint)(value << 14); this.SetBorderOptions2(); } } public byte FillPattern { set { mFillPattern = (uint)(value << 26); this.SetBorderOptions2(); } } public byte PatternForeColour { set { mPatternFore = (ushort)(value << 0); //Shift Bits Up by 0 extendedformat.fillPalleteOptions = 0; extendedformat.fillPalleteOptions |= mPatternFore; extendedformat.fillPalleteOptions |= mPatternBack; } } public byte PatternBackColour { set { mPatternBack = (ushort)(value << 7); //Shift Bits Up by 7 extendedformat.fillPalleteOptions = 0; extendedformat.fillPalleteOptions |= mPatternFore; extendedformat.fillPalleteOptions |= mPatternBack; } } #region IRecords ³ΙΤ± public byte[] GetByte() { return Globals.GetStructToBytes(extendedformat); } #endregion } }