Skip to content

Commit

Permalink
BugFix: process address with sheet name
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkHung committed Dec 26, 2017
1 parent f481e9d commit c4349d3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
23 changes: 19 additions & 4 deletions EPPlus/ExcelCellBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,25 @@ private static string Translate(string value, dlgTransl addressTranslator, int r
/// <returns></returns>
private static string ToR1C1(string part, int row, int col, int rowIncr, int colIncr)
{
int shInd = part.IndexOf('!');
string sh = "";
if (shInd > 0)
{
sh = part.Substring(0, shInd + 1);
part = part.Substring(shInd + 1);
}
int delim = part.IndexOf(':');
if (delim > 0)
{
string p1 = ToR1C1_1(part.Substring(0, delim), row, col, rowIncr, colIncr);
string p2 = ToR1C1_1(part.Substring(delim + 1), row, col, rowIncr, colIncr);
if (p1.Equals(p2))
return p1;
return p1 + ":" + p2;
return sh + p1 + ":" + p2;
}

else
return ToR1C1_1(part, row, col, rowIncr, colIncr);
return sh + ToR1C1_1(part, row, col, rowIncr, colIncr);
}
private static string ToR1C1_1(string part, int row, int col, int rowIncr, int colIncr)
{
Expand Down Expand Up @@ -190,17 +197,25 @@ private static string ToR1C1_1(string part, int row, int col, int rowIncr, int c
/// <returns></returns>
private static string ToAbs(string part, int row, int col, int rowIncr, int colIncr)
{
int shInd = part.IndexOf('!');
string sh = "";
if (shInd > 0)
{
sh = part.Substring(0, shInd + 1);
part = part.Substring(shInd + 1);
}

int delim = part.IndexOf(':');
if (delim > 0)
{
string p1 = ToAbs_1(part.Substring(0, delim), row, col, rowIncr, colIncr);
string p2 = ToAbs_1(part.Substring(delim + 1), row, col, rowIncr, colIncr);
if (p1.Equals(p2))
return p1;
return p1 + ":" + p2;
return sh + p1 + ":" + p2;
}
else
return ToAbs_1(part, row, col, rowIncr, colIncr);
return sh + ToAbs_1(part, row, col, rowIncr, colIncr);
}
private static string ToAbs_1(string part, int row, int col, int rowIncr, int colIncr)
{
Expand Down
1 change: 1 addition & 0 deletions EPPlusTest/EPPlusTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Compile Include="FormulaParsing\ExpressionGraph\CompileResultTests.cs" />
<Compile Include="FormulaParsing\ExpressionGraph\FunctionCompilers\FunctionCompilerFactoryTests.cs" />
<Compile Include="FormulaParsing\FormulaParserManagerTests.cs" />
<Compile Include="FormulaParsing\FormulaR1C1Test.cs" />
<Compile Include="SparkLines.cs" />
<Compile Include="Utils\ConvertUtilTest.cs" />
<Compile Include="DataValidation\CustomValidationTests.cs" />
Expand Down
8 changes: 8 additions & 0 deletions EPPlusTest/FormulaParsing/FormulaR1C1Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public void C2Abs()
Assert.AreEqual("SUM($B:$B)", f);
}
[TestMethod]
public void C2AbsWithSheet()
{
string fR1C1 = "SUM(A!C2)";
_sheet.Cells[5, 3].FormulaR1C1 = fR1C1;
string f = _sheet.Cells[5, 3].Formula;
Assert.AreEqual("SUM(A!$B:$B)", f);
}
[TestMethod]
public void C2()
{
string fR1C1 = "SUM(C2)";
Expand Down

0 comments on commit c4349d3

Please sign in to comment.