You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.
If we have two equal cell values with illegal xml characters, <test> for example, and try to add
a table containing this cells: var table = sheet.Tables.Add(sheet.Cells[sheet.Dimension.Address], "dataTable");
then we get the following exception:
ArgumentException: An item with the same key has already been added
System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) in System.Collections.Generic.Dictionary'2.Insert(TKey key, TValue value, Boolean add) in OfficeOpenXml.Table.ExcelTable.GetStartXml(String name, Int32 tblId) in OfficeOpenXml.Table.ExcelTable..ctor(ExcelWorksheet sheet, ExcelAddressBase address, String name, Int32 tblId) в OfficeOpenXml.Table.ExcelTableCollection.Add(ExcelAddressBase Range, String Name) в Mfc.Web.Results.ExcelTableResult'1.CreatePackage() in D:\Agent_work\6\s\Mfc\Mfc.Web.Controllers\Results\ExcelTableResult{T}.cs:line 110
Code above does not check encoded column value for presence in the dictionary.
So, for our example:
String <test> does not exist in the names dictionary.
After xml encoding we get the string <test> and add this value to the dictionary.
In the next iteration we try to find the second string <test>, but this value do not exist in the dictionary.
Therefore we try to add an item with the key <test> twice.
The text was updated successfully, but these errors were encountered:
Dude3030
changed the title
"An item with the same key has already been added" Exception when cteating ExcelTable.
"An item with the same key has already been added" Exception when creating ExcelTable.
Sep 25, 2019
If we have two equal cell values with illegal xml characters,
<test>
for example, and try to adda table containing this cells:
var table = sheet.Tables.Add(sheet.Cells[sheet.Dimension.Address], "dataTable");
then we get the following exception:
Looking at the source,
EPPlus/EPPlus/Table/ExcelTable.cs
Line 172 in 4dacf27
the second part of the condition looks for cell value before xml encoding.
EPPlus/EPPlus/Table/ExcelTable.cs
Line 184 in 4dacf27
Code above does not check encoded column value for presence in the dictionary.
So, for our example:
<test>
does not exist in thenames
dictionary.<test>
and add this value to the dictionary.<test>
, but this value do not exist in the dictionary.<test>
twice.The text was updated successfully, but these errors were encountered: