Skip to content

Commit 46385a8

Browse files
committed
Fix List<Dictionary<string,object>> SaveAs the filter button at the bottom when only one column & multiple rows #789
1 parent a5c3e88 commit 46385a8

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.DefaultOpenXml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ private static string GetDimensionRef(int maxRowIndex, int maxColumnIndex)
347347
if (maxRowIndex == 0 && maxColumnIndex == 0)
348348
dimensionRef = "A1";
349349
else if (maxColumnIndex <= 1)
350-
dimensionRef = $"A{maxRowIndex}";
350+
dimensionRef = $"A1:A{maxRowIndex}";
351351
else if (maxRowIndex == 0)
352352
dimensionRef = $"A1:{ColumnHelper.GetAlphabetColumnName(maxColumnIndex - 1)}1";
353353
else

src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ private int WriteValues(MiniExcelStreamWriter writer, object values)
251251
writer.Write(WorksheetXml.EndSheetData);
252252

253253
if (_configuration.AutoFilter)
254-
{
255254
writer.Write(WorksheetXml.Autofilter(GetDimensionRef(maxRowIndex, maxColumnIndex)));
256-
}
257255

258256
writer.Write(WorksheetXml.Drawing(_currentSheetIndex));
259257
writer.Write(WorksheetXml.EndWorksheet);

tests/MiniExcelTests/MiniExcelIssueTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,4 +4374,23 @@ public void TestIssue773()
43744374
Assert.Equal("c3", rows[6].AA);
43754375
Assert.Equal("Ram", rows[6].B);
43764376
}
4377+
4378+
/// <summary>
4379+
/// https://github.com/mini-software/MiniExcel/issues/789
4380+
/// </summary>
4381+
[Fact]
4382+
public void TestIssue789()
4383+
{
4384+
var path = PathHelper.GetTempPath();
4385+
var value = new[] {
4386+
new Dictionary<string, object> { {"no","1"} },
4387+
new Dictionary<string, object> { {"no","2"} },
4388+
new Dictionary<string, object> { {"no","3"} },
4389+
};
4390+
MiniExcel.SaveAs(path, value);
4391+
4392+
var xml = Helpers.GetZipFileContent(path.ToString(), "xl/worksheets/sheet1.xml");
4393+
4394+
Assert.Contains("<x:autoFilter ref=\"A1:A4\" />", xml);
4395+
}
43774396
}

0 commit comments

Comments
 (0)