We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cell.HtmlString is erroring out while setting the value


While setting the cell.HtmlString, I am getting error for a value, below:

Actual Error Stack Trace is:

 System.ArgumentException: Item has already been added. Key in dictionary: '' Key being added: '' at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at System.Collections.Hashtable.Add(Object key, Object value) at ’’.Ÿ‹.š(WorksheetCollection , Font , String , ArrayList ) at ’’.Ÿ‹.š(Cell , String )

Actual Value is "Tax Risk — Sample Text.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Actual Code:

cell.HtmlString = FormatText(cell.StringValue);

Where FormatText is

private static string FormatText(string cellValue)


cellValue = cellValue.Replace("
\r\n", "

cellValue = cellValue.Replace("
", "

cellValue = cellValue.Replace("", "");

cellValue = cellValue.Replace("", "");

return cellValue;



1. It works with other text which is having tags like eg test


1. Aspose.Cell: ""

I have also tried with new version Aspose.Cell: """, but it still gives error.

Please help to make this work. Thanking you in advance!



Hi Prajakta,

Thanks for your posting and using Aspose.Cells.

I was able to replicate this exception using the following code with the latest version: Aspose.Cells
for .NET v8.1.0.2

However, this might not be a bug but a correct behavior of Aspose.Cells because it does not take every sort of Html for Cell.HtmlString. It just takes very simple HTML.

For example, in the following code it accepts the second Html string fine.

However, we have logged this issue in our database for investigation. We will look into it and see if this issue could be fixed. Once, there is some resolution or other update for you, we will let you know asap.

This issue has been logged as CELLSNET-42770.


Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];

Cell cell = worksheet.Cells[“A1”];

//It does not accept complex html like this

cell.HtmlString = “Tax Risk — Sample Text.<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>”;

//It accepts simple html like this

//cell.HtmlString = “Tax Risk — Sample Text.”;


Hi Prajakta,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.1.0.3 and let us know your feedback.