Skip to content

Commit 52b87ec

Browse files
authored
Merge pull request #172 from spreadsheetlab/improve-parser-reference
Improve ParserReference
2 parents 8a4ab70 + 9468c07 commit 52b87ec

2 files changed

Lines changed: 9 additions & 39 deletions

File tree

src/XLParser/ExcelFormulaParser.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ public static IEnumerable<ParserReference> GetParserReferences(this ParseTreeNod
432432
ParserReference range = rangeStart.First();
433433
range.MaxLocation = rangeEnd.First().MinLocation;
434434
range.ReferenceType = ReferenceType.CellRange;
435+
range.ReferenceNode = node;
435436
range.LocationString = node.Print();
436437
list.Add(range);
437438
}
@@ -440,6 +441,8 @@ public static IEnumerable<ParserReference> GetParserReferences(this ParseTreeNod
440441
ParserReference range = rangeStart.First();
441442
range.TableColumns = rangeStart.First().TableColumns.Concat(rangeEnd.First().TableColumns).ToArray();
442443
range.TableSpecifiers = rangeStart.First().TableSpecifiers.SequenceEqual(rangeEnd.First().TableSpecifiers) ? range.TableSpecifiers : new string[0];
444+
range.ReferenceNode = node;
445+
range.LocationString = node.Print();
443446
list.Add(range);
444447
}
445448
else

src/XLParser/ParserReference.cs

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,19 @@ public enum ReferenceType
1616

1717
public class ParserReference
1818
{
19-
public const int MaxRangeHeight = 1048576;
20-
public const int MaxRangeWidth = 16384;
21-
2219
public ReferenceType ReferenceType { get; set; }
20+
public ParseTreeNode ReferenceNode { get; set; }
2321
public string LocationString { get; set; }
2422
public string Worksheet { get; set; }
2523
public string LastWorksheet { get; set; }
2624
public string FilePath { get; set; }
2725
public string FileName { get; set; }
28-
public string Name { get; private set; }
29-
public string MinLocation { get; set; } //Location as appearing in the formula, eg $A$1
26+
public string Name { get; set; }
27+
public string MinLocation { get; set; }
3028
public string MaxLocation { get; set; }
3129
public string[] TableSpecifiers { get; set; }
3230
public string[] TableColumns { get; set; }
33-
34-
public ParserReference(ReferenceType referenceType, string locationString = null, string worksheet = null, string lastWorksheet = null,
35-
string filePath = null, string fileName = null, string name = null, string minLocation = null, string maxLocation = null,
36-
string[] tableSpecifiers = null, string[] tableColumns = null)
37-
{
38-
ReferenceType = referenceType;
39-
LocationString = locationString;
40-
Worksheet = worksheet;
41-
LastWorksheet = lastWorksheet;
42-
FilePath = filePath;
43-
FileName = fileName;
44-
Name = name;
45-
MinLocation = minLocation;
46-
MaxLocation = maxLocation != null ? maxLocation : minLocation;
47-
TableColumns = tableColumns;
48-
TableSpecifiers = tableSpecifiers;
49-
}
50-
31+
5132
public ParserReference(ParseTreeNode node)
5233
{
5334
InitializeReference(node);
@@ -123,6 +104,7 @@ public void InitializeReference(ParseTreeNode node)
123104
break;
124105
}
125106

107+
ReferenceNode = node;
126108
LocationString = node.Print();
127109
}
128110

@@ -131,24 +113,9 @@ private string UnEscape(string value, string escapeCharacter)
131113
return System.Text.RegularExpressions.Regex.Replace(value, $"{escapeCharacter}(?!{escapeCharacter})", "");
132114
}
133115

134-
/// <summary>
135-
/// Converts the column number to an Excel column string representation.
136-
/// </summary>
137-
/// <param name="columnNumber">The zero-based column number.</param>
138-
private string ConvertColumnToStr(int columnNumber)
139-
{
140-
var sb = new System.Text.StringBuilder();
141-
while (columnNumber >= 0)
142-
{
143-
sb.Insert(0, (char)(65 + columnNumber % 26));
144-
columnNumber = columnNumber / 26 - 1;
145-
}
146-
return sb.ToString();
147-
}
148-
149116
public override string ToString()
150117
{
151-
return ReferenceType == ReferenceType.Cell ? MinLocation.ToString() : string.Format("{0}:{1}", MinLocation, MaxLocation);
118+
return LocationString;
152119
}
153120
}
154121
}

0 commit comments

Comments
 (0)