Cell.HtmlString is erroring out while setting the value

Hi,

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.

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;

}

Observations:

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

Versions:

  1. Aspose.Cells: “7.4.0.4”

I have also tried with new version Aspose.Cells: “8.1.0.0"”, but it still gives error.

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

Regards,

Prajakta

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.

C#

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.>”;

//It accepts simple html like this

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

workbook.Save(“output.xlsx”);

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.