Color

Hi,


Can you explain me why method Color.getR() return value “-1”(for red text in cell) but every Color component must have a range 0 to 255? Can you check this with following code and attached file? What is a problem?

String path = “/home/emisia/Desktop/formatting-test.xls”;
Workbook workbook = new Workbook(path);
Worksheet worksheet = workbook.getWorksheets().get(0);
Cell cell = worksheet.getCells().get(0);
FontSetting[] characters = cell.getCharacters();
FontSetting fontSetting = characters[4];
Color color = fontSetting.getFont().getColor();
int red = color.getR();
System.out.println(red);

Thanks,
Bojan

Hi,

Please use this code instead, it will return the correct color of the 4th character, which is black, so red part is 0.

I have highlighted the changes in red.

The output of this code will be 0, which is correct.

Java


String path = “F:\Shak-Data-RW\Downloads\formatting-test.xls”;


Workbook workbook = new Workbook(path);

Worksheet worksheet = workbook.getWorksheets().get(0);

Cell cell = worksheet.getCells().get(0);

FontSetting[] characters = cell.getCharacters();

FontSetting fontSetting = cell.characters(4, 1);

Color color = fontSetting.getFont().getColor();

int red = color.getR();

System.out.println(red);

Hi,


thanks for reply but this is not what I want. Problem is that the method Color.getR() return value “-1” for some Color and that is a problem, because range for Color component is 0 to 255. My code cannot operate with this value, pleas help me with this because this stop my project.

Thanks,
Bojan

Hi,

Actually, 255 means -1 if the byte is signed.

You should read unsigned byte, then you will get a value from 0-255.