namespace com.azkoss.excellite { using System; using System.Text.RegularExpressions; /// ///Formula token for holding 3d reference on internal cell. /// internal class Ref3dFormulaToken : RefFormulaToken { // Methods static Ref3dFormulaToken() { Ref3dFormulaToken.regexOptions = RegexOptions.Compiled; Ref3dFormulaToken.IsCell3DRegex = new Regex(@"(?[\S ]+)[\!](?[\$]?[A-Z]+)(?[\$]?\d+)", Ref3dFormulaToken.regexOptions); } /// ///Initializes a new instance of the class. /// ///The code. public Ref3dFormulaToken(FormulaTokenCode code) : base(code, 7) { this.refIndex = 0; } /// ///Convert formula token to array of byte representation. /// ///formula token' array of byte representation public override byte[] ConvertToBytes() { byte[] buffer1 = new byte[this.Size]; buffer1[0] = base.Code; if (this.sheet != null) { this.SetSheet(this.sheet); } BitConverter.GetBytes(this.refIndex).CopyTo(buffer1, 1); BitConverter.GetBytes(base.row).CopyTo(buffer1, 3); buffer1[5] = base.Column; buffer1[6] = base.options; return buffer1; } /// ///Make custom delay initialize. /// ///The data for initialization which is unique for each formula token. public override void DelayInitialize(object[] data) { this.workbook = data[1] as ExcelWorksheetCollection; this.Set3dCell(data[0] as string); } /// ///Initialize formula token by reading input data from array of bytes /// ///input data, array of bytes ///start position for array of bytes to read from public override void Read(byte[] rpnBytes, int startIndex) { this.refIndex = BitConverter.ToUInt16(rpnBytes, startIndex + 1); base.row = BitConverter.ToUInt16(rpnBytes, startIndex + 3); base.column = rpnBytes[startIndex++]; base.options = rpnBytes[startIndex]; } private void Set3dCell(string cell) { Match match1 = Ref3dFormulaToken.IsCell3DRegex.Match(cell); this.sheet = match1.Groups["Sheet"].Value; string text1 = match1.Groups["Row"].Value; string text2 = match1.Groups["Column"].Value; base.SetCell(text1, text2); this.SetSheet(this.sheet); } private void SetSheet(string sheet) { this.refIndex = this.workbook.AddSheetReference(sheet); } /// ///Convert formula token to string representation. /// ///formula token string representation public override string ToString() { return (this.sheet + "!" + base.ToString()); } // Fields /// ///Regular expression used to determinate whether the input string is 3d cell or not /// public static readonly Regex IsCell3DRegex; /// ///REF entry' index on EXTERNSHEET record( see the Link Table ). /// private ushort refIndex; /// ///Regular expression default options /// private static RegexOptions regexOptions; private string sheet; private ExcelWorksheetCollection workbook; } }