Fix SaveAsByTemplate single column demension index error #226

This commit is contained in:
wei 2021-05-10 14:33:09 +08:00
parent a79acd72a9
commit c7e4230729
3 changed files with 31 additions and 9 deletions

Binary file not shown.

View File

@ -603,12 +603,20 @@ namespace MiniExcelLibs.OpenXml
// e.g <dimension ref=\"A1:B6\" /> only need to update B6 to BMaxRowIndex
var @refs = dimension.GetAttribute("ref").Split(':');
if (@refs.Length == 2)
{
var letter = new String(refs[1].Where(Char.IsLetter).ToArray());
var digit = int.Parse(new String(refs[1].Where(Char.IsDigit).ToArray()));
dimension.SetAttribute("ref", $"{refs[0]}:{letter}{digit + maxRowIndexDiff}");
}
else
{
var letter = new String(refs[0].Where(Char.IsLetter).ToArray());
var digit = int.Parse(new String(refs[0].Where(Char.IsDigit).ToArray()));
dimension.SetAttribute("ref", $"A1:{letter}{digit + maxRowIndexDiff}");
}
}
}
}

View File

@ -25,6 +25,20 @@ namespace MiniExcelLibs.Tests
this.output = output;
}
/// <summary>
/// https://github.com/shps951023/MiniExcel/issues/226
/// Fix SaveAsByTemplate single column demension index error #226
/// </summary>
[Fact]
public void Issue226()
{
var path = PathHelper.GetNewTemplateFilePath();
var templatePath = PathHelper.GetSamplePath("xlsx/TestIssue226.xlsx");
MiniExcel.SaveAsByTemplate(path, templatePath, new { employees = new[] { new { name = "123" }, new { name = "123" } } });
Assert.Equal("A1:A3", Helpers.GetFirstSheetDimensionRefValue(path));
}
/// <summary>
/// ASP.NET Webform gridview datasource can't use miniexcel queryasdatatable · Issue #223]
/// (https://github.com/shps951023/MiniExcel/issues/223)