Cell.HtmlString CSS "color:#FF0000 !important" throws an Exception

Hi,

The following Aspose.Cells code throws an error. The cause is the CSS color string color:#ff00000 !important part of the HTML

var xls = new Workbook();
var sheet = xls.Worksheets.First();

var row = sheet.Cells.Rows[0];
row[0].HtmlString = @"<span style=""color:#ff0000"">TEST</span>";   // OK
row[0].HtmlString = @"<span style=""color:rgb(17,17,17)"">TEST</span>"; // OK

row[0].HtmlString = @"<span style=""color:#ff0000 !important;"">TEST</span>"; // <== ERROR
row[0].HtmlString = @"<span style=""color:rgb(17,17,17) !important"">TEST</span>";  // <== ERROR
row[0].HtmlString = @"<span style=""color:#ff0000!important;"">TEST</span>";  // <== ERROR
row[0].HtmlString = @"<span style=""color:rgb(17,17,17)!important"">TEST</span>";  // <== ERROR

The error depends on the actual string passed. You can have:

Unhandled exception. System.ArgumentException: Convert invalid primitive (Parameter 'text') (Parameter 'htmlColor')
 ---> System.ArgumentException: Convert invalid primitive (Parameter 'text')
 ---> System.FormatException: Additional non-parsable characters are at the end of the string.
   at System.ParseNumbers.StringToInt(ReadOnlySpan`1 s, Int32 radix, Int32 flags, Int32& currPos)
   at System.Convert.ToInt32(String value, Int32 fromBase)
   at ♥☻.☻(String ☻, Int32)
   at ♥☻(String ☻, CultureInfo)
   --- End of inner exception stack trace ---
   at ♥☻(String ☻, CultureInfo)
   at ♥☻.☻(String ☻, CultureInfo)
   at ♥☻.☻(String ☻)
   --- End of inner exception stack trace ---
   at ♥☻.☻(String ☻)
   at Aspose.Cells.Drawing.ColorHelper.☻(String ☻)
   at Aspose.Cells.Drawing.ColorHelper.☻(String ☻)
   at→▬.☻(String ☻)
   at→▬.☻(WorksheetCollection ☻, Font, Hashtable ♣, Hashtable ♠)
   at→▬.☻(Shape ☻, WorksheetCollection, Font ♣, Char[] ♠, ArrayList ♥, Hashtable )
   at→▬.☻(Cell ☻, String, Hashtable ♣)
   at Aspose.Cells.Cell.set_HtmlString(String value)

or

Unhandled exception. System.FormatException: The input string '17)!importan' was not in a correct format.
   at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, ReadOnlySpan`1 value, TypeCode type)
   at System.Int32.Parse(String s)
   at→▬.☻(String ☻)
   at→▬.☻(WorksheetCollection ☻, Font, Hashtable ♣, Hashtable ♠)
   at→▬.☻(Shape ☻, WorksheetCollection, Font ♣, Char[] ♠, ArrayList ♥, Hashtable )
   at→▬.☻(Cell ☻, String, Hashtable ♣)
   at Aspose.Cells.Cell.set_HtmlString(String value)

color:#ff0000 !important or color:#ff00000!important (without the space) are all valid values according to the W3C Validator and should be supported, or at the very least, not throw an error.

Thanks.


Tested with Aspose.Cells 23.3.0 and 24.1.0.0

@dstj,

I was able to reproduce the issue as you mentioned. I found Cell.HtmlString CSS “color:#FF0000 !important” throws an exception as you pointed out.

We need to evaluate your issue in details. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-54971

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@dstj ,

We are pleased to inform you that your issue has been resolved. The fix will be included in an upcoming release (Aspose.Cells v24.2) that we plan to release in the first half of February 2024. You will be notified when the next version is released.

The issues you have found earlier (filed as CELLSNET-54971) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi