Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed May 20, 2015 6:36 pm

I need to add HTML to an excel cell, but that HTML is not necessarily composed of paragraphs (as your example assumes), for example with <BR>, <FONT>, <B>, tables, <UL>, <LI>.

If I do it directly, the HTML is not interpreted, it's shown like plain text showing the tags.

If I convert it to a Document with the "LoadHTML", It doesn't generate paragraphs as the example population assumes.

How can I achieve this?

thank you

nguivisdalsky
 
Posts: 3
Joined: Tue May 19, 2015 4:12 pm

Thu May 21, 2015 7:02 am

Hello,

Thanks for your inquiry. The Spire.Xls only supports to insert simple html as our example assumes.
http://www.e-iceblue.com/Tutorials/Spir ... -in-C.html

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Oct 22, 2019 2:25 pm

Is there a list of what e-iceblue considers "simple html"? I'm trying to insert a line break in the cell with <br/> or <p></p> or something. Both of those tags seem pretty simple to me, but using them does not insert a line break, and sometimes causes problems in the formatting of the rest of the html. Any suggestions are appreciated.

ryanewing1
 
Posts: 4
Joined: Thu Oct 25, 2018 1:34 pm

Wed Oct 23, 2019 10:52 am

Hi,

Thanks for your inquiry.
Sorry that there is no list. Besides, please note that Spire.XLS doesn't support to insert Html into Excel cell directly. In the article(Insert HTML-Formatted RichText into Excel Cell in C#) it actually uses Spire.Doc to parse the Html string into a Word document firstly, then gets the paragraph with rich text style in the Word file and returns a RichTextString object, finally combines all text without format and set the format dividedly in an Excel cell. I am afraid this solution cannot achieve the effect like <br> tag at present.
We will consider adding this new feature(insert Html string into Excel cell directly) into our upgrade schedule, once there is any progress, we will inform you. Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Jan 12, 2022 6:12 pm

Hi,

The example you linked using Spire.Doc does not compile with the latest version of Spire, since CharacterFormat does not have the property Font, but only FontName, FontSize etc. However the Workbook.CreateFont method only accepts a Font object.
Do you suggest any workaround? Or can you update the article according the latest APIs?

Thanks

Francesco

f.mazzurco
 
Posts: 13
Joined: Thu Aug 30, 2018 7:57 am

Thu Jan 13, 2022 2:32 am

Hello,

Thanks for your inquiry!

Did you mean the code from article "Insert HTML-Formatted RichText into Excel Cell in C#"? I tested the code with the latest Spire.Office for net 6.12.1, but the CharacterFormat did has the Font property, also the same result in the latest Spire.Doc for Net 9.12.12. If I have some misunderstand here, could you please provide us with the code you were using? Thanks in advance.
code.png
code.png (23.79 KiB) Viewed 1077 times

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Thu Jan 13, 2022 1:05 pm

Yes, I'm referring to the same article. I installed via nuget Spire.Office 6.12.1 on my project targeting .NET 5, but the Font property is not found:
Code.png
Code.png (28 KiB) Viewed 1071 times

I then donwloaded Spire.Doc 9.12.12 from https://www.e-iceblue.com/Download/download-word-for-net-now.html, and inspected the different dlls contained in the zip file.
I found out that the Font property exist in the .NET Framework 4.6 version of Spire.Doc, but not in the .NET 5 or .NET 6 versions.

Can you please check this?

Thanks,

Francesco

f.mazzurco
 
Posts: 13
Joined: Thu Aug 30, 2018 7:57 am

Fri Jan 14, 2022 6:25 am

Hello,

Thanks for sharing more information!

I did notice that the "CharacterFormat.Font" has been removed in our dlls of .NET 5.0 and .NET6.0. Actually, we are planing to gradually deprecate and remove this method in the future release products since each time it is called, this method consumes too much memory and affects performance.

We have changed the article on our website, and please refer to the following code to achieve the same effect with another way.
Code: Select all
            ExcelFont excelFont = workbook.CreateFont();
            excelFont.FontName = (item as Spire.Doc.Fields.TextRange).CharacterFormat.FontName;
            excelFont.Size = (item as Spire.Doc.Fields.TextRange).CharacterFormat.FontSize;
            excelFont.IsBold = (item as Spire.Doc.Fields.TextRange).CharacterFormat.Bold;
            excelFont.IsItalic = (item as Spire.Doc.Fields.TextRange).CharacterFormat.Italic;
            excelFont.Underline = (FontUnderlineType)(item as Spire.Doc.Fields.TextRange).CharacterFormat.UnderlineStyle; excelFont.Color = (item as Spire.Doc.Fields.TextRange).CharacterFormat.TextColor;
            workbook.Worksheets[0].Range["A4"].RichText.SetFont(i, i, excelFont);


Thanks for your understanding.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Fri Jan 14, 2022 4:24 pm

Hi,
thanks for updating the code.
However, I still have issues with richtext, which do not depend on the fact that we are calling a Word document to parse the html.
I will open another topic regarding it.

Thanks again

Francesco

f.mazzurco
 
Posts: 13
Joined: Thu Aug 30, 2018 7:57 am

Mon Jan 24, 2022 9:44 am

Hello,

Thanks for your patience!

Glad to inform you that we just released Spire.XLS Pack Version:12.1 which supports setting Html string for cell range

Please download the fix version from the following links and the following code to test.

Website link: https://www.e-iceblue.com/Download/download-excel-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.XLS/12.1.0

Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"input.xlsx");
Worksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].HtmlString = "<div>xxxx<br>yyyy</div>";


Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.XLS