Example usage for org.apache.poi.xssf.usermodel XSSFColor XSSFColor

List of usage examples for org.apache.poi.xssf.usermodel XSSFColor XSSFColor

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFColor XSSFColor.

Prototype

@Deprecated
@Removal(version = "4.2")
public XSSFColor(java.awt.Color clr) 

Source Link

Document

Create an instance of XSSFColor from the awt Color

Usage

From source file:br.com.techne.gluonsoft.eowexport.builder.ExcelBuilder.java

License:Apache License

/**
 * cria estilos de celulas//from ww w.  j  a  v a  2 s  .com
 */
private static HashMap<String, CellStyle> createStyles(XSSFWorkbook wb) {
    HashMap<String, CellStyle> styles = new HashMap<String, CellStyle>();

    XSSFCellStyle style;
    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(new XSSFColor(new Color(167, 191, 222)));
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(headerFont);
    styles.put("header", style);

    style = createBorderedStyle(wb);

    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setWrapText(false);
    style.setFillForegroundColor(new XSSFColor(new Color(211, 223, 238)));
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styles.put("cell_normal_even", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setWrapText(false);
    style.setFillForegroundColor(new XSSFColor(new Color(237, 242, 248)));
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styles.put("cell_normal_odd", style);

    return styles;
}

From source file:br.com.tecsinapse.dataio.style.CellStyleBorder.java

License:LGPL

public CellStyle toCellStyle(CellStyle cellStyle) {
    if (cellStyle == null || !left && !right && !bottom && !top) {
        return cellStyle;
    }/* ww  w. java2  s  .c  om*/
    if (left) {
        cellStyle.setBorderLeft(BorderStyle.THIN);
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle) cellStyle).setLeftBorderColor(new XSSFColor(toIndexedColorMap(borderColor)));
        } else {
            cellStyle.setLeftBorderColor(borderColor.getIndex());
        }
    }
    if (right) {
        cellStyle.setBorderRight(BorderStyle.THIN);
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle) cellStyle).setRightBorderColor(new XSSFColor(toIndexedColorMap(borderColor)));
        } else {
            cellStyle.setRightBorderColor(borderColor.getIndex());
        }
    }
    if (bottom) {
        cellStyle.setBorderBottom(BorderStyle.THIN);
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle) cellStyle).setBottomBorderColor(new XSSFColor(toIndexedColorMap(borderColor)));
        } else {
            cellStyle.setBottomBorderColor(borderColor.getIndex());
        }
    }
    if (top) {
        cellStyle.setBorderTop(BorderStyle.THIN);
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle) cellStyle).setTopBorderColor(new XSSFColor(toIndexedColorMap(borderColor)));
        } else {
            cellStyle.setTopBorderColor(borderColor.getIndex());
        }
    }
    return cellStyle;
}

From source file:br.com.tecsinapse.dataio.style.TableCellStyle.java

License:LGPL

private void configFont(Font font) {
    font.setBold(isBold());/*ww w .jav  a2s.c o m*/
    font.setItalic(isItalic());
    font.setStrikeout(isStrikeout());
    font.setUnderline(isUnderline() ? Font.U_SINGLE : Font.U_NONE);
    if (getFontSize() != null) {
        font.setFontHeightInPoints(fontSize.shortValue());
    }
    if (getFontColor() != null) {
        if (font instanceof XSSFFont) {
            ((XSSFFont) font).setColor(new XSSFColor(toIndexedColorMap(fontColor)));
        } else {
            font.setColor(fontColor.getIndex());
        }
    }
}

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  ww.j av  a  2s .c  o m
    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);/* w w  w .  ja v a  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:ch.admin.isb.hermes5.business.userszenario.projektstrukturplan.ProjektstrukturplanGeneratorExcel.java

License:Apache License

private XSSFCellStyle getHeaderStyle(XSSFWorkbook wb) {
    XSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFillForegroundColor(new XSSFColor(new Color(184, 204, 228)));
    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    XSSFFont headerFont = wb.createFont();
    headerFont.setFontHeight(12);//from  w ww. j  a va  2s .  com
    headerFont.setFontName(fontName.getStringValue());
    cellStyle.setFont(headerFont);
    return cellStyle;
}

From source file:com.accenture.control.ExtraiPlanilha.java

public static void gravaCTPlanilha(List<Plano> plano, String panilha, int linhaCelula)
        throws FileNotFoundException, IOException, InvalidFormatException, SQLException,
        ClassNotFoundException {//  ww  w .  j av a 2  s .c o m
    ManipulaDadosSQLite banco = new ManipulaDadosSQLite();
    //recebe a planilha e atribui a variavel arquivo
    FileInputStream arquivo = new FileInputStream(new File(panilha));
    System.out.println(panilha);
    //instacia um workbook passando arquivo como paramentro
    XSSFWorkbook workbook = new XSSFWorkbook(arquivo);

    XSSFSheet sheetPlano = workbook.getSheetAt(1);
    String cadeia = "B", segmento = "C", produto = "D", funcionalidade = "E", cenarioItegrado = "F",
            sistemaMaster = "G", sistemasEnvolvidos = "H", fornecedor = "I", tpRequisito = "J", requisito = "K",
            cenarioTeste = "L", casoTeste = "M", descricao = "N", nomeStep = "P", descricaoStep = "Q",
            resultadoEsperado = "R", cenarioAuto = "U", type = "V", trg = "W", subject = "X", criacao = "Y";
    CellReference cellReference = new CellReference("B8");
    //     Row row = sheetPlano.getRow(cellReference.getRow());
    //     Cell cell = row.getCell(cellReference.getCol());

    int tamanhoLista = plano.size();
    int numeroCelula = 8;

    int linha = linhaCelula;
    int celula = 12;

    Row row = sheetPlano.getRow(linha);
    Cell cell;//= row.getCell(celula);
    Cell celCadeia = row.getCell(1);
    Cell celSegmento = row.getCell(2);
    Cell celProduto = row.getCell(3);
    Cell celFuncionalidade = row.getCell(4);
    Cell celCenarioIntegracao = row.getCell(5);
    Cell celSistemaMaster = row.getCell(6);
    Cell celSistemaEnvolvidos = row.getCell(7);
    Cell celFornecedor = row.getCell(8);
    Cell celTpRequisito = row.getCell(9);
    Cell celRequisito = row.getCell(10);
    Cell celCenario = row.getCell(11);
    Cell celCasoTeste = row.getCell(12);
    Cell celDescricao = row.getCell(13);
    Cell celQtdSistemas = row.getCell(19);
    Cell celCenarioAuto = row.getCell(21);
    Cell celType = row.getCell(22);
    Cell celTrg = row.getCell(23);
    Cell celSubject = row.getCell(24);
    Cell celCriacao = row.getCell(25);
    Cell celStep = row.getCell(16);

    Step steps = new Step();

    for (int i = 0; i < tamanhoLista; i++) {

        row = sheetPlano.getRow(linha);

        celCadeia = row.getCell(1);
        celSegmento = row.getCell(2);
        celProduto = row.getCell(3);
        celFuncionalidade = row.getCell(4);
        celCenarioIntegracao = row.getCell(5);
        celSistemaMaster = row.getCell(6);
        celSistemaEnvolvidos = row.getCell(7);
        celFornecedor = row.getCell(8);
        celTpRequisito = row.getCell(9);
        celRequisito = row.getCell(10);
        celCenario = row.getCell(11);
        celCasoTeste = row.getCell(12);
        celDescricao = row.getCell(13);
        Cell celComplexidade = row.getCell(15);
        celQtdSistemas = row.getCell(19);
        Cell celQtdStep = row.getCell(20);
        celCenarioAuto = row.getCell(21);
        celType = row.getCell(22);
        celTrg = row.getCell(23);
        celSubject = row.getCell(24);
        celCriacao = row.getCell(25);

        celCadeia.setCellValue(plano.get(i).getCadeia());
        celSegmento.setCellValue(plano.get(i).getSegmento());
        celProduto.setCellValue(plano.get(i).getProduto());
        celFuncionalidade.setCellValue(plano.get(i).getFuncionalidade());
        celCenarioIntegracao.setCellValue(plano.get(i).getCenarioIntegrado());
        celSistemaMaster.setCellValue(plano.get(i).getSistemaMaster());
        celSistemaEnvolvidos.setCellValue(plano.get(i).getSistemasEnvolvidos());
        celFornecedor.setCellValue(plano.get(i).getFornecedor());
        celTpRequisito.setCellValue(plano.get(i).getTpRequisito());
        celRequisito.setCellValue(plano.get(i).getRequisito());
        celCenario.setCellValue(plano.get(i).getCenarioTeste());
        celCasoTeste.setCellValue(plano.get(i).getCasoTeste());
        celDescricao.setCellValue(plano.get(i).getDescCasoTeste());
        String formulaComplexibilidade = celComplexidade.getCellFormula();
        celComplexidade.setCellFormula(formulaComplexibilidade);
        celQtdSistemas.setCellValue(plano.get(i).getQtdSistemas());
        String formulaQtdStep = celQtdStep.getCellFormula();
        celQtdStep.setCellFormula(formulaQtdStep);
        celCenarioAuto.setCellValue(plano.get(i).getCenarioAutomatizavel());
        celType.setCellValue(plano.get(i).getType());
        celTrg.setCellValue(plano.get(i).getTrg());
        celSubject.setCellValue(plano.get(i).getSubject());
        celCriacao.setCellValue(plano.get(i).getCriacaoAlteracao());

        celStep = row.getCell(16);

        row = sheetPlano.getRow(linha);
        //            celCasoTeste = row.getCell(12);
        int linhaStep = linha;

        List<Plano> listPlanos = banco.selectPlanoPorId(plano.get(i));

        List<Step> listStep = banco.getStepPorPlano(plano.get(i));

        int linhaLimpeza = linha;
        //limpa as clulas de step
        for (int cont = 0; cont <= 24; cont++) {

            Cell celNomeStep = row.getCell(16);
            Cell celDescStep = row.getCell(17);
            Cell celResultadoStep = row.getCell(18);

            String valor = null;
            celNomeStep.setCellValue(valor);
            celDescStep.setCellValue(valor);
            celResultadoStep.setCellValue(valor);

            linhaLimpeza = linhaLimpeza + 1;

            row = sheetPlano.getRow(linhaLimpeza);

        }
        //fim
        row = sheetPlano.getRow(linha);
        int tamanho = listStep.size();
        int idTemp = 0;
        for (int cont = 0; cont < tamanho; cont++) {

            //                   if(idTemp != listPlanos.get(cont).getStep().getId()){
            //                    model.addRow(new String[]{String.valueOf(listPlanos.get(cont).getStep().getNomeStep()), listPlanos.get(cont).getStep().getDescStep(),
            //                        listPlanos.get(cont).getStep().getResultadoStep(), String.valueOf(listPlanos.get(cont).getStep().getId())});
            //                   }
            Cell celNomeStep = row.getCell(16);
            Cell celDescStep = row.getCell(17);
            Cell celResultadoStep = row.getCell(18);

            celNomeStep.setCellValue(listStep.get(cont).getNomeStep());
            celDescStep.setCellValue(listStep.get(cont).getDescStep());
            celResultadoStep.setCellValue(listStep.get(cont).getResultadoStep());

            //caso o ct seja alterao pinta os steps de amarelo - inicio
            if (plano.get(i).getCriacaoAlteracao().equals("Alterao")) {
                Color color = new XSSFColor(java.awt.Color.yellow);
                //                    XSSFCellStyle style = workbook.createCellStyle();
                //                    style.setBorderTop((short) 6); // double lines border
                //                    style.setBorderBottom((short) 1); // single line border
                //                    style.setFillBackgroundColor(IndexedColors.YELLOW.getIndex());
                //                    
                //                    celNomeStep.setCellStyle(style);
            }
            //fim

            linhaStep = linhaStep + 1;

            row = sheetPlano.getRow(linhaStep);
            celStep = row.getCell(16);

            idTemp = listPlanos.get(cont).getId();
        }

        linha = linha + 25;
        row = sheetPlano.getRow(linha);
        cell = celCadeia;

    }

    FileOutputStream fileOut = new FileOutputStream(new File(panilha));
    workbook.write(fileOut);
    fileOut.close();
}

From source file:com.accenture.control.ExtraiPlanilha.java

/**
 * Mtodo para sobrescrever ct na planilha * com o ct existente em uma
 * determinada linha ser substituido */*from  w  w  w. j av a  2 s  . c om*/
 *
 * @author Raphael Coelho
 *
 * @param Plano - objeto plano
 * @param String - caminho da planilha
 * @param int - nmero da linha que est o ct na planilha
 *
 * @return void
 *
 */
public static void gravaCTPlanilha(Plano plano, String panilha, int linhaCelula) throws FileNotFoundException,
        IOException, InvalidFormatException, SQLException, ClassNotFoundException {

    /**
     * Exemplo bsico de um comentrio em JavaDoc
     */
    //recebe a planilha e atribui a variavel arquivo
    FileInputStream arquivo = new FileInputStream(new File(panilha));
    System.out.println(panilha);
    //instacia um workbook passando arquivo como paramentro
    ManipulaDadosSQLite banco = new ManipulaDadosSQLite();
    XSSFWorkbook workbook = new XSSFWorkbook(arquivo);

    XSSFSheet sheetPlano = workbook.getSheetAt(1);

    CellReference cellReference = new CellReference("B8");
    //     Row row = sheetPlano.getRow(cellReference.getRow());
    //     Cell cell = row.getCell(cellReference.getCol());

    //        int tamanhoLista = plano.size();
    int numeroCelula = 8;

    int linha = linhaCelula;
    int celula = 12;

    Row row = sheetPlano.getRow(linha);
    Cell cell;//= row.getCell(celula);
    Cell celCadeia = row.getCell(1);
    Cell celSegmento = row.getCell(2);
    Cell celProduto = row.getCell(3);
    Cell celFuncionalidade = row.getCell(4);
    Cell celCenarioIntegracao = row.getCell(5);
    Cell celSistemaMaster = row.getCell(6);
    Cell celSistemaEnvolvidos = row.getCell(7);
    Cell celFornecedor = row.getCell(8);
    Cell celTpRequisito = row.getCell(9);
    Cell celRequisito = row.getCell(10);
    Cell celCenario = row.getCell(11);
    Cell celCasoTeste = row.getCell(12);
    Cell celDescricao = row.getCell(13);
    Cell celQtdSistemas = row.getCell(19);
    Cell celCenarioAuto = row.getCell(21);
    Cell celType = row.getCell(22);
    Cell celTrg = row.getCell(23);
    Cell celSubject = row.getCell(24);
    Cell celCriacao = row.getCell(25);
    Cell celStep = row.getCell(16);

    Step steps = new Step();

    row = sheetPlano.getRow(linha);

    celCadeia = row.getCell(1);
    celSegmento = row.getCell(2);
    celProduto = row.getCell(3);
    celFuncionalidade = row.getCell(4);
    celCenarioIntegracao = row.getCell(5);
    celSistemaMaster = row.getCell(6);
    celSistemaEnvolvidos = row.getCell(7);
    celFornecedor = row.getCell(8);
    celTpRequisito = row.getCell(9);
    celRequisito = row.getCell(10);
    celCenario = row.getCell(11);
    celCasoTeste = row.getCell(12);
    celDescricao = row.getCell(13);
    Cell celComplexidade = row.getCell(15);
    celQtdSistemas = row.getCell(19);
    Cell celQtdStep = row.getCell(20);
    celCenarioAuto = row.getCell(21);
    celType = row.getCell(22);
    celTrg = row.getCell(23);
    celSubject = row.getCell(24);
    celCriacao = row.getCell(25);

    celCadeia.setCellValue(plano.getCadeia());
    celSegmento.setCellValue(plano.getSegmento());
    celProduto.setCellValue(plano.getProduto());
    celFuncionalidade.setCellValue(plano.getFuncionalidade());
    celCenarioIntegracao.setCellValue(plano.getCenarioIntegrado());
    celSistemaMaster.setCellValue(plano.getSistemaMaster());
    celSistemaEnvolvidos.setCellValue(plano.getSistemasEnvolvidos());
    celFornecedor.setCellValue(plano.getFornecedor());
    celTpRequisito.setCellValue(plano.getTpRequisito());
    celRequisito.setCellValue(plano.getRequisito());
    celCenario.setCellValue(plano.getCenarioTeste());
    celCasoTeste.setCellValue(plano.getCasoTeste());
    celDescricao.setCellValue(plano.getDescCasoTeste());
    String formulaComplexibilidade = celComplexidade.getCellFormula();
    celComplexidade.setCellFormula(formulaComplexibilidade);
    celQtdSistemas.setCellValue(plano.getQtdSistemas());
    String formulaQtdStep = celQtdStep.getCellFormula();
    celQtdStep.setCellFormula(formulaQtdStep);
    celCenarioAuto.setCellValue(plano.getCenarioAutomatizavel());
    celType.setCellValue(plano.getType());
    celTrg.setCellValue(plano.getTrg());
    celSubject.setCellValue(plano.getSubject());
    celCriacao.setCellValue(plano.getCriacaoAlteracao());

    celStep = row.getCell(16);

    row = sheetPlano.getRow(linha);
    //            celCasoTeste = row.getCell(12);
    int linhaStep = linha;

    List<Plano> listPlanos = banco.selectPlanoPorId(plano);

    List<Step> listStep = banco.getStepPorPlano(plano);

    int linhaLimpeza = linha;
    //limpa as clulas de step
    for (int cont = 0; cont <= 24; cont++) {

        Cell celNomeStep = row.getCell(16);
        Cell celDescStep = row.getCell(17);
        Cell celResultadoStep = row.getCell(18);
        String valor = null;
        celNomeStep.setCellValue(valor);
        celDescStep.setCellValue(valor);
        celResultadoStep.setCellValue(valor);

        linhaLimpeza = linhaLimpeza + 1;

        row = sheetPlano.getRow(linhaLimpeza);

    }
    //fim
    row = sheetPlano.getRow(linha);
    int tamanho = listStep.size();
    int idTemp = 0;
    for (int cont = 0; cont < tamanho; cont++) {

        //                   if(idTemp != listPlanos.get(cont).getStep().getId()){
        //                    model.addRow(new String[]{String.valueOf(listPlanos.get(cont).getStep().getNomeStep()), listPlanos.get(cont).getStep().getDescStep(),
        //                        listPlanos.get(cont).getStep().getResultadoStep(), String.valueOf(listPlanos.get(cont).getStep().getId())});
        //                   }
        Cell celNomeStep = row.getCell(16);
        Cell celDescStep = row.getCell(17);
        Cell celResultadoStep = row.getCell(18);

        celNomeStep.setCellValue(listStep.get(cont).getNomeStep());
        celDescStep.setCellValue(listStep.get(cont).getDescStep());
        celResultadoStep.setCellValue(listStep.get(cont).getResultadoStep());
        //caso o ct seja alterao pinta os steps de amarelo - inicio
        if (plano.getCriacaoAlteracao().equals("Alterao")) {
            Color color = new XSSFColor(java.awt.Color.yellow);
            //                    XSSFCellStyle style = workbook.createCellStyle();
            //                    style.setBorderTop((short) 6); // double lines border
            //                    style.setBorderBottom((short) 1); // single line border
            //                    style.setFillBackgroundColor((XSSFColor) color);
            //                    
            //                    celNomeStep.setCellStyle(style);
        }
        //fim
        linhaStep = linhaStep + 1;

        row = sheetPlano.getRow(linhaStep);
        celStep = row.getCell(16);

        idTemp = listPlanos.get(cont).getId();
    }

    linha = linha + 25;
    row = sheetPlano.getRow(linha);
    cell = celCadeia;

    FileOutputStream fileOut = new FileOutputStream(new File(panilha));
    workbook.write(fileOut);
    fileOut.close();
}

From source file:com.adobe.acs.commons.mcp.impl.ProcessErrorReportExcelServlet.java

License:Apache License

CellStyle createHeaderStyle(Workbook wb) {
    XSSFCellStyle xstyle = (XSSFCellStyle) wb.createCellStyle();
    XSSFColor header = new XSSFColor(new Color(79, 129, 189));
    xstyle.setFillForegroundColor(header);
    xstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    XSSFFont font = (XSSFFont) wb.createFont();
    font.setColor(IndexedColors.WHITE.index);
    xstyle.setFont(font);/*ww w . ja v a  2  s .co m*/
    return xstyle;
}

From source file:com.crm.webapp.util.ExcelCustomExporter.java

License:Apache License

protected void createCustomFonts() {

    Font facetFont = wb.createFont();
    Font cellFont = wb.createFont();

    if (cellFontColor != null) {
        XSSFColor cellColor = new XSSFColor(cellFontColor);
        ((XSSFFont) cellFont).setColor(cellColor);
    }//  w  w  w  .jav a2 s . c  o m
    if (cellFontSize != null) {
        cellFont.setFontHeightInPoints((short) cellFontSize);
    }

    if (cellFontStyle.equalsIgnoreCase("BOLD")) {
        cellFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    }
    if (cellFontStyle.equalsIgnoreCase("ITALIC")) {
        cellFont.setItalic(true);
    }

    if (facetFontStyle.equalsIgnoreCase("BOLD")) {
        facetFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    }
    if (facetFontStyle.equalsIgnoreCase("ITALIC")) {
        facetFont.setItalic(true);
    }

    if (fontName != null) {
        cellFont.setFontName(fontName);
        facetFont.setFontName(fontName);
    }

    cellStyle.setFont(cellFont);

    if (facetBackground != null) {
        XSSFColor backgroundColor = new XSSFColor(facetBackground);
        ((XSSFCellStyle) facetStyle).setFillForegroundColor(backgroundColor);
        facetStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);

    }

    if (facetFontColor != null) {
        XSSFColor facetColor = new XSSFColor(facetFontColor);
        ((XSSFFont) facetFont).setColor(facetColor);

    }
    if (facetFontSize != null) {
        facetFont.setFontHeightInPoints((short) facetFontSize);
    }

    facetStyle.setFont(facetFont);
    facetStyle.setAlignment(CellStyle.ALIGN_CENTER);

}