List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle getFont
public XSSFFont getFont()
From source file:br.ufpa.psi.comportamente.labgame.relatorios.RelatorioJogadasExperimento.java
License:Open Source License
public InputStream relatorioOntogenese(Long idExp) throws FileNotFoundException, IOException { Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("Relatrio Ontognese"); JogadaDAO jogadaDAO = new JogadaDAO(); jogadaDAO.beginTransaction();// w w w.ja v a 2 s. com List<Jogada> jogadasAux = jogadaDAO.encontrarPorExperimento(idExp); jogadaDAO.stopOperation(false); ExperimentoDAO expDAO = new ExperimentoDAO(); expDAO.beginTransaction(); Experimento experimento = expDAO.find(Experimento.class, idExp); expDAO.stopOperation(false); JogadorDAO jogDAO = new JogadorDAO(); jogDAO.beginTransaction(); List<Jogador> jogadoresTotais = jogDAO.encontraPorExperimento(experimento); jogDAO.stopOperation(false); //CRIA O CABEALHO "ONTOGNESE int quantidadeColunas = 6; int quantidadeJogadoresPorCiclo = experimento.getTamanhoFilaJogadores(); //Vai pegar o valor de acordo com o experimento. int larguraColuna = 4600; int colunaAtual; int colunaFinalOntogenese = (quantidadeColunas * quantidadeJogadoresPorCiclo) + 1; // --- DEFINE AS PROPRIEDADES DAS CLULAS sheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 0)); sheet.addMergedRegion(new CellRangeAddress(0, 2, 1, 1)); sheet.setColumnWidth(0, 1500); sheet.setColumnWidth(1, 2000); sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, colunaFinalOntogenese)); sheet.addMergedRegion(new CellRangeAddress(1, 2, colunaFinalOntogenese + 1, colunaFinalOntogenese + 1)); sheet.setColumnWidth(colunaFinalOntogenese + 1, 3000); sheet.addMergedRegion(new CellRangeAddress(1, 3, colunaFinalOntogenese + 2, colunaFinalOntogenese + 2)); sheet.setColumnWidth(colunaFinalOntogenese + 2, 4000); // --- FIM //for (int i = 0; i < quantidadeJogadoresPorCiclo; i++) //if(i == 1){ sheet.setColumnWidth(2, larguraColuna); // Campo com o nome do participante fica nessa coluna. colunaAtual = 2 + quantidadeColunas; //} else { sheet.setColumnWidth((colunaAtual), larguraColuna); colunaAtual += quantidadeColunas; sheet.setColumnWidth(colunaAtual, larguraColuna); //} // ---DEFINE AS CORES DE CADA FONTE XSSFFont fonteBranca = (XSSFFont) wb.createFont(); fonteBranca.setColor(new XSSFColor(Color.WHITE)); XSSFFont fonteNegra = (XSSFFont) wb.createFont(); fonteNegra.setColor(new XSSFColor(Color.BLACK)); XSSFFont fonteVermelha = (XSSFFont) wb.createFont(); fonteVermelha.setColor(new XSSFColor(Color.RED)); // --- FIM // --- DEFINE ESTILOS CLULAS //ESTILO COLUNA LINHA XSSFCellStyle estiloColunaLinha = (XSSFCellStyle) wb.createCellStyle(); estiloColunaLinha.setVerticalAlignment(VerticalAlignment.CENTER); estiloColunaLinha.setAlignment(CellStyle.ALIGN_CENTER); estiloColunaLinha.setFillForegroundColor(new XSSFColor(Color.LIGHT_GRAY)); estiloColunaLinha.setFillPattern(CellStyle.SOLID_FOREGROUND); estiloColunaLinha.getFont().setBold(true); estiloColunaLinha.setBorderBottom(BorderStyle.MEDIUM); estiloColunaLinha.setBorderLeft(BorderStyle.MEDIUM); estiloColunaLinha.setBorderRight(BorderStyle.MEDIUM); estiloColunaLinha.setBorderTop(BorderStyle.MEDIUM); XSSFCellStyle estiloColunaColuna = (XSSFCellStyle) wb.createCellStyle(); estiloColunaColuna.setVerticalAlignment(VerticalAlignment.CENTER); estiloColunaColuna.setAlignment(CellStyle.ALIGN_CENTER); estiloColunaColuna.getFont().setBold(true); //ESTILO CABEALHO XSSFCellStyle estiloCabecalhoColunaAB = (XSSFCellStyle) wb.createCellStyle(); estiloCabecalhoColunaAB.setVerticalAlignment(VerticalAlignment.CENTER); estiloCabecalhoColunaAB.setAlignment(CellStyle.ALIGN_CENTER); estiloCabecalhoColunaAB.setFillForegroundColor(new XSSFColor(Color.LIGHT_GRAY)); estiloCabecalhoColunaAB.setFillPattern(CellStyle.SOLID_FOREGROUND); estiloCabecalhoColunaAB.getFont().setBold(true); XSSFCellStyle estiloCabecalhoColunaP = (XSSFCellStyle) wb.createCellStyle(); estiloCabecalhoColunaP.setVerticalAlignment(VerticalAlignment.CENTER); estiloCabecalhoColunaP.setAlignment(CellStyle.ALIGN_CENTER); estiloCabecalhoColunaP.setFont(fonteNegra); estiloCabecalhoColunaP.getFont().setBold(true); //ESTILO MUDANA DE CICLO XSSFCellStyle estiloMudancaCiclo = (XSSFCellStyle) wb.createCellStyle(); estiloMudancaCiclo.setVerticalAlignment(VerticalAlignment.CENTER); estiloMudancaCiclo.setAlignment(CellStyle.ALIGN_CENTER); estiloMudancaCiclo.setFillForegroundColor(new XSSFColor(Color.RED)); estiloMudancaCiclo.setFillPattern(CellStyle.SOLID_FOREGROUND); estiloMudancaCiclo.setFont(fonteBranca); //ESTILO CICLO SEM MUDANA XSSFCellStyle estiloCicloSemMudanca = (XSSFCellStyle) wb.createCellStyle(); estiloCicloSemMudanca.setVerticalAlignment(VerticalAlignment.CENTER); estiloCicloSemMudanca.setAlignment(CellStyle.ALIGN_CENTER); estiloCicloSemMudanca.setFont(fonteNegra); //ESTILO NOME PARTICIPANTE XSSFCellStyle estiloNomeP = (XSSFCellStyle) wb.createCellStyle(); estiloNomeP.setVerticalAlignment(VerticalAlignment.CENTER); estiloNomeP.setAlignment(CellStyle.ALIGN_CENTER); estiloNomeP.setBorderBottom(BorderStyle.DOTTED); estiloNomeP.setBorderTop(BorderStyle.DOTTED); estiloNomeP.setFillForegroundColor(new XSSFColor(Color.BLACK)); estiloNomeP.setFillPattern(CellStyle.SOLID_FOREGROUND); estiloNomeP.setFont(fonteBranca); estiloNomeP.getFont().setBold(true); //ESTILO ESTABILIDADE XSSFCellStyle estiloEstabilidade = (XSSFCellStyle) wb.createCellStyle(); estiloEstabilidade.setVerticalAlignment(VerticalAlignment.CENTER); estiloEstabilidade.setAlignment(CellStyle.ALIGN_CENTER); estiloEstabilidade.setFont(fonteVermelha); estiloEstabilidade.getFont().setBold(true); // --- FIM int cr = 0; // --- CRIA PRIMEIRA COLUNA (CABEALHO) XSSFRow row1 = (XSSFRow) sheet.createRow((short) cr++); //CRIA CLULA 1 XSSFCell c1 = row1.createCell(0); c1.setCellValue("FASE"); c1.setCellStyle(estiloCabecalhoColunaAB); //CRIA CLULA 2 XSSFCell c2 = row1.createCell(1); c2.setCellValue("CICLO"); c2.setCellStyle(estiloCabecalhoColunaAB); //CRIA CLULA 3 (ONTOGNESE) XSSFCell cOnto = row1.createCell(2); cOnto.setCellValue("ONTOGNESE"); cOnto.setCellStyle(estiloCicloSemMudanca); //CRIA CLULA 'CC' XSSFRow row2 = (XSSFRow) sheet.createRow(1); XSSFCell cCC = row2.createCell(colunaFinalOntogenese + 1); cCC.setCellValue("CC"); cCC.setCellStyle(estiloCicloSemMudanca); //CRIA CLULA 'ESTABILIDADE' XSSFCell cEstab = row2.createCell(colunaFinalOntogenese + 2); cEstab.setCellValue("ESTABILIDADE"); cEstab.setCellStyle(estiloEstabilidade); // --- FIM int contadorCelulasCabecalho = 2; int contadorAcertosCultural = 0; XSSFRow row3 = (XSSFRow) sheet.createRow((short) 2); //GERA O CABEALHO DAS JOGADAS for (int i = 0; i < experimento.getTamanhoFilaJogadores(); i++) { //CRIA CLULA 3 NA LINHA 3 XSSFCell c3 = row3.createCell(contadorCelulasCabecalho++); c3.setCellValue("P"); c3.setCellStyle(estiloCabecalhoColunaP); //CRIA CLULA 4 NA LINHA 3 XSSFCell c4 = row3.createCell(contadorCelulasCabecalho++); c4.setCellValue("Linha"); c4.setCellStyle(estiloCabecalhoColunaP); //CRIA CLULA 5 NA LINHA 3 XSSFCell c5 = row3.createCell(contadorCelulasCabecalho++); c5.setCellValue("Cor"); c5.setCellStyle(estiloCabecalhoColunaP); //CRIA CLULA 6 NA LINHA 3 XSSFCell c6 = row3.createCell(contadorCelulasCabecalho++); c6.setCellValue("Col"); c6.setCellStyle(estiloCabecalhoColunaP); //CRIA CLULA 7 NA LINHA 3 XSSFCell c7 = row3.createCell(contadorCelulasCabecalho++); c7.setCellValue("CI"); c7.setCellStyle(estiloCabecalhoColunaP); //CRIA CLULA 8 NA LINHA 3 XSSFCell c8 = row3.createCell(contadorCelulasCabecalho++); c8.setCellValue("CI Cum"); c8.setCellStyle(estiloCabecalhoColunaP); } //VARI?VEIS INICIAIS DA ELABORAO DO RELATRIO int quantidadeCiclosTotais = (jogadasAux.size() / experimento.getTamanhoFilaJogadores()); int contRowJogadas = 4; int contadorCiclo = 1; //INICIA LISTA DOS JOGADORES POR ORDEM List<Jogador> jogadoresAtuais = new ArrayList<>(); int contOrdem = 1; for (int i = 0; i < quantidadeJogadoresPorCiclo; i++) { for (Jogador jgdr : jogadoresTotais) { if (jgdr.getOrdem() == contOrdem) { jogadoresAtuais.add(jgdr); contOrdem++; break; } } } //FAZ A REMOO DO(S) ELEMENTO(S) DA LISTA PRA POUPAR RECURSO EM BUSCA FUTURA jogadoresTotais.removeAll(jogadoresAtuais); //CRIA INSTNCIA CONTROLE DE PONTUAO CULTURAL int pontCulturalCiclo; //FOR (JOGADOR : JOGADORES POR CICLO) //CRIA LISTA DE CADA JOGADOR AT FIM DO CICLO for (int i = 0; i < quantidadeCiclosTotais; i++) { //PEGA JOGADAS DO CICLO List<Jogada> jogadasCiclo = new ArrayList<>(); for (Jogada jogada : jogadasAux) { if (jogada.getRodada() == i + 1) { jogadasCiclo.add(jogada); if (jogadasCiclo.size() == quantidadeJogadoresPorCiclo) { break; } } } //FAZ A REMOO DO(S) ELEMENTO(S) DA LISTA PRA POUPAR RECURSO EM BUSCA FUTURA jogadasAux.removeAll(jogadasCiclo); //VERIFICA SE A ORDEM MUDOU int contJogadoresIguais = 0; List<Jogada> jogadasARemover = new ArrayList<>(); for (Jogador jogador : jogadoresAtuais) { for (Jogada jogada : jogadasCiclo) { if (jogada.getJogador().compareTo(jogador) == 0) { jogador.setUltimaJogada(jogada); jogador.incrementaPontuacaoRelatorio(); jogadasARemover.add(jogada); contJogadoresIguais++; } } } jogadasCiclo.removeAll(jogadasARemover); boolean mudouGeracaoCiclo = false; if (contJogadoresIguais == quantidadeJogadoresPorCiclo) { //CONTINUA COM OS MESMOS JOGADORES } else { mudouGeracaoCiclo = true; Jogador jogadorARemover = new Jogador(); jogadoresAtuais.remove(0); for (Jogador jgdr : jogadoresTotais) { if (jgdr.getOrdem() == contOrdem) { //PEGA A PRIMEIRA POSIO PQ ESSA TEM QUE SER A NICA COM ELEMENTO jgdr.setUltimaJogada(jogadasCiclo.get(0)); jgdr.incrementaPontuacaoRelatorio(); jogadoresAtuais.add(jgdr); contOrdem++; jogadorARemover = jgdr; break; } } jogadoresTotais.remove(jogadorARemover); } // --- ENCERRA ETAPAS DE VERIFICAO, INICIA A POPULAO DE NOVA LINHA DO XLSX E //VERIFICA SE EXISTE PONTUAO CULTURAL. int contCellJogadas = 1; if (jogadoresAtuais.get(0).getUltimaJogada().getPontuacaoCultural() != 0) { pontCulturalCiclo = jogadoresAtuais.get(0).getUltimaJogada().getPontuacaoCultural(); contadorAcertosCultural++; } else { pontCulturalCiclo = 0; } XSSFRow row = (XSSFRow) sheet.createRow((short) contRowJogadas); XSSFCell cell = row.createCell(contCellJogadas++); //CICLO if (contRowJogadas == 4 || mudouGeracaoCiclo == true) { //QUANDO HOUVER MUDANA DA GERAO cell.setCellValue(contadorCiclo++); cell.setCellStyle(estiloMudancaCiclo); } else { cell.setCellValue(contadorCiclo++); cell.setCellStyle(estiloCicloSemMudanca); } for (int j = 0; j < quantidadeJogadoresPorCiclo; j++) { //P XSSFCell cell1 = row.createCell(contCellJogadas++); cell1.setCellValue(jogadoresAtuais.get(j).getNome()); cell1.setCellStyle(estiloNomeP); //Linha XSSFCell cell2 = row.createCell(contCellJogadas++); cell2.setCellValue(jogadoresAtuais.get(j).getUltimaJogada().getLinhaSelecionada()); cell2.setCellStyle(estiloColunaLinha); //Cor XSSFCell cell3 = row.createCell(contCellJogadas++); cell3.setCellValue(jogadoresAtuais.get(j).getUltimaJogada().getCorSelecionada()); cell3.setCellStyle(EstiloCelula.retornaEstilo( jogadoresAtuais.get(j).getUltimaJogada().getCorSelecionada(), wb, fonteBranca, fonteNegra)); //Col XSSFCell cell4 = row.createCell(contCellJogadas++); cell4.setCellValue(jogadoresAtuais.get(j).getUltimaJogada().getColunaSelecionada()); cell4.setCellStyle(estiloColunaColuna); //CI XSSFCell cell5 = row.createCell(contCellJogadas++); cell5.setCellValue(jogadoresAtuais.get(j).getUltimaJogada().getPontuacaoIndividual()); cell5.setCellStyle(estiloColunaColuna); //CI Cum XSSFCell cell6 = row.createCell(contCellJogadas++); cell6.setCellValue(jogadoresAtuais.get(j).getPontuacaoExibidaRelatorio()); cell6.setCellStyle(estiloColunaColuna); } //CC XSSFCell cell7 = row.createCell(contCellJogadas++); cell7.setCellValue(pontCulturalCiclo); cell7.setCellStyle(estiloCabecalhoColunaAB); // ESTABILIDADE XSSFCell cell8 = row.createCell(contCellJogadas); cell8.setCellValue((contadorAcertosCultural * 100) / (i + 1) + "%"); cell8.setCellStyle(estiloColunaColuna); contRowJogadas++; } //ESCREVE O ARQUIVO byte[] bytes; try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { wb.write(out); bytes = out.toByteArray(); } return new ByteArrayInputStream(bytes); }
From source file:br.ufpa.psi.comportamente.labgame.relatorios.RelatorioJogadasExperimento.java
License:Open Source License
public static CellStyle retornaEstilo(String cor, Workbook wb, XSSFFont fb, XSSFFont fn) { XSSFCellStyle estilo = (XSSFCellStyle) wb.createCellStyle(); estilo.setVerticalAlignment(VerticalAlignment.CENTER); estilo.setAlignment(CellStyle.ALIGN_CENTER); estilo.setFillPattern(CellStyle.SOLID_FOREGROUND); estilo.setBorderBottom(BorderStyle.MEDIUM); estilo.setBorderTop(BorderStyle.MEDIUM); estilo.setFont(fb);/*from w w w .ja va 2s .c o m*/ estilo.getFont().setBold(true); switch (cor) { case "verde": estilo.setFillForegroundColor(new XSSFColor(new java.awt.Color(31, 131, 101))); return estilo; case "azul": estilo.setFillForegroundColor(new XSSFColor(Color.BLUE)); return estilo; case "vermelho": estilo.setFillForegroundColor(new XSSFColor(Color.RED)); return estilo; case "amarelo": estilo.setFillForegroundColor(new XSSFColor(Color.YELLOW)); estilo.setFont(fn); return estilo; case "roxo": estilo.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); return estilo; default: return estilo; } }
From source file:cc.landking.converter.office.excel.XSSFHtmlHelper.java
License:Apache License
public void colorStyles(CellStyle style, Formatter out) { XSSFCellStyle cs = (XSSFCellStyle) style; styleColor(out, "background-color", cs.getFillForegroundXSSFColor()); styleColor(out, "text-color", cs.getFont().getXSSFColor()); }
From source file:com.vaadin.addon.spreadsheet.XSSFColorConverter.java
License:Open Source License
@Override public void colorStyles(CellStyle cellStyle, StringBuilder sb) { XSSFCellStyle cs = (XSSFCellStyle) cellStyle; XSSFColor fillBackgroundXSSFColor = cs.getFillBackgroundXSSFColor(); XSSFColor fillForegroundXSSFColor = cs.getFillForegroundXSSFColor(); String backgroundColor = null; if (fillForegroundXSSFColor != null && !fillForegroundXSSFColor.isAuto()) { backgroundColor = styleColor(fillForegroundXSSFColor); } else if (fillBackgroundXSSFColor != null && !fillBackgroundXSSFColor.isAuto()) { backgroundColor = styleColor(fillBackgroundXSSFColor); } else {/*from ww w.ja v a2s . c om*/ // bypass POI API and try to get the fill ourself, because of bug: // https://issues.apache.org/bugzilla/show_bug.cgi?id=53262 try { XSSFColor themeColor = getFillColor(cs); if (themeColor != null && !themeColor.isAuto()) { backgroundColor = styleColor(themeColor); } } catch (Exception e) { LOGGER.log(Level.FINEST, e.getMessage(), e); } } if (backgroundColor != null && !backgroundColor.equals(defaultBackgroundColor)) { sb.append("background-color:"); sb.append(backgroundColor); } XSSFColor xssfColor = cs.getFont().getXSSFColor(); if (xssfColor != null) { String color = styleColor(xssfColor); if (color != null && !color.equals(defaultColor)) { sb.append("color:"); sb.append(color); } } }
From source file:com.vaadin.addon.spreadsheet.XSSFColorConverter.java
License:Open Source License
@Override public void defaultColorStyles(CellStyle cellStyle, StringBuilder sb) { XSSFCellStyle cs = (XSSFCellStyle) cellStyle; XSSFColor fillForegroundColorColor = cs.getFillForegroundColorColor(); XSSFColor fillBackgroundColorColor = cs.getFillBackgroundColorColor(); defaultBackgroundColor = styleColor(fillForegroundColorColor); defaultBackgroundColor = styleColor(fillBackgroundColorColor); if (defaultBackgroundColor == null) { defaultBackgroundColor = "rgba(255,255,255,1.0);"; }/* w ww. java 2s . c o m*/ sb.append("background-color:"); sb.append(defaultBackgroundColor); XSSFColor xssfColor = cs.getFont().getXSSFColor(); defaultColor = styleColor(xssfColor); if (defaultColor == null) { defaultColor = "rgba(0,0,0,1.0);"; } sb.append("color:"); sb.append(defaultColor); }
From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java
License:Apache License
/** * [Flow #-6] ? : ? ?(?, ? )? /* ww w. j a v a 2 s .c om*/ */ @Test public void testModifyCellAttribute() throws Exception { try { LOGGER.debug("testModifyCellAttribute start...."); StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testModifyCellAttribute.xlsx"); if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); LOGGER.debug("Delete file....{}", sb.toString()); } Workbook wbTmp = new XSSFWorkbook(); wbTmp.createSheet(); // ? ? excelService.createWorkbook(wbTmp, sb.toString()); // ? XSSFWorkbook wb = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook()); LOGGER.debug("testModifyCellAttribute after loadWorkbook...."); Sheet sheet = wb.createSheet("cell test sheet2"); sheet.setColumnWidth((short) 3, (short) 200); // column Width CellStyle cs = wb.createCellStyle(); XSSFFont font = wb.createFont(); font.setFontHeight(16); font.setBoldweight((short) 3); font.setFontName("fixedsys"); cs.setFont(font); cs.setAlignment(XSSFCellStyle.ALIGN_RIGHT); // cell cs.setWrapText(true); for (int i = 0; i < 100; i++) { Row row = sheet.createRow(i); row.setHeight((short) 300); // row? height for (int j = 0; j < 5; j++) { Cell cell = row.createCell(j); cell.setCellValue(new XSSFRichTextString("row " + i + ", cell " + j)); cell.setCellStyle(cs); } } // ? FileOutputStream out = new FileOutputStream(sb.toString()); wb.write(out); out.close(); ////////////////////////////////////////////////////////////////////////// // ? XSSFWorkbook wbT = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook()); Sheet sheetT = wbT.getSheet("cell test sheet2"); LOGGER.debug("getNumCellStyles : {}", wbT.getNumCellStyles()); XSSFCellStyle cs1 = (XSSFCellStyle) wbT.getCellStyleAt((short) (wbT.getNumCellStyles() - 1)); XSSFFont fontT = cs1.getFont(); LOGGER.debug("font getFontHeight : {}", fontT.getFontHeight()); LOGGER.debug("font getBoldweight : {}", fontT.getBoldweight()); LOGGER.debug("font getFontName : {}", fontT.getFontName()); LOGGER.debug("getAlignment : {}", cs1.getAlignment()); LOGGER.debug("getWrapText : {}", cs1.getWrapText()); for (int i = 0; i < 100; i++) { Row row1 = sheetT.getRow(i); for (int j = 0; j < 5; j++) { Cell cell1 = row1.getCell(j); LOGGER.debug("row {}, cell {} : {}", i, j, cell1.getRichStringCellValue()); assertEquals(320, fontT.getFontHeight()); assertEquals(400, fontT.getBoldweight()); LOGGER.debug("fontT.getBoldweight()? ? 400? ?"); assertEquals(XSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment()); assertTrue(cs1.getWrapText()); } } } catch (Exception e) { LOGGER.error(e.toString()); throw new Exception(e); } finally { LOGGER.debug("testModifyCellAttribute end...."); } }
From source file:net.mcnewfamily.rmcnew.shared.Util.java
License:Open Source License
public static void copyXSSFCellStyle(XSSFCell srcCell, XSSFCell destCell) { XSSFCellStyle srcCellStyle = srcCell.getCellStyle(); XSSFCellStyle destCellStyle = destCell.getCellStyle(); // destCellStyle.cloneStyleFrom(srcCellStyle); destCellStyle.setAlignment(srcCellStyle.getAlignment()); destCellStyle.setVerticalAlignment(srcCellStyle.getVerticalAlignment()); destCellStyle.setFont(srcCellStyle.getFont()); destCellStyle.setBorderBottom(srcCellStyle.getBorderBottom()); destCellStyle.setBorderLeft(srcCellStyle.getBorderLeft()); destCellStyle.setBorderRight(srcCellStyle.getBorderRight()); destCellStyle.setBorderTop(srcCellStyle.getBorderTop()); destCellStyle.setFillPattern(srcCellStyle.getFillPattern()); // foreground color must be set before background color is set destCellStyle.setFillForegroundColor(srcCellStyle.getFillForegroundColor()); destCellStyle.setFillBackgroundColor(srcCellStyle.getFillBackgroundColor()); destCellStyle.setIndention(srcCellStyle.getIndention()); destCellStyle.setWrapText(srcCellStyle.getWrapText()); destCell.setCellStyle(destCellStyle); }
From source file:org.apache.metamodel.excel.XlsxSheetToRowsHandler.java
License:Apache License
private void configureStyle(XSSFCellStyle style) { XSSFFont font = style.getFont(); if (font.getBold()) { _style.bold();/* w ww . j ava2 s.c o m*/ } if (font.getItalic()) { _style.italic(); } if (font.getUnderline() != FontUnderline.NONE.getByteValue()) { _style.underline(); } if (style.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) { XSSFColor fillForegroundXSSFColor = style.getFillForegroundXSSFColor(); String argb = fillForegroundXSSFColor.getARGBHex(); if (argb != null) { _style.background(argb.substring(2)); } } final XSSFFont stdFont = _stylesTable.getStyleAt(0).getFont(); final short fontHeight = style.getFont().getFontHeightInPoints(); if (stdFont.getFontHeightInPoints() != fontHeight) { _style.fontSize(fontHeight, SizeUnit.PT); } XSSFColor fontColor = style.getFont().getXSSFColor(); if (fontColor != null) { String argbHex = fontColor.getARGBHex(); if (argbHex != null) { _style.foreground(argbHex.substring(2)); } } switch (style.getAlignmentEnum()) { case LEFT: _style.leftAligned(); break; case RIGHT: _style.rightAligned(); break; case CENTER: _style.centerAligned(); break; case JUSTIFY: _style.justifyAligned(); break; default: // do nothing break; } }
From source file:org.bbreak.excella.core.test.util.TestUtil.java
License:Open Source License
private static String getCellStyleString(XSSFCellStyle cellStyle) { StringBuffer sb = new StringBuffer(); if (cellStyle != null) { XSSFFont font = cellStyle.getFont(); sb.append("Font=").append(font.getCTFont()).append(","); sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(","); sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(","); sb.append("Hidden=").append(cellStyle.getHidden()).append(","); sb.append("Locked=").append(cellStyle.getLocked()).append(","); sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(","); sb.append("WrapText=").append(cellStyle.getWrapText()).append(","); sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(","); sb.append("Rotation=").append(cellStyle.getRotation()).append(","); sb.append("Indention=").append(cellStyle.getIndention()).append(","); sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(","); sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(","); sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(","); sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(","); sb.append("LeftBorderColor=").append(getXSSFColorString(cellStyle.getLeftBorderXSSFColor())) .append(","); sb.append("RightBorderColor=").append(getXSSFColorString(cellStyle.getRightBorderXSSFColor())) .append(","); sb.append("TopBorderColor=").append(getXSSFColorString(cellStyle.getTopBorderXSSFColor())).append(","); sb.append("BottomBorderColor=").append(getXSSFColorString(cellStyle.getBottomBorderXSSFColor())) .append(","); sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(","); sb.append("FillForegroundColor=").append(getXSSFColorString(cellStyle.getFillForegroundXSSFColor())) .append(","); sb.append("FillBackgroundColor=").append(getXSSFColorString(cellStyle.getFillBackgroundXSSFColor())); }//from ww w . j av a2s.c o m return sb.toString(); }
From source file:org.bbreak.excella.reports.ReportsTestUtil.java
License:Open Source License
/** * XSSF????/*from w ww. ja va 2 s. c o m*/ * * @param cellStyle * @return ?? */ private static String getCellStyleString(XSSFCellStyle cellStyle) { StringBuffer sb = new StringBuffer(); if (cellStyle != null) { XSSFFont font = cellStyle.getFont(); sb.append("Font=").append(font.getCTFont()).append(","); sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(","); sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(","); sb.append("Hidden=").append(cellStyle.getHidden()).append(","); sb.append("Locked=").append(cellStyle.getLocked()).append(","); sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(","); sb.append("WrapText=").append(cellStyle.getWrapText()).append(","); sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(","); sb.append("Rotation=").append(cellStyle.getRotation()).append(","); sb.append("Indention=").append(cellStyle.getIndention()).append(","); sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(","); sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(","); sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(","); sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(","); sb.append("LeftBorderColor=").append(getXSSFColorString(cellStyle.getLeftBorderXSSFColor())) .append(","); sb.append("RightBorderColor=").append(getXSSFColorString(cellStyle.getRightBorderXSSFColor())) .append(","); sb.append("TopBorderColor=").append(getXSSFColorString(cellStyle.getTopBorderXSSFColor())).append(","); sb.append("BottomBorderColor=").append(getXSSFColorString(cellStyle.getBottomBorderXSSFColor())) .append(","); sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(","); try { sb.append("FillForegroundColor=").append(getXSSFColorString(cellStyle.getFillForegroundXSSFColor())) .append(","); } catch (NullPointerException e) { // POI-3.7??? sb.append("FillForegroundColor=none,"); } try { sb.append("FillBackgroundColor=") .append(getXSSFColorString(cellStyle.getFillBackgroundXSSFColor())); } catch (NullPointerException e) { // POI-3.7??? sb.append("FillBackgroundColor=none,"); } } return sb.toString(); }