https://issues.apache.org/bugzilla/show_bug.cgi?id=51236
Bug #: 51236
Summary: Font color set incorrectly for black and white color
using RGB values
Product: POI
Version: 3.8-dev
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: critical
Priority: P2
Component: XSSF
AssignedTo: [email protected]
ReportedBy: [email protected]
Classification: Unclassified
Created attachment 27044
--> https://issues.apache.org/bugzilla/attachment.cgi?id=27044
Java code to show that Font colors are incorrect for black and white
I am using POI 3.8 beta 2 to create cells with black and white font colors
using RGB values.
The RGB value for white color should be FFFFFF and for black should be 000000.
However, in the Excel file that was created, Font colors were reversed for
black and white. The RGB values from the Font Color icon are reversed.
Attached is the source code to reproduce this issue.
package org.apache.poi.ss.examples;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFFont;
import java.io.FileOutputStream;
public class TestFontColor {
protected static XSSFColor getXSSFColor(String RGB) {
int red = Integer.parseInt(RGB.substring(0,2), 16);
int green = Integer.parseInt(RGB.substring(2,4), 16);
int blue = Integer.parseInt(RGB.substring(4,6), 16);
return new XSSFColor(new byte[] { (byte) red, (byte) green, (byte) blue
});
}
public static void main(String[] args) throws Exception {
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
Sheet sheet = wb.createSheet("Fonts");
Font font0 = wb.createFont();
Font font1 = wb.createFont();
XSSFColor color_white = getXSSFColor("FFFFFF");
XSSFColor color_black = getXSSFColor("000000");
((XSSFFont) font0).setColor(color_white); //FFFFFF returns black
((XSSFFont) font1).setColor(color_black); //000000 returns white
CellStyle style0 = wb.createCellStyle();
CellStyle style1 = wb.createCellStyle();
style0.setFont(font0);
style1.setFont(font1);
Cell cell0 = sheet.createRow(0).createCell(0);
cell0.setCellValue("FFFFFF");
cell0.setCellStyle(style0);
Cell cell1 = sheet.createRow(1).createCell(0);
cell1.setCellValue("000000");
cell1.setCellStyle(style1);
// Write the output to a file
FileOutputStream fileOut = new
FileOutputStream("C:\\workspace\\TestFontColor.xlsx");
wb.write(fileOut);
fileOut.close();
}
}
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]