FontSettings are nulls

Hello,

I’m writing you because I’ve faced with a little misconvenience. With last release aspose-cells-8.6.0.6-java I’m getting null for fontSettings = cell.getCharacters() for simple cells

I use:

Worksheet sheet = book.getWorksheets().get(i);

if (sheet != null) {

Cells cells = sheet.getCells();

if (cells != null) {

for (Object cell0 : cells) {

Cell cell = (Cell) cell0;

if (cell.getStringValue() != null && !cell.getStringValue().isEmpty()) {

FontSetting[] fontSettings = cell.getCharacters();

if (fontSettings != null) {

for (FontSetting fontSetting : fontSettings) {

font = fontSetting != null ? fontSetting.getFont() : null;

if (font != null) {

font.setColor(Color.getRed());

font.setBold(true);

font.setItalic(true);

}

}

}



But all text is still black.

I use getting Style for the cells now, so it is just report about little issue.

Could you please check it?

Thank you in advance

Hi Akane,


You have shared 2 concerns in this thread so let me share some details on both.

  1. FontSettings is null for simple cells while using Cell.getCharacters: That is correct behavior because the feature is designed for Rich Text. Please add another check to your application to test for Cells.isRichText. Moreover, if you intend to get the FontSetting for a simple cell then please use Cell.characters method.
  2. Style is not being changed while using Cell.getCharacters: As per my experience this is intended behavior too, however, I have logged these concerns to the ticket CELLSJAVA-41350 (attached to your other thread) and currently waiting for the product team’s response on this matter. In the meanwhile, I request you to check the article on how to format the selected the characters in a cell and give it a try on your side.

Hi,


Thanks for providing us template file and sample code.

After an initial test, I observed the issue as you mentioned. I found FontSettings are always nulls for your test file data. I used the sample code with your template file to reproduce the issue on our end. But It is quite possible that Cell.getCharacters() would return valid formatting for rich text only, so it does return null for your data in the sheet is not formatted. Anyways, we need to evaluate it thoroughly if this is an issue with the product or your code needs some tweak, we will check it out soon.
e.g
Sample code:

Workbook book = new Workbook(“book20.xlsx”);

Worksheet sheet = book.getWorksheets().get(1);
if (sheet != null) {
Cells cells = sheet.getCells();
if (cells != null) {
for (Object cell0 : cells) {
Cell cell = (Cell) cell0;
if (cell.getStringValue() != null && !cell.getStringValue().isEmpty()) {
FontSetting[] fontSettings = cell.getCharacters();
if (fontSettings != null) {
for (FontSetting fontSetting : fontSettings) {
Font font = fontSetting != null ? fontSetting.getFont() : null;
if (font != null) {
font.setColor(Color.getRed());
font.setBold(true);
font.setItalic(true);
}
}
}
}
}


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

Once we have any update on it, we will let you know here.

Thank you.

Hi,

Thanks for using Aspose.Cells.

We have looked into this issue further and found, it is not a bug but expected behavior. If the cell string value is a rich text, it will return null.

Hi,


We actually meant, for Cell.getCharacters() method, if a cell’s string value is not rich text, it would return null.

Thank you.

Hello,
I see, my fault, I’ve missed that point.
Thank you very much for explanation and sorry for bothering
Best Regards

Hi Akane,


You are most welcome. We will make sure to add this information to live documentation for future reference. In the meanwhile, please feel free to contact us back in case you need our further assistance with Aspose APIs.