Hi
I am using following html string:"
<div xmlns="http://www.w3.org/1999/xhtml"><p dir="ltr" style="margin-left: 0px; "><span style="font-size: 11pt; font-family: arial, helvetica, sans-serif; "></span></p><p dir="ltr" style="margin-left: 0px; "><span style="font-size: 11pt; font-family: arial, helvetica, sans-serif; "><b>RRV21 </b></span><span style="background-color:#ffc000; font-size: 11pt; font-family: arial, helvetica, sans-serif; ">Requirement Y was updated in version 1.1 so this must show a new approval.</span></p><p dir="ltr" style="margin-left: 0px; "><span style="font-size: 11pt; font-family: arial, helvetica, sans-serif; "><b>RRV22</b></span><span style="font-size: 11pt; font-family: arial, helvetica, sans-serif; "> This functionality should be provided through the use of templates. We will verify. </span></p><p dir="ltr" style="margin-left: 0px; "><span style="font-size: 11pt; font-family: arial, helvetica, sans-serif; "><b>RRV23: </b></span><span style="font-size: 11pt; font-family: arial, helvetica, sans-serif; "> RISK 4: This could be misconstrued as a deal breaker if we do not provide this functionality or a reasonable answer for futures</span></p><p dir="ltr" style="margin-left: 0px; "><span style="font-size: 11pt; font-family: arial, helvetica, sans-serif; "></span></p></div>
I am using cell.setHtmlString() method to save this xml in cell.
After using Aspose 21.2 , background-color is not set in cell.
Prior to 21.2 it was set.
Any pointers on this will be helpful
@prafulla1980,
I tried the following sample code to generate the output Excel file using Aspose.Cells for Java v21.3, v21.1, 20.11, etc., I found all the versions do not set background-color inside the cell. So, all the versions work the same:
e.g.
Sample code:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
Cell cell = worksheet.getCells().get("A1");
cell.setHtmlString("<div xmlns=\"http://www.w3.org/1999/xhtml\"><p dir=\"ltr\" style=\"margin-left: 0px; \"><span style=\"font-size: 11pt; font-family: arial, helvetica, sans-serif; \"></span></p><p dir=\"ltr\" style=\"margin-left: 0px; \"><span style=\"font-size: 11pt; font-family: arial, helvetica, sans-serif; \"><b>RRV21 </b></span><span style=\"background-color:#ffc000; font-size: 11pt; font-family: arial, helvetica, sans-serif; \">Requirement Y was updated in version 1.1 so this must show a new approval.</span></p><p dir=\"ltr\" style=\"margin-left: 0px; \"><span style=\"font-size: 11pt; font-family: arial, helvetica, sans-serif; \"><b>RRV22</b></span><span style=\"font-size: 11pt; font-family: arial, helvetica, sans-serif; \"> This functionality should be provided through the use of templates. We will verify. </span></p><p dir=\"ltr\" style=\"margin-left: 0px; \"><span style=\"font-size: 11pt; font-family: arial, helvetica, sans-serif; \"><b>RRV23: </b></span><span style=\"font-size: 11pt; font-family: arial, helvetica, sans-serif; \"> RISK 4: This could be misconstrued as a deal breaker if we do not provide this functionality or a reasonable answer for futures</span></p><p dir=\"ltr\" style=\"margin-left: 0px; \"><span style=\"font-size: 11pt; font-family: arial, helvetica, sans-serif; \"></span></p></div>");
workbook.save("f:\\files\\out1.xlsx");
Could you give us details with sample code (runnable) and sample output file and which version renders the background color?
The sample code is much pretty similar to your code. Only the change I made is I started using Aspose 21.2 and new html file which I shared.
Is there any alternate solution so that color is set.I mean any property or style required to set for cell?
@prafulla1980,
Which HTML string or file you used in your code, please provide a zipped archive for your HTML string or HTML file? Please note, I used your exact HTML string (you pated in the first post of the thread) in my sample code (using new and older versions) and still do not get background color in the output file.
The html file is generated dynamically in my code by client. It is the one which I pasted .
One new thing I noticed that attached html1File.zip (314 Bytes)
html file works in 21.2 also
So is there any generic solution so that both html work in latest 21.2?
@prafulla1980,
We are sorry but still I could not get background color in the cell using new or any older versions that I tried. Here is my new sample code:
e.g.
Sample code:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
Cell cell = worksheet.getCells().get("A1");
cell.setHtmlString("<div xmlns=\"\"http://www.w3.org/1999/xhtml\"\">\n" +
"<p dir=\"\"ltr\"\" id=\"\"_1616581138352\"\"><span style=\"\"background-color:#800000\"\">art2 </span>this is <span style=\"\"background-color:#008000\"\">sample </span>testing</p>\n" +
"</div>");
workbook.save("f:\\files\\out1.xlsx");
Could you try the sample code and attach the output files by different versions (older and newer versions), we will check it soon. Also find attached the output Excel file which does not have background color set.
files1.zip (6.6 KB)
Please note, in case, you are using some different code (other than above) kindly do provide the sample code (runnable).
Code file with sample html that works both for xls and xlsx.zip (424 Bytes)
I have tested your code in my environment and uploaded the same.
Attached is working code and sample output filesOutputfiles.zip (7.8 KB)
I have tested these on newer version. The older version setup is no longer used;hence could not test .
I did test using your sample code (as following) and found it works fine. I have used latest version/fix: Aspose.Cells for Java v20.3.x to generate the file:
e.g.
Sample code:
Workbook workbook = new Workbook();
Worksheet worksheet1 = workbook.getWorksheets().get(0);
Cell cell2 = worksheet1.getCells().get("A1");
cell2.setHtmlString("<div xmlns=\"http://www.w3.org/1999/xhtml\"><p dir=\"ltr\" id=\"_1616581138352\"><span style=\"background-color:#800000\">art2 </span>this is<span style=\"background-color:#008000\">sample </span>testing</p>\r\n" +
"</div>");
workbook.save("f:\\files\\out1.xlsx");
Please find attached the output file for your reference. I can see the green color is set to the cell as background color.
out1.zip (6.6 KB)
What’s wrong with the attached output file or your output files, please elaborate?
Hi
My previously attached output(Outputfiles.zip)file also contains green colour.So Sample code html is showing coloured background in latest Aspose.
The question is why the very first html in this post is not showing coloured background using latest Aspose.Note that on UI it is showing coloured background.
I have attached the code file having very first html and its output file.
Can you test and let me know why this particular html in the code is not working for background colour? Code file with very first html html.zip (664 Bytes)
out1.zip (6.8 KB)
@prafulla1980,
We were able to observe the issue with this particular html. 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
CELLSJAVA-43426 - Background-color with hex color code is not set in excel
Thanks for your cooperation
@prafulla1980,
MS Excel only supports background color for the whole cell. Aspose.Cells works as MS Excel. We could not support this feature.