https://issues.apache.org/bugzilla/show_bug.cgi?id=51236
--- Comment #10 from [email protected] 2011-06-13 19:55:51 UTC --- I am unable to create 4 part color for the Font using the POI library. For example, XSSFColor CW = new XSSFColor(new byte[] { (byte) -1, (byte) 255, (byte) 255, (byte) 255 }); and set the Font Color to CW. The generated xlsx file contains <color rgb="FFFFFF"/> instead of <color rgb="FFFFFFFF"/> in the styles.xml file. The problem with this is that when you unload such color representation, you will get rgb value 000000 (which is wrong)! If you have a way to get the 4-part color for the Font color, please let me know. However, such 4-color part seems to work for Foreground. Please see code attached. package org.apache.poi.ss.examples; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFColor; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFFont; import java.awt.Color; import java.io.FileOutputStream; import java.util.HashMap; public class TestFontColor { private static HashMap createStyles(Workbook wb){ HashMap m = new HashMap(); XSSFColor CW = new XSSFColor(new byte[] { (byte) -1, (byte) 255, (byte) 255, (byte) 255 }); XSSFColor CB = new XSSFColor(new byte[] { (byte) -1, (byte) 0, (byte) 0, (byte) 0 }); XSSFCellStyle styleX = (XSSFCellStyle)wb.createCellStyle(); XSSFFont fontX = (XSSFFont) wb.createFont(); fontX.setColor(CW); //do it again fontX.setFontHeightInPoints((short) 29); styleX.setFont(fontX); styleX.setFillForegroundColor(CB); styleX.setFillPattern((short) 1); m.put("WHITE", styleX); XSSFCellStyle styleY = (XSSFCellStyle) wb.createCellStyle(); XSSFFont fontY = (XSSFFont) wb.createFont(); fontY.setColor(CB); //FFFFFF returns black fontY.setFontHeightInPoints((short) 23); styleY.setFont(fontY); m.put("BLACK", styleY); return m; } public static void main(String[] args) throws Exception { Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet("Fonts"); HashMap map = createStyles(wb); Cell cell0 = sheet.createRow(0).createCell(0); cell0.setCellValue("A1234567"); cell0.setCellStyle((CellStyle) map.get("WHITE")); Cell cell1 = sheet.createRow(1).createCell(0); cell1.setCellValue("B7654321"); cell1.setCellStyle((CellStyle) map.get("BLACK")); // 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]
