Example usage for org.apache.poi.ss.usermodel RichTextString applyFont

List of usage examples for org.apache.poi.ss.usermodel RichTextString applyFont

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel RichTextString applyFont.

Prototype

void applyFont(short fontIndex);

Source Link

Document

Applies the specified font to the entire string.

Usage

From source file:com.cms.utils.ExportExcell.java

private Comment getcellComment(FormatExcell item, Cell cell) {
    ExcellHeaderComment headerCommand = item.getHeaderCommand();
    Drawing sSFPatriarch = sh.createDrawingPatriarch();
    CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
    ClientAnchor anchor = factory.createClientAnchor();
    Comment comment1 = sSFPatriarch.createCellComment(anchor);

    anchor.setCol1(headerCommand.getRow1());
    anchor.setCol2(headerCommand.getRow2());
    anchor.setRow1(headerCommand.getColumn1());
    anchor.setRow2(headerCommand.getColumn2());
    anchor.setDx1(headerCommand.getDx1());
    anchor.setDx2(headerCommand.getDx2());
    anchor.setDy1(headerCommand.getDy1());
    anchor.setDy2(headerCommand.getDy2());

    RichTextString rtf1 = factory.createRichTextString(headerCommand.getValue());
    Font font = wb.createFont();//  w  w w  .jav a 2  s .  c  o  m
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 10);
    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    font.setColor(IndexedColors.RED.getIndex());
    rtf1.applyFont(font);
    comment1.setString(rtf1);
    comment1.setAuthor("Logistics");
    //        comment1.setColumn(cell.getColumnIndex());
    //        comment1.setRow(cell.getRowIndex());
    return comment1;
}

From source file:com.cms.utils.ExportExcell.java

private Comment getcellComment(Sheet sh, FormatExcell item, Cell cell) {
    ExcellHeaderComment headerCommand = item.getHeaderCommand();
    Drawing sSFPatriarch = sh.createDrawingPatriarch();
    CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
    ClientAnchor anchor = factory.createClientAnchor();
    Comment comment1 = sSFPatriarch.createCellComment(anchor);

    anchor.setCol1(headerCommand.getRow1());
    anchor.setCol2(headerCommand.getRow2());
    anchor.setRow1(headerCommand.getColumn1());
    anchor.setRow2(headerCommand.getColumn2());
    anchor.setDx1(headerCommand.getDx1());
    anchor.setDx2(headerCommand.getDx2());
    anchor.setDy1(headerCommand.getDy1());
    anchor.setDy2(headerCommand.getDy2());

    RichTextString rtf1 = factory.createRichTextString(headerCommand.getValue());
    Font font = wb.createFont();//  www  .j a v a2s  .  c om
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 10);
    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    font.setColor(IndexedColors.RED.getIndex());
    rtf1.applyFont(font);
    comment1.setString(rtf1);
    comment1.setAuthor("Logistics");
    //        comment1.setColumn(cell.getColumnIndex());
    //        comment1.setRow(cell.getRowIndex());
    return comment1;
}

From source file:com.globalsight.everest.qachecks.DITAQAChecker.java

License:Apache License

private RichTextString getRichTextString(Workbook p_workBook, String segment, List<String> highlightIndexes) {
    RichTextString ts = new XSSFRichTextString(segment);
    ts.applyFont(getNormalFont(p_workBook));
    for (String red : highlightIndexes) {
        String[] arr = red.split("-");
        int indexStart = Integer.parseInt(arr[0]);
        int indexEnd = Integer.parseInt(arr[1]);
        ts.applyFont(indexStart, indexEnd, getRedFont(p_workBook));
    }//from w w w .j av a2  s  . c o m
    return ts;
}

From source file:com.pe.nisira.movil.view.action.MultitablaAction.java

public StreamedContent downFormatExcel() throws Exception {
    InputStream stream = null;//from w ww  .  j  a v a 2s .  c om
    StreamedContent arch = null;
    try {
        String folder = "C:\\SOLUTION\\WEB\\FORMATOS_IMPORTACION";
        File ruta = new File(folder);
        if (!ruta.isDirectory()) {
            ruta.mkdirs();
        }
        String rutaArchivo = folder + "\\FI_MULTITABLA.xlsx";
        File fileXls = new File(rutaArchivo);
        if (fileXls.exists()) {
            fileXls.delete();
        }
        fileXls.createNewFile();
        XSSFWorkbook libro = new XSSFWorkbook();
        FileOutputStream file = new FileOutputStream(fileXls);
        XSSFSheet hoja = libro.createSheet("IMPORTAR_MULTITABLA");
        CreationHelper factory = libro.getCreationHelper();
        hoja = libro.getSheetAt(0);
        XSSFCellStyle style = libro.createCellStyle();
        Font font = libro.createFont();
        Font font1 = libro.createFont();
        Drawing drawing = hoja.createDrawingPatriarch();
        ClientAnchor anchor1 = factory.createClientAnchor();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        font.setFontHeightInPoints((short) 8);
        font1.setFontHeightInPoints((short) 8);
        font1.setFontName("Arial");
        font.setFontName("Arial");
        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(247, 150, 70)));
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style.setAlignment(CellStyle.VERTICAL_CENTER);
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setFont(font);
        for (int f = 0; f < 1; f++) {
            XSSFRow fila = hoja.createRow(f);
            for (int c = 0; c < 4; c++) {
                XSSFCell celda = fila.createCell(c);
                celda.setCellStyle(style);
                anchor1.setCol1(celda.getColumnIndex());
                anchor1.setCol2(celda.getColumnIndex() + 4);
                anchor1.setRow1(fila.getRowNum());
                anchor1.setRow2(fila.getRowNum() + 3);
                Comment comment = drawing.createCellComment(anchor1);
                if (f == 0 && c == 0) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Indicar si es es Padre (Usar SI o NO).");
                    str.applyFont(font1);
                    str.applyFont(0, 29, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("Es Padre");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 1) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Opcional \n - Escribir la Abreviatura del campo del cual depende este.");
                    str.applyFont(font1);
                    str.applyFont(0, 29, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("Abreviatura Padre");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 2) {
                    RichTextString str = factory
                            .createRichTextString("ADM:\nCampo Obligatorio \n - Descripcion de la multitabla");
                    str.applyFont(font1);
                    str.applyFont(0, 29, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("DESCRIPCION");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 3) {
                    RichTextString str = factory
                            .createRichTextString("ADM:\nCampo Obligatorio \n - Abreviatura de la multitabla.");
                    str.applyFont(font1);
                    str.applyFont(0, 29, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("ABREVIATURA");
                    celda.setCellComment(comment);
                }
            }
        }
        hoja.autoSizeColumn((short) 0);
        hoja.autoSizeColumn((short) 1);
        hoja.autoSizeColumn((short) 2);
        libro.write(file);
        file.close();
        stream = new FileInputStream(new File(rutaArchivo));
        arch = new DefaultStreamedContent(stream, "application/xlsx", "FI_MULTITABLA.xlsx");
    } catch (FileNotFoundException ex) {
        System.out.println("Error al Descargar : " + ex.getMessage());
    }
    return arch;
}

From source file:com.pe.nisira.movil.view.action.RegistroPaleta.java

public StreamedContent downFormatExcel() throws Exception {
    InputStream stream = null;/*from   w ww. j a  v a  2 s. c o  m*/
    StreamedContent arch = null;
    try {
        String folder = "C:\\SOLUTION\\WEB\\FORMATOS_IMPORTACION";
        File ruta = new File(folder);
        if (!ruta.isDirectory()) {
            ruta.mkdirs();
        }
        String rutaArchivo = folder + "\\FI_REGISTROPALE.xlsx";
        File fileXls = new File(rutaArchivo);
        if (fileXls.exists()) {
            fileXls.delete();
        }
        fileXls.createNewFile();
        XSSFWorkbook libro = new XSSFWorkbook();
        FileOutputStream file2 = new FileOutputStream(fileXls);
        XSSFSheet hoja = libro.createSheet("IMPORTAR_PALETA");
        CreationHelper factory = libro.getCreationHelper();
        hoja = libro.getSheetAt(0);
        XSSFCellStyle style = libro.createCellStyle();
        Font font = libro.createFont();
        Font font1 = libro.createFont();
        Drawing drawing = hoja.createDrawingPatriarch();
        ClientAnchor anchor1 = factory.createClientAnchor();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        font.setFontHeightInPoints((short) 8);
        font1.setFontHeightInPoints((short) 8);
        font1.setFontName("Arial");
        font.setFontName("Arial");
        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(247, 150, 70)));
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style.setAlignment(CellStyle.VERTICAL_CENTER);
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setFont(font);

        XSSFSheet hoja2 = libro.createSheet("IMPORTAR_DET_PALETA");
        CreationHelper factory2 = libro.getCreationHelper();
        hoja2 = libro.getSheetAt(1);
        XSSFCellStyle style2 = libro.createCellStyle();
        Font font2 = libro.createFont();
        Font font12 = libro.createFont();
        Drawing drawing2 = hoja2.createDrawingPatriarch();
        ClientAnchor anchor12 = factory2.createClientAnchor();
        font2.setBoldweight(Font.BOLDWEIGHT_BOLD);
        font2.setFontHeightInPoints((short) 8);
        font12.setFontHeightInPoints((short) 8);
        font12.setFontName("Arial");
        font2.setFontName("Arial");
        style2.setFillForegroundColor(new XSSFColor(new java.awt.Color(247, 150, 70)));
        style2.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style2.setAlignment(CellStyle.VERTICAL_CENTER);
        style2.setAlignment(CellStyle.ALIGN_CENTER);
        style2.setFont(font);
        for (int f = 0; f < 1; f++) {
            XSSFRow fila = hoja.createRow(f);
            for (int c = 0; c < 29; c++) {
                XSSFCell celda = fila.createCell(c);
                celda.setCellStyle(style);
                anchor1.setCol1(celda.getColumnIndex());
                anchor1.setCol2(celda.getColumnIndex() + 5);
                anchor1.setRow1(fila.getRowNum());
                anchor1.setRow2(fila.getRowNum() + 3);
                Comment comment = drawing.createCellComment(anchor1);
                if (f == 0 && c == 0) {
                    RichTextString str = factory.createRichTextString("ADM:\nCampo Obligatorio \n - IDEMPRESA");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDEMPRESA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 1) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - IDREGISTROPALETA. \n Debe de tener (15) caracteres");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDREGISTROPALETA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 2) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del emisor. \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDEMISOR");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 3) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - id de la operacion.\n -Debe tener 4 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDOPERACION");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 4) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Numero de Operacion.\n -Debe tener 10 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("NUMOPERACION");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 5) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del motivo de Paleta.\n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDMOTIVOPALETA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 6) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id documento. \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDDOCUMENTO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 7) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Serie del Documento. \n -Debe tener 4 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("SERIE");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 8) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Numero de Documento.\n -Debe tener 7 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("NUMERO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 9) {
                    RichTextString str = factory
                            .createRichTextString("ADM:\nCampo Obligatorio \n - Formato YYYY/MM/DD.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("FECHA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 10) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Perido del ao \n - fromato YYYYMM.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("PERIODO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 11) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del estado \n -Debe tener 2 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDESTADO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 12) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del cliente o proveedor \n -Debe tener 11 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDCLIEPROV");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 13) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Numero de Paleta \n -Debe tener 20 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("NROPALETA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 14) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id de envase \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDENVASE");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 15) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id la sucursal \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDSUCURSAL");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 16) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del almacen. \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDALMACEN");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 17) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del embalaje. \n -Debe tener 10 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDEMBALAJE");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 18) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id de cultivo. \n -Debe tener 4 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDCULTIVO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 19) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - id de Variadd. \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDVARIEDAD");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 20) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Observaciones sobre la paleta \n -como maximo 240 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("OBSERVACIONES");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 21) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n -Nombre de la venta \n como maximo 50 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("VENTANA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 22) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Cantidad. \n - 15 numeros y 2 decimales como maximo.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("CANTIDAD");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 23) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Estado de la paleta \n- 1 = cerrado, 0 = Abierto.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("CERRADO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 24) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Sincroniza \n - N = no , S = si.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("SINCRONIZA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 25) {
                    RichTextString str = factory
                            .createRichTextString("ADM:\nCampo Obligatorio \n - Formato YYYY/MM/DD.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("FECHACREACION");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 26) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Numero de Manural\n Debe tener 10 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("NROMANUAL");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 27) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - idcliepro-destino\n debe tener 11 caracteres");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDCLIEPROV_DESTINO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 28) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Tipo de paleta\n debe tener 1 caraccter..");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("TIPO");
                    celda.setCellComment(comment);
                }
            }
        }
        hoja.autoSizeColumn((short) 0);
        hoja.autoSizeColumn((short) 1);
        hoja.autoSizeColumn((short) 2);
        hoja.autoSizeColumn((short) 3);
        hoja.autoSizeColumn((short) 4);
        hoja.autoSizeColumn((short) 5);
        hoja.autoSizeColumn((short) 6);
        hoja.autoSizeColumn((short) 7);
        hoja.autoSizeColumn((short) 8);
        hoja.autoSizeColumn((short) 9);
        hoja.autoSizeColumn((short) 10);
        hoja.autoSizeColumn((short) 11);
        hoja.autoSizeColumn((short) 12);
        hoja.autoSizeColumn((short) 13);
        hoja.autoSizeColumn((short) 14);
        hoja.autoSizeColumn((short) 15);
        hoja.autoSizeColumn((short) 16);
        hoja.autoSizeColumn((short) 17);
        hoja.autoSizeColumn((short) 18);
        hoja.autoSizeColumn((short) 19);
        hoja.autoSizeColumn((short) 20);
        hoja.autoSizeColumn((short) 21);
        hoja.autoSizeColumn((short) 22);
        hoja.autoSizeColumn((short) 23);
        hoja.autoSizeColumn((short) 24);
        hoja.autoSizeColumn((short) 25);
        hoja.autoSizeColumn((short) 26);
        hoja.autoSizeColumn((short) 27);
        hoja.autoSizeColumn((short) 28);
        for (int f = 0; f < 2; f++) {
            XSSFRow fila2 = hoja2.createRow(f);
            if (f == 0) {
                for (int c = 0; c < 15; c++) {
                    XSSFCell celda2 = fila2.createCell(c);
                    anchor12.setCol1(celda2.getColumnIndex());
                    anchor12.setCol2(celda2.getColumnIndex() + 8);
                    anchor12.setRow1(fila2.getRowNum());
                    anchor12.setRow2(fila2.getRowNum() + 8);
                    Comment comment2 = drawing2.createCellComment(anchor12);
                    RichTextString str;
                    switch (c) {
                    case 0:
                        celda2.setCellStyle(style2);
                        str = factory2.createRichTextString(
                                "ADM:\nCampo Obligatorio \n - El Cdigo debe de ser nico.");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDEMPRESA");
                        celda2.setCellComment(comment2);
                        break;
                    case 1:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio ");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDREGISTROPALETA");
                        celda2.setCellComment(comment2);
                        break;
                    case 2:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio ");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("ITEM");
                        celda2.setCellComment(comment2);
                        break;
                    case 3:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio ");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDCLIEPROV");
                        celda2.setCellComment(comment2);
                        break;
                    case 4:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDLOTE");
                        celda2.setCellComment(comment2);
                        break;
                    case 5:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDCONDICION");
                        celda2.setCellComment(comment2);
                        break;
                    case 6:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDTALLA");
                        celda2.setCellComment(comment2);
                        break;
                    case 7:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDCOLOR");
                        celda2.setCellComment(comment2);
                        break;
                    case 8:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("CANTIDAD");
                        celda2.setCellComment(comment2);
                        break;
                    case 9:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDEMBALAJE");
                        celda2.setCellComment(comment2);
                        break;
                    case 10:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDPRODUCTO");
                        celda2.setCellComment(comment2);
                        break;
                    case 11:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDLOTEP");
                        celda2.setCellComment(comment2);
                        break;
                    case 12:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDCONSUMIDOR");
                        celda2.setCellComment(comment2);
                        break;
                    case 13:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDLOTECAMPO");
                        celda2.setCellComment(comment2);
                        break;
                    case 14:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDPRESENTACION");
                        celda2.setCellComment(comment2);
                        break;
                    }
                }
            }
        }
        hoja2.autoSizeColumn((short) 0);
        hoja2.autoSizeColumn((short) 1);
        hoja2.autoSizeColumn((short) 2);
        hoja2.autoSizeColumn((short) 3);
        hoja2.autoSizeColumn((short) 4);
        hoja2.autoSizeColumn((short) 5);
        hoja2.autoSizeColumn((short) 6);
        hoja2.autoSizeColumn((short) 7);
        hoja2.autoSizeColumn((short) 8);
        hoja2.autoSizeColumn((short) 9);
        hoja2.autoSizeColumn((short) 10);
        hoja2.autoSizeColumn((short) 11);
        hoja2.autoSizeColumn((short) 12);
        hoja2.autoSizeColumn((short) 13);
        hoja2.autoSizeColumn((short) 14);
        hoja2.autoSizeColumn((short) 15);
        libro.write(file2);
        file2.close();
        stream = new FileInputStream(new File(rutaArchivo));
        arch = new DefaultStreamedContent(stream, "application/xlsx", "FI_REGISTROPALE.xlsx");
    } catch (FileNotFoundException ex) {
        System.out.println("Error al Descargar : " + ex.getMessage());
    }
    return arch;
}

From source file:com.tremolosecurity.scale.ui.reports.GenerateSpreadsheet.java

License:Apache License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");
    resp.setHeader("Pragma", "no-cache");

    ReportViewer scaleReport = (ReportViewer) req.getSession().getAttribute("scaleReportCached");

    Workbook wb = new XSSFWorkbook();

    Font font = wb.createFont();/* ww  w.  j a va2  s.com*/
    font.setBold(true);

    Font titleFont = wb.createFont();
    titleFont.setBold(true);
    titleFont.setFontHeightInPoints((short) 16);

    Sheet sheet = wb.createSheet(WorkbookUtil.createSafeSheetName(scaleReport.getReportInfo().getName()));

    //Create a header
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);

    RichTextString title = new XSSFRichTextString(scaleReport.getReportInfo().getName());
    title.applyFont(titleFont);

    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));

    cell.setCellValue(title);

    row = sheet.createRow(1);
    cell = row.createCell(0);
    cell.setCellValue(scaleReport.getReportInfo().getDescription());

    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 3));

    row = sheet.createRow(2);
    cell = row.createCell(0);
    cell.setCellValue(scaleReport.getRunDateTime());

    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 3));

    row = sheet.createRow(3);

    int rowNum = 4;

    if (scaleReport.getResults().getGrouping().isEmpty()) {
        row = sheet.createRow(rowNum);
        cell = row.createCell(0);
        cell.setCellValue("There is no data for this report");
    } else {

        for (ReportGrouping group : scaleReport.getResults().getGrouping()) {
            for (String colHeader : scaleReport.getResults().getHeaderFields()) {
                row = sheet.createRow(rowNum);
                cell = row.createCell(0);

                RichTextString rcolHeader = new XSSFRichTextString(colHeader);
                rcolHeader.applyFont(font);

                cell.setCellValue(rcolHeader);
                cell = row.createCell(1);
                cell.setCellValue(group.getHeader().get(colHeader));

                rowNum++;
            }

            row = sheet.createRow(rowNum);

            int cellNum = 0;
            for (String colHeader : scaleReport.getResults().getDataFields()) {
                cell = row.createCell(cellNum);

                RichTextString rcolHeader = new XSSFRichTextString(colHeader);
                rcolHeader.applyFont(font);
                cell.setCellValue(rcolHeader);
                cellNum++;
            }

            rowNum++;

            for (Map<String, String> dataRow : group.getData()) {
                cellNum = 0;
                row = sheet.createRow(rowNum);
                for (String colHeader : scaleReport.getResults().getDataFields()) {
                    cell = row.createCell(cellNum);
                    cell.setCellValue(dataRow.get(colHeader));
                    cellNum++;
                }
                rowNum++;
            }

            row = sheet.createRow(rowNum);
            rowNum++;
        }

    }

    resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    wb.write(resp.getOutputStream());

}

From source file:com.tremolosecurity.scalejs.ws.ScaleMain.java

License:Apache License

private void exportToExcel(HttpFilterRequest request, HttpFilterResponse response, Gson gson)
        throws IOException {
    int lastslash = request.getRequestURI().lastIndexOf('/');
    int secondlastslash = request.getRequestURI().lastIndexOf('/', lastslash - 1);

    String id = request.getRequestURI().substring(secondlastslash + 1, lastslash);

    ReportResults res = (ReportResults) request.getSession().getAttribute(id);

    if (res == null) {
        response.setStatus(404);// ww w.j  a  v a2  s. co m
        ScaleError error = new ScaleError();
        error.getErrors().add("Report no longer available");
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().print(gson.toJson(error).trim());
        response.getWriter().flush();
    } else {

        response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");
        response.setHeader("Pragma", "no-cache");

        Workbook wb = new XSSFWorkbook();

        Font font = wb.createFont();
        font.setBold(true);

        Font titleFont = wb.createFont();
        titleFont.setBold(true);
        titleFont.setFontHeightInPoints((short) 16);

        Sheet sheet = wb.createSheet(WorkbookUtil.createSafeSheetName(res.getName()));

        //Create a header
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);

        RichTextString title = new XSSFRichTextString(res.getName());
        title.applyFont(titleFont);

        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));

        cell.setCellValue(title);

        row = sheet.createRow(1);
        cell = row.createCell(0);
        cell.setCellValue(res.getDescription());

        sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 3));

        row = sheet.createRow(2);
        cell = row.createCell(0);
        //cell.setCellValue(new DateTime().toString("MMMM Do, YYYY h:mm:ss a"));

        sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 3));

        row = sheet.createRow(3);

        int rowNum = 4;

        if (res.getGrouping().isEmpty()) {
            row = sheet.createRow(rowNum);
            cell = row.createCell(0);
            cell.setCellValue("There is no data for this report");
        } else {

            for (ReportGrouping group : res.getGrouping()) {
                for (String colHeader : res.getHeaderFields()) {
                    row = sheet.createRow(rowNum);
                    cell = row.createCell(0);

                    RichTextString rcolHeader = new XSSFRichTextString(colHeader);
                    rcolHeader.applyFont(font);

                    cell.setCellValue(rcolHeader);
                    cell = row.createCell(1);
                    cell.setCellValue(group.getHeader().get(colHeader));

                    rowNum++;
                }

                row = sheet.createRow(rowNum);

                int cellNum = 0;
                for (String colHeader : res.getDataFields()) {
                    cell = row.createCell(cellNum);

                    RichTextString rcolHeader = new XSSFRichTextString(colHeader);
                    rcolHeader.applyFont(font);
                    cell.setCellValue(rcolHeader);
                    cellNum++;
                }

                rowNum++;

                for (Map<String, String> dataRow : group.getData()) {
                    cellNum = 0;
                    row = sheet.createRow(rowNum);
                    for (String colHeader : res.getDataFields()) {
                        cell = row.createCell(cellNum);
                        cell.setCellValue(dataRow.get(colHeader));
                        cellNum++;
                    }
                    rowNum++;
                }

                row = sheet.createRow(rowNum);
                rowNum++;
            }

        }

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        wb.write(response.getOutputStream());
    }
}

From source file:excel.CellComments.java

License:Apache License

public static void main(String[] args) throws IOException {
    try (Workbook wb = new XSSFWorkbook()) {

        CreationHelper factory = wb.getCreationHelper();

        Sheet sheet = wb.createSheet();/* w  w w .j a  va  2  s .c  o  m*/

        Cell cell1 = sheet.createRow(3).createCell(5);
        cell1.setCellValue("F4");

        Drawing<?> drawing = sheet.createDrawingPatriarch();

        ClientAnchor anchor = factory.createClientAnchor();

        Comment comment1 = drawing.createCellComment(anchor);
        RichTextString str1 = factory.createRichTextString("Hello, World!");
        comment1.setString(str1);
        comment1.setAuthor("Apache POI");
        cell1.setCellComment(comment1);

        Cell cell2 = sheet.createRow(2).createCell(2);
        cell2.setCellValue("C3");

        Comment comment2 = drawing.createCellComment(anchor);
        RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");
        //apply custom font to the text in the comment
        Font font = wb.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 14);
        font.setBold(true);
        font.setColor(IndexedColors.RED.getIndex());
        str2.applyFont(font);

        comment2.setString(str2);
        comment2.setAuthor("Apache POI");
        comment2.setAddress(new CellAddress("C3"));

        try (FileOutputStream out = new FileOutputStream("comments.xlsx")) {
            wb.write(out);
        }
    }
}

From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

private RichTextString createRichTextFromContent(List<Content> contentList, CreationHelper createHelper,
        Workbook wb, short fontIndex) {
    StringBuilder text = new StringBuilder();
    int[] idx = new int[contentList.size()];
    int i = 0;/*from ww w  .  j a  v a  2  s. c om*/
    for (Content content : contentList) {
        idx[i++] = text.length();
        text.append(content.getText());
    }
    RichTextString richText = createHelper.createRichTextString(text.toString());
    richText.applyFont(fontIndex);
    for (int n = 0; n < contentList.size(); n++) {
        Content content = contentList.get(n);
        Font font = getFont(fontIndex, content.getAttributeSet(), wb);
        if (font != null) {
            int end = (n < idx.length - 1) ? idx[n + 1] : text.length();
            richText.applyFont(idx[n], end, font);
        }
    }
    return richText;
}

From source file:packtest.CellComments.java

License:Apache License

public static void main(String[] args) throws IOException {
    Workbook wb = new XSSFWorkbook();

    CreationHelper factory = wb.getCreationHelper();

    Sheet sheet = wb.createSheet();/* w  w  w.  j  a v a 2 s .c o  m*/

    Cell cell1 = sheet.createRow(3).createCell(5);
    cell1.setCellValue("F4");

    Drawing drawing = sheet.createDrawingPatriarch();

    ClientAnchor anchor = factory.createClientAnchor();

    Comment comment1 = drawing.createCellComment(anchor);
    RichTextString str1 = factory.createRichTextString("Hello, World!");
    comment1.setString(str1);
    comment1.setAuthor("Apache POI");
    cell1.setCellComment(comment1);

    Cell cell2 = sheet.createRow(2).createCell(2);
    cell2.setCellValue("C3");

    Comment comment2 = drawing.createCellComment(anchor);
    RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");
    //apply custom font to the text in the comment
    Font font = wb.createFont();
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 14);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setColor(IndexedColors.RED.getIndex());
    str2.applyFont(font);

    comment2.setString(str2);
    comment2.setAuthor("Apache POI");
    //        comment2.setAddress(new CellAddress("C3"));

    String fname = "comments.xlsx";
    FileOutputStream out = new FileOutputStream(fname);
    wb.write(out);
    out.close();

    wb.close();
}