HSSFCellStyle, na preenche o fundo da célula...[RESOLVIDO]

2 respostas
N

Galera é o seguinte,

Estou usando POI para gerar um excel,
e em dado momento utilizo a classe
HSSFCellStyle para formatar as células
do meu arquivo, só que uma única
carcaterística não funciona, esta classe
não está mudando as cores de fundo e
da fonte. Preciso de ajuda urgente porque
tenho que entregar este código no fim da
semana.

HSSFWorkbook wb = new HSSFWorkbook();
			
HSSFCellStyle labelStyle = wb.createCellStyle();
HSSFCellStyle valueStyle = wb.createCellStyle();
			
labelStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); //funciona corretamente
labelStyle.setFillForegroundColor(HSSFColor.GREEN.index);  //não funciona 
labelStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);  //funciona corretamente
		
//...muito código aqui...

// agora em um método de outra classe...

HSSFSheet sheet = wb.createSheet("aba de consolidação");
HSSFRow row;
HSSFCell cell;

row = sheet.createRow(1);
cell = row.createCell(1);
cell.setCellStyle(labelStyle);
cell.setCellValue(new HSSFRichTextString(getBundle("page.lbl.grp")));

2 Respostas

I
HSSFWorkbook workb = new HSSFWorkbook(); 
HSSFSheet sheet = workb.createSheet("PANILHA 1");
HSSFCellStyle estiloCor = workb.createCellStyle();


estiloCor.setFillForegroundColor(HSSFColor.LEMON_CHIFFON.index);
estiloCor.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
estiloCor.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);

HSSFRow row1 = sheet.createRow((short) 0);

HSSFCell cel1 = row1.createCell(0);
	estilo.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	cel1.setCellStyle(estiloCor);
	cel1.setCellValue(new HSSFRichTextString("NOME DA CELULA"));
	sheet = workb.getSheetAt(0);
	sheet.autoSizeColumn((short) 0);

Segue assim acho que vai dar certo pois eu tive que fazer um exemplo desse aki no trambo. Qualquer coisa só postar. Valew

N

IronJavaMan,

Muito obrigado cara,
a grande sacada é a linha

sheet = workb.getSheetAt(0);

eu não sabia que tinha que por este código.

Valeu brother, agora só vou adaptar meu projeto.

Criado 7 de julho de 2009
Ultima resposta 8 de jul. de 2009
Respostas 2
Participantes 2