Bug 52219

Summary: XSSFTextBox cannot show font color and size
Product: POI Reporter: wangxujiajia
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.8-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description wangxujiajia 2011-11-21 05:02:32 UTC
My Test File

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFTextBox;

public class TestXSSFTextBox{
	public static void main(String[] args) throws IOException{
		Workbook wb = new XSSFWorkbook();
		Sheet sheet=wb.createSheet();
		Drawing drawing2 =sheet.createDrawingPatriarch();
		CreationHelper helper = wb.getCreationHelper();
		XSSFClientAnchor a1 = (XSSFClientAnchor) helper.createClientAnchor();
	    a1.setRow1(0);
	    a1.setRow2(5);
	    a1.setCol1(0);
	    a1.setCol2(5);
	    
	    XSSFTextBox textbox2 =((XSSFDrawing) drawing2).createTextbox(a1);
	    XSSFRichTextString str = new XSSFRichTextString("Fontcolor is white!You can not reset it!");
	    XSSFFont font = (XSSFFont) wb.createFont();
	    XSSFColor col=new XSSFColor(new java.awt.Color(0, 0, 255));
	    font.setColor(col);
	    font.setItalic(true);
	    font.setFontName("sss");
	    font.setBold(true);
	    str.applyFont(font);
	    textbox2.setText(str);
	    textbox2.setNoFill(true);
	    
	    String file = "c:\\111.xlsx";
		FileOutputStream fileOut = new FileOutputStream(file);
		try{
			wb.write(fileOut);
		}finally{
			fileOut.close();
		}
	}
}
Comment 1 Yegor Kozlov 2011-12-19 08:27:15 UTC
It was a bug in XSSF: setting font color and size had no effect because not all text attributes were copied to xml. 

Should be fixed in r1220642.


Regards,
Yegor