Cell.HtmlString is erroring out while setting the value- for a value

Hi,


1) Well, you have to use HtmlEncode as the fix works using this method.
2) For “CELLSNET-41060”, you have to also use HtmlEncode() method for it as HtmlDecode will give you the error.

Sample code that works fine with the fix we provided to you

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

string cellValue1 = ““Barclays Capital Inc.” and “Barclays US Floating Rate Note < 5 Years Index” are trademarks of Barclays Bank PLC and have been licensed for use for certain purposes by BlackRock Institutional Trust Company, N.A. (“BTC”). iShares® is a registered trademark of BTC.”;
string cellValue2 = “one is < two”;

Aspose.Cells.Cell cellA1 = worksheet.Cells[“A1”];
Aspose.Cells.Cell cellA2 = worksheet.Cells[“A2”];

cellA1.HtmlString = System.Web.HttpUtility.HtmlEncode(cellValue1);
cellA2.HtmlString = System.Web.HttpUtility.HtmlEncode(cellValue2);


workbook.Save(“e:\test2\result1.xls”);

Anyways, we have logged your comments against your existing issue(s). Our concerned developer will look into it if we can support it. If we have some update on it, we will let you know here.

Thank you.

Hi,

Thanks for your posting and using Aspose.Cells.

Please use the following code.

C#


Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];


string cellValue1 = ““Barclays Capital Inc.” and “Barclays US Floating Rate Note < 5 Years Index” are trademarks of Barclays Bank PLC and have been licensed for use for certain purposes by BlackRock Institutional Trust Company, N.A. (“BTC”). iShares® is a registered trademark of BTC.”;


string cellValue2 = “one is < two”;


Aspose.Cells.Cell cellA1 = worksheet.Cells[“A1”];

Aspose.Cells.Cell cellA2 = worksheet.Cells[“A2”];

cellA1.HtmlString = cellValue1;//cellvalue1 has been encoded.

cellA2.HtmlString = System.Web.HttpUtility.HtmlEncode(cellValue2);

workbook.Save(“d:\filetemp\dest.xls”);

Hi Shakeel Faiz,


Thanks for your code.

But, the above your code won’t works for all my scenarios, below.
Please have below my actual code (foreach()) and provide actual solution as ExpectedResult.xls.

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
string[] cellValues = string.Format("“Barclays Capital Inc.” and “Barclays US Floating Rate Note < 5 Years Index” are trademarks of Barclays Bank PLC and have been licensed for use for certain purposes by BlackRock Institutional Trust Company; N.A. (“BTC”). iShares® is a registered trademark of BTC.,one is < two,Bold,Italic,Underline,H2O,(a+b)2").Split(’,’);
Aspose.Cells.Cell cellA1 = worksheet.Cells[“A1”];
Aspose.Cells.Cell cellA2 = worksheet.Cells[“A2”];
Aspose.Cells.Cell cellA3 = worksheet.Cells[“A3”];
Aspose.Cells.Cell cellA4 = worksheet.Cells[“A4”];
Aspose.Cells.Cell cellA5 = worksheet.Cells[“A5”];
Aspose.Cells.Cell cellA6 = worksheet.Cells[“A6”];
Aspose.Cells.Cell cellA7 = worksheet.Cells[“A7”];

int i = 0;

foreach (Aspose.Cells.Cell cell in worksheet.Cells)
{
if (cell != null)
{
cell.HtmlString = System.Web.HttpUtility.HtmlDecode(cellValues[i]);
}

i++;
}

workbook.Save(“C:\temp\ExpectedResult.xls”);

Please Find 2 attachments.

Thanks,
Lakshmi Narasaiah C

Hi Lakshmi,


I think you may replace the line in your code, i.e.
cell.HtmlString = System.Web.HttpUtility.HtmlDecode(cellValues[i]);
with:
cell.HtmlString = cellValues[i];

However, I can still see one significant issue though. For the A2 cell, it still displays:
"one is" instead of "one is < two" but again, you may use HtmlEncode() method for this.
Anyways, we need to further look into it and we will do so soon.

Thank you.

Hi,

Thanks for your posting and using Aspose.Cells.

If you want input < as the cell value not html tag, please encode it as “<”

If we get ‘<’ when parsing html string and can get ‘>’ after ‘>’, we think it’s not standard html string and can process it fine.

And we did the following tests in IE with a simple html file:

a)If " one is < two " is input, " one is < two " is displayed.

b)If " one is <two " is input, " one is " is displayed.

We found if a space is followed by < , it should be process as html tag. We will fix this issue soon.

But we still hope you can input standard html string value to ignore unknown issues.

Hi,


Looks like, issue got resolved with " Aspose.Cells for .NET v7.3.1.5 and Code Change:
cell.HtmlString = cellValue;"
instead of cell.HtmlString = System.Web.HttpUtility.HtmlDecode(cellValue);

But still, as you said, if value has “<” instead of “<” issue exists. So please look into this as well and update us back.

I will get back to you, if we face any more issues after deploying to actual application.

Thank you very much Amjad Sahi and Shakeel Faiz for your support.


Regards,
Lakshmi Narasaiah C

Hi,

You are welcome.

We will keep looking into your mentioned issue. Once we will have some update/advice for you, we will get back to you asap.

Also, if you face any other issue relating to Aspose.Cells, please let us know, we will be glad to assist you.

Hi,

I have downloaded the version specified for Aspose.cell in the thread. But I am getting Index out of range. Did you guys changed anything in the specified version in thread.. ? As previously I downloaded the dll from this thread it was working fine, and Now I am getting "Index out of Range Error " while setting the value for cell.HtmlString..

Thanks.

Hi,


Could you paste your sample runnable code here and also provide us the template file(s) if you have any to reproduce the issue on our end. We will check your issue soon.

Also, kindly use our latest version/fix: Aspose.Cells for .NET v7.4.0.3


Thank you.

 cell.HtmlString  is "<Font Style="FONT-WEIGHT: bold;FONT-FAMILY: Arial;FONT-SIZE: 10pt;COLOR: #000000;">Less Fee Waivers &amp; Net Expenses Footnote</Font> "<div><br></div><div>cell.StringValue :-  Less Fee Waivers & Net Expenses Footnote.</div><div><br></div><div> cell.HtmlString = cell.StringValue;  this line is throwing the error  Index out of range. </div><div><br></div>

This is happening for me whenever there is “&” symbol in the cell.StringValue

Hi,


Thanks for providing us details.

Yes, you are right, I can find the error (“IndexOutOfRangeException”) by using the simplest lines of code.

Sample code:

Workbook workbook = new Workbook();
Worksheet worksheet1 = workbook.Worksheets[0];
Cells cells = worksheet1.Cells;
Aspose.Cells.Cell cell = cells[“A1”];
string val = “Less Fee Waivers & Net Expenses Footnote.”;
cell.HtmlString = val; // error

workbook.Save(“e:\test2\outputcellstring.xlsx”);

I have logged a ticket with an id “CELLSNET-41405” for your issue. We will look into your issue soon.

Thank you.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please download and try this fix: Aspose.Cells for .NET v7.4.0.4 and let us know your feedback.

Now For this value it is throwing index out of range. QA test & Var1good^&#4dfsdf23dfewr¥dfs¥.


Please check with this value as htmlString it is throwing Index out of range error.

Thanks,
Ankit

Hi,


I have tested the new string with v7.4.0.4, it works fine.

Here is my sample code and please find attached the output file. I do not get any error and the output file is fine.

Sample code:

Workbook workbook = new Workbook();
Worksheet worksheet1 = workbook.Worksheets[0];
Cells cells = worksheet1.Cells;
Aspose.Cells.Cell cell = cells[“A1”];
string val = “QA test & Var1good^&#4dfsdf23dfewr¥dfs¥.”;
cell.HtmlString = val;

workbook.Save(“e:\test2\HtmlStringtest.xlsx”);

If you still find the issue, kindly do paste your sample code here, we will check your issue soon.

Thank you.

Hi ,


I am trying to create an excel file which has a cell with value this with inline fonts ‘Barclays US Floating Rate Note < 5 Years Index’.

I want the resultant cell value to be ‘Barclays US FloatingRate Note < 5 Years Index’.
How to acheive it as I can not set “<” because the above value is a part of html which is getting parsed and saved in excel . ?
I am using the Aspose version v7.4.0.4.



Corporateitcompliance:
Hi ,

I am trying to create an excel file which has a cell with value this with inline fonts 'Barclays US Floating Rate Note < 5 Years Index'.

I want the resultant cell value to be 'Barclays US FloatingRate Note < 5 Years Index'.
How to acheive it as I can not set "<" because the above value is a part of html which is getting parsed and saved in excel . ?
I am using the Aspose version v7.4.0.4.



Hi,

Thanks for your posting and using Aspose.Cells for .NET.

We have logged your requirements inside our database against the issue id: CELLSNET-41061. We will look into your issue and help you asap.

Once, there is some update for you, we will share it with you.

Hi,

Thanks for using Aspose.Cells.

We have looked into your issue but we are unable to understand it.Could you explain your issue with more detail.

"'Barclays US Floating Rate Note < 5 Years Index".

The word in double quote need to be save in an excel cell. so we are using Aspose.cells to do the same.
As it has Inline formatting like bold and italics so we are using code
cell.HtmlString = Cell.StringValue ;

But the Thing is that the html entity < should be converted in "<" as other html tags are getting converted properly like (, ). And hence entity like <, > should come as respective symbol in Excel "<" , ">". But when I debugged I can see that < is shown as &amplt; and may be because of this its not getting converted into "<".
And Because of this issue the above mentioned sentence come as it is instead of it should be like ""'Barclays US Floating Rate Note < 5 Years Index".

I tried with simple example also . like 5 < 7
it should come as 5 < 7 ;



Hi,

Thanks for your posting and using Aspose.Cells for .NET.

We tried the following code, it works fine.

C#



Workbook workbook = new Workbook();

Cells cells = workbook.Worksheets[0].Cells;

cells[“A1”].HtmlString = “'Barclays US Floating Rate Note < 5 Years Index”;

Console.WriteLine(cells[“A1”].StringValue);// Barclays US Floating Rate Note < 5 Years Index


Console.WriteLine(cells[“A1”].HtmlString);


workbook.Save(@“d:\filetemp\myoutputfile.xlsx”);