Aspose.Cells .NET 17.4.0: TextBox.Characters() has side effects

Here’s how you reproduce the bug. CharactersSideEffectsWorkbook.zip (9.8 KB)
(1) Decompress the attached .zip
(2) Load the workbook file within it into a new Workbook object and run the following code:

using (var workbook = new Workbook(“CharactersSideEffectsWorkbook.xlsx”)) {
var sheet = workbook.Worksheets[0];
var textBox = sheet.TextBoxes[0];
textBox.HtmlText = @"<Font Style="“FONT-FAMILY: Arial;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;”">
<Font Style="“FONT-FAMILY: Arial;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;”">
";
var chart = textBox.Characters(0, 1);
Console.WriteLine(textBox.HtmlText);
}
}

The starting HtmlText has two tags, but after accessing textBox.Characters(0, 1) it has three. I have observed this occurring whenever calling textBox.Characters(0, n) where n is one greater than the length of the inner text contained in the first tag. I was not able to reproduce this issue in a newly created workbook, which is why I provided my test file. I therefore believe it depends on some setting particular to the test file. Can you please provide a fix?

@Justafool,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-47325 – Calling TextBox.Characters() causes additional tags in HtmlText

Thank you. I am not able to upgrade to a newer version of Aspose, so some insight into what particular property of this workbook is causing the issue would be very helpful.

@Justafool,

Please spare us little time to evaluate the issue thoroughly before we could provide details and insight on it. Hopefully we will figure out the issue soon.

@Justafool,
This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-47325”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@Justafool,

Please try our latest version/fix: Aspose.Cells for .NET v20.4.5 (attached)

Your issue should be fixed in it.

Let us know your feedback.
Aspose.Cells20.4.5 For .Net2_AuthenticodeSigned.Zip (5.3 MB)
Aspose.Cells20.4.5 For .Net4.0.Zip (5.4 MB)

The method still has side effects. If you run my example using the newest version, the HtmlText after the Characters() call has one Font tag instead of the two it should. I have observed it adding additional tags in other examples. Could you please attempt to reproduce this bug?

@Justafool,
We have observed the issue while using Console.WriteLine however if we write output to text file, there are two tags. This is because the < character is replaced by &lt; and > is replaced by &gt; in the output when we check it in text file. We are looking into this issue and will share our feedback soon.

@Justafool,
We have further investigated the issue and observed that the input string needs to be formatted as follows:

&lt;Font Style="FONT-FAMILY:Arial;FONT-SIZE:10pt;COLOR:#000000;TEXT-ALIGN:left;"&gt;&lt;Font Style="FONT-FAMILY:Arial;FONT-SIZE:9pt;COLOR:#000000;TEXT-ALIGN:left;"&gt;&lt;/Font&gt;

It will return the following output:

&lt;Font Style="FONT-FAMILY:Arial;FONT-SIZE:10pt;COLOR:#000000;TEXT-ALIGN:left;"&gt;&lt;Font Style="FONT-FAMILY:Arial;FONT-SIZE:9pt;COLOR:#000000;TEXT-ALIGN:left;"&gt;&lt;/Font&gt;

Please give it a try and share the feedback.

Thank you for the response, but on saving the workbook I see this causes the HTML tags to be displayed as text in the textbox. They are intended to format the text. I am also not directly setting the HTML text in the actual code I am working on. I only set it here to demonstrate the side effects of calling the Characters() method. For my purposes I require that calling the Characters() method not insert or remove line breaks into the text. Failing that, I require a knowledge of the circumstances under which this behavior occurs, so I can come up with a workaround. I appreciate your assistance so far, but is there any way you can help me figure out how to do that, please?

@Justafool,
We have logged your information in our database for further analysis. We will write back here once the feedback is ready to share.

@Justafool,

If you call Shape.Characters() method, we have to split the text to several FontSetting objects to represent the rich formatted text. When we export Shape.HtmlString, we will export Font html tag for each FontSetting. Now in order to reduce Font tag to fit your needs, we will check whether adjacent FontSetting objects are formatted the same. We cannot confirm that input htmlstring is same as exported htmlstring. We only can try to display the value as you could expect in browser.

I understand. My expectation is that calling Shape.Characters would be akin to using the Excel user interface to highlight a range of text in the textbox, then apply font formats to the selected range. There is no problem if that modifies the HTML text, but it seems like it should not insert additional line breaks. Thanks again for all your help.

@Justafool,

Thanks for your feedback.

We will evaluate it further and get back to you with updates soon.

@Justafool,

Could you please provide us some sample where this line break can be observed? Provide the source template file and output file which contains this issue for our reference.

I rewrote the text in the textbox I was working with and am now unable to reproduce the error. I will let you know if it comes up again. I very much appreciate your help.

@Justafool,
Thank you for the feedback and take your time to create the sample for reproducing this issue.

The issues you have found earlier (filed as CELLSNET-47325) have been fixed in Aspose.Cells for .NET v20.5. This message was posted using Bugs notification tool by Amjad_Sahi