mirror of
https://gitee.com/dotnetchina/MiniExcel.git
synced 2024-11-29 18:38:08 +08:00
Fix SaveAsByTemplate single column demension index error #226
This commit is contained in:
parent
a79acd72a9
commit
c7e4230729
BIN
samples/xlsx/TestIssue226.xlsx
Normal file
BIN
samples/xlsx/TestIssue226.xlsx
Normal file
Binary file not shown.
@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user