From 9e6a3da21486dc299e6a20c1beb71d5021bf0b4a Mon Sep 17 00:00:00 2001 From: Willem-Jan Meerkerk Date: Thu, 19 Jan 2023 14:36:28 +0100 Subject: [PATCH 1/4] Improve ToString() of ParserReference --- src/XLParser/ParserReference.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/XLParser/ParserReference.cs b/src/XLParser/ParserReference.cs index d88dc3c..634579c 100644 --- a/src/XLParser/ParserReference.cs +++ b/src/XLParser/ParserReference.cs @@ -148,7 +148,7 @@ private string ConvertColumnToStr(int columnNumber) public override string ToString() { - return ReferenceType == ReferenceType.Cell ? MinLocation.ToString() : string.Format("{0}:{1}", MinLocation, MaxLocation); + return LocationString; } } } \ No newline at end of file From 4db09ab1904f242b7097d6064d060c31b0cac2e8 Mon Sep 17 00:00:00 2001 From: Willem-Jan Meerkerk Date: Thu, 19 Jan 2023 14:37:19 +0100 Subject: [PATCH 2/4] Code cleanup of ParserReference --- src/XLParser/ParserReference.cs | 41 +++------------------------------ 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/src/XLParser/ParserReference.cs b/src/XLParser/ParserReference.cs index 634579c..fb35187 100644 --- a/src/XLParser/ParserReference.cs +++ b/src/XLParser/ParserReference.cs @@ -16,38 +16,18 @@ public enum ReferenceType public class ParserReference { - public const int MaxRangeHeight = 1048576; - public const int MaxRangeWidth = 16384; - public ReferenceType ReferenceType { get; set; } public string LocationString { get; set; } public string Worksheet { get; set; } public string LastWorksheet { get; set; } public string FilePath { get; set; } public string FileName { get; set; } - public string Name { get; private set; } - public string MinLocation { get; set; } //Location as appearing in the formula, eg $A$1 + public string Name { get; set; } + public string MinLocation { get; set; } public string MaxLocation { get; set; } public string[] TableSpecifiers { get; set; } public string[] TableColumns { get; set; } - - public ParserReference(ReferenceType referenceType, string locationString = null, string worksheet = null, string lastWorksheet = null, - string filePath = null, string fileName = null, string name = null, string minLocation = null, string maxLocation = null, - string[] tableSpecifiers = null, string[] tableColumns = null) - { - ReferenceType = referenceType; - LocationString = locationString; - Worksheet = worksheet; - LastWorksheet = lastWorksheet; - FilePath = filePath; - FileName = fileName; - Name = name; - MinLocation = minLocation; - MaxLocation = maxLocation != null ? maxLocation : minLocation; - TableColumns = tableColumns; - TableSpecifiers = tableSpecifiers; - } - + public ParserReference(ParseTreeNode node) { InitializeReference(node); @@ -131,21 +111,6 @@ private string UnEscape(string value, string escapeCharacter) return System.Text.RegularExpressions.Regex.Replace(value, $"{escapeCharacter}(?!{escapeCharacter})", ""); } - /// - /// Converts the column number to an Excel column string representation. - /// - /// The zero-based column number. - private string ConvertColumnToStr(int columnNumber) - { - var sb = new System.Text.StringBuilder(); - while (columnNumber >= 0) - { - sb.Insert(0, (char)(65 + columnNumber % 26)); - columnNumber = columnNumber / 26 - 1; - } - return sb.ToString(); - } - public override string ToString() { return LocationString; From 4d421b19e1f34a2a4dc054c38f57ab22d2ec03a6 Mon Sep 17 00:00:00 2001 From: Willem-Jan Meerkerk Date: Thu, 19 Jan 2023 14:40:13 +0100 Subject: [PATCH 3/4] Add property ReferenceNode to ParserReference --- src/XLParser/ParserReference.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/XLParser/ParserReference.cs b/src/XLParser/ParserReference.cs index fb35187..630322a 100644 --- a/src/XLParser/ParserReference.cs +++ b/src/XLParser/ParserReference.cs @@ -17,6 +17,7 @@ public enum ReferenceType public class ParserReference { public ReferenceType ReferenceType { get; set; } + public ParseTreeNode ReferenceNode { get; set; } public string LocationString { get; set; } public string Worksheet { get; set; } public string LastWorksheet { get; set; } @@ -103,6 +104,7 @@ public void InitializeReference(ParseTreeNode node) break; } + ReferenceNode = node; LocationString = node.Print(); } From 9468c07d059a831de756668c91c604739157fa20 Mon Sep 17 00:00:00 2001 From: Willem-Jan Meerkerk Date: Thu, 19 Jan 2023 14:42:10 +0100 Subject: [PATCH 4/4] Set ReferenceNode for ranges correctly --- src/XLParser/ExcelFormulaParser.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/XLParser/ExcelFormulaParser.cs b/src/XLParser/ExcelFormulaParser.cs index 4aea815..ff65503 100644 --- a/src/XLParser/ExcelFormulaParser.cs +++ b/src/XLParser/ExcelFormulaParser.cs @@ -432,6 +432,7 @@ public static IEnumerable GetParserReferences(this ParseTreeNod ParserReference range = rangeStart.First(); range.MaxLocation = rangeEnd.First().MinLocation; range.ReferenceType = ReferenceType.CellRange; + range.ReferenceNode = node; range.LocationString = node.Print(); list.Add(range); } @@ -440,6 +441,8 @@ public static IEnumerable GetParserReferences(this ParseTreeNod ParserReference range = rangeStart.First(); range.TableColumns = rangeStart.First().TableColumns.Concat(rangeEnd.First().TableColumns).ToArray(); range.TableSpecifiers = rangeStart.First().TableSpecifiers.SequenceEqual(rangeEnd.First().TableSpecifiers) ? range.TableSpecifiers : new string[0]; + range.ReferenceNode = node; + range.LocationString = node.Print(); list.Add(range); } else