mirror of
https://gitee.com/dotnetchina/MiniExcel.git
synced 2024-12-02 03:47:41 +08:00
[Bug] SaveAs by datareader, sometime it will add one more autoFilter column #352
This commit is contained in:
parent
268e997641
commit
12b6b25d0f
@ -24,6 +24,7 @@
|
||||
|
||||
### 1.25.0
|
||||
- [New] SaveAs support overwriteFile parameter for enable/unable overwriting exist file #307
|
||||
- [Bug] SaveAs by datareader, sometime it will add one more autoFilter column #352
|
||||
|
||||
### 1.24.3
|
||||
- [Bug] Fixed multiple threads Async error 'The given key N was not present in the dictionary' #344
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
### 1.25.0
|
||||
- [New] SaveAs 支持 overwriteFile 参数,方便调整是否要覆盖已存在文件。 #307
|
||||
- [Bug] SaveAs by datareader, 有时会多一个 autoFilter column #352
|
||||
|
||||
### 1.24.3
|
||||
- [Bug] 修正多 threads Async 可能错误 'The given key N was not present in the dictionary' #344
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
### 1.25.0
|
||||
- [New] SaveAs 支持 overwriteFile 參數,方便調整是否要覆蓋已存在文件。 #307
|
||||
- [Bug] SaveAs by datareader, 有時會多一個 autoFilter column #352
|
||||
|
||||
### 1.24.3
|
||||
- [Bug] 修正多 threads Async 可能錯誤 'The given key N was not present in the dictionary' #344
|
||||
|
@ -540,7 +540,7 @@ namespace MiniExcelLibs.OpenXml
|
||||
|
||||
private void GenerateSheetByIDataReader(StreamWriter writer, IDataReader reader)
|
||||
{
|
||||
var xy = ExcelOpenXmlUtils.ConvertCellToXY("A1");
|
||||
var xy = ExcelOpenXmlUtils.ConvertCellToXY("A1"); /*TODO:code smell*/
|
||||
|
||||
writer.Write($@"<?xml version=""1.0"" encoding=""utf-8""?><x:worksheet xmlns:x=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"">");
|
||||
var yIndex = xy.Item2;
|
||||
@ -583,7 +583,7 @@ namespace MiniExcelLibs.OpenXml
|
||||
}
|
||||
}
|
||||
writer.Write("</x:sheetData>");
|
||||
writer.Write($"<x:autoFilter ref=\"A1:{ExcelOpenXmlUtils.ConvertXyToCell(xIndex, yIndex)}\" />");
|
||||
writer.Write($"<x:autoFilter ref=\"A1:{ExcelOpenXmlUtils.ConvertXyToCell((xIndex-1)/*TODO:code smell*/, yIndex-1)}\" />");
|
||||
writer.Write("</x:worksheet>");
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,51 @@ namespace MiniExcelLibs.Tests
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestIssue352()
|
||||
{
|
||||
{
|
||||
DataTable table = new DataTable();
|
||||
{
|
||||
table.Columns.Add("id", typeof(int));
|
||||
table.Columns.Add("name", typeof(string));
|
||||
table.Rows.Add(1, "Jack");
|
||||
table.Rows.Add(2, "Mike");
|
||||
}
|
||||
var path = Path.GetTempPath() + Guid.NewGuid() + ".xlsx";
|
||||
DataTableReader reader = table.CreateDataReader();
|
||||
MiniExcel.SaveAs(path, reader);
|
||||
var xml = Helpers.GetZipFileContent(path, "xl/worksheets/sheet1.xml");
|
||||
var cnt = Regex.Matches(xml, "<x:autoFilter ref=\"A1:B3\" />").Count;
|
||||
}
|
||||
{
|
||||
DataTable table = new DataTable();
|
||||
{
|
||||
table.Columns.Add("id", typeof(int));
|
||||
table.Columns.Add("name", typeof(string));
|
||||
table.Rows.Add(1, "Jack");
|
||||
table.Rows.Add(2, "Mike");
|
||||
}
|
||||
var path = Path.GetTempPath() + Guid.NewGuid() + ".xlsx";
|
||||
DataTableReader reader = table.CreateDataReader();
|
||||
MiniExcel.SaveAs(path, reader,false);
|
||||
var xml = Helpers.GetZipFileContent(path, "xl/worksheets/sheet1.xml");
|
||||
var cnt = Regex.Matches(xml, "<x:autoFilter ref=\"A1:B2\" />").Count;
|
||||
}
|
||||
{
|
||||
DataTable table = new DataTable();
|
||||
{
|
||||
table.Columns.Add("id", typeof(int));
|
||||
table.Columns.Add("name", typeof(string));
|
||||
}
|
||||
var path = Path.GetTempPath() + Guid.NewGuid() + ".xlsx";
|
||||
DataTableReader reader = table.CreateDataReader();
|
||||
MiniExcel.SaveAs(path, reader);
|
||||
var xml = Helpers.GetZipFileContent(path, "xl/worksheets/sheet1.xml");
|
||||
var cnt = Regex.Matches(xml, "<x:autoFilter ref=\"A1:B1\" />").Count;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestIssue307()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user