Example usage for org.apache.poi.ss.usermodel CreationHelper createRichTextString

List of usage examples for org.apache.poi.ss.usermodel CreationHelper createRichTextString

Introduction

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

Prototype

RichTextString createRichTextString(String text);

Source Link

Document

Creates a new RichTextString instance

Usage

From source file:com.tecnosur.util.Excel.java

private static void createCell(HSSFWorkbook wb, Row row, int column, short halign, short valign,
        String strContenido, boolean booBorde, boolean booCabecera) {
    CreationHelper ch = wb.getCreationHelper();
    Cell cell = row.createCell(column);/*ww w.  j a v  a 2  s .co  m*/
    HSSFFont cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 8);
    cellFont.setFontName(HSSFFont.FONT_ARIAL);
    cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    cell.setCellValue(ch.createRichTextString(strContenido));
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(valign);
    cellStyle.setFont(cellFont);
    if (booBorde) {
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBottomBorderColor((short) 8);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setLeftBorderColor((short) 8);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setRightBorderColor((short) 8);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setTopBorderColor((short) 8);
    }
    if (booCabecera) {
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBottomBorderColor((short) 8);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setLeftBorderColor((short) 8);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setRightBorderColor((short) 8);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setTopBorderColor((short) 8);

        cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
        cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    }
    cell.setCellStyle(cellStyle);
}

From source file:com.vaadin.addon.spreadsheet.action.InsertDeleteCellCommentAction.java

License:Open Source License

private void createCellComment(Spreadsheet spreadsheet, Sheet sheet, Cell cell, CellReference cellRef) {
    CreationHelper factory = sheet.getWorkbook().getCreationHelper();
    Drawing drawing = sheet.createDrawingPatriarch();

    ClientAnchor anchor = factory.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setCol2(cell.getColumnIndex() + 1);
    anchor.setRow1(cell.getRowIndex());/*  ww  w  . j  a  va  2s .  c o m*/
    anchor.setRow2(cell.getRowIndex() + 3);

    // Create the comment and set the text+author
    Comment comment = drawing.createCellComment(anchor);
    RichTextString str = factory.createRichTextString("");
    comment.setString(str);

    // Fetch author from provider or fall back to default
    String author = null;
    if (spreadsheet.getCommentAuthorProvider() != null) {
        author = spreadsheet.getCommentAuthorProvider().getAuthorForComment(cellRef);
    }
    if (author == null || author.trim().isEmpty()) {
        author = "Spreadsheet User";
    }
    comment.setAuthor(author);

    // Assign the comment to the cell
    cell.setCellComment(comment);
}

From source file:com.vaadin.addon.spreadsheet.SpreadsheetHandlerImpl.java

@Override
public void updateCellComment(String text, int col, int row) {
    CreationHelper factory = spreadsheet.getWorkbook().getCreationHelper();
    RichTextString str = factory.createRichTextString(text);
    spreadsheet.getActiveSheet().getCellComment(row - 1, col - 1).setString(str);
}

From source file:das.pf.io.IOExcel.java

License:Open Source License

private void createHeaderData(Sheet sheet, CellStyle style) {
    Row row = sheet.createRow(2);/*from   w w w  .  j av a 2s .  c  om*/
    CreationHelper helper = sheet.getWorkbook().getCreationHelper();

    String[] titles = new String[] { "Pais", "Regiones", "Mercados Relevantes", "CT", "Key Markets", "Producto",
            "Key Competitors", "Sku", "Laboratorios", "Tipo de Mercado", "Molculas" };

    for (int index = 0; index < titles.length; index++) {
        Cell cell = row.createCell(index);

        cell.setCellType(Cell.CELL_TYPE_STRING);
        cell.setCellValue(helper.createRichTextString(titles[index]));
        cell.setCellStyle(style);

        cell = null;
    }

    row = null;
    helper = null;
}

From source file:das.pf.io.IOExcel.java

License:Open Source License

/**
 * Este metodo se encarga de escribir en la hoja de destino todos los datos relacionados con las Clases
 * Terapeuticas, que se encuentren dentro de la hoja fuente.
 * /*w ww .  j av a  2s. c  o m*/
 * @param sheet
 *          Instancia que modela la hoja objetivo o hoja en la que se desea trabajar.
 * 
 * @param source
 *          Instancia que modela la hoja que posee todos las Clases Terapeuticas.
 * 
 * @param start 
 *          Indica el indice de la primer fila donde se encuentran las clases terapeuticas.
 * 
 * @param endRow 
 *          Inidca el indice de la ultima fila que se desea escribir.
 */
private void writeCT(Sheet sheet, Sheet source, int start, int endRow) {
    int indexTarget = 3;
    int indexRow = start;

    String ct = "";
    CreationHelper helper = sheet.getWorkbook().getCreationHelper();

    while (indexRow < (endRow + start)) {
        try {
            Row rowSource = source.getRow(indexRow);

            if (rowSource != null) {
                Cell type = rowSource.getCell(2);

                if (type != null) {

                    if (type.getRichStringCellValue().getString().equals("ATC IV")) {
                        ct = rowSource.getCell(6).getRichStringCellValue().getString();

                        int totalPacks = 0;
                        int indexProd = indexRow + 1;
                        int count = 0;
                        int totalProdu = getNumberOfSubNodes(source, indexRow, "Prds.", "ATC IV");

                        // se obtienen los totales de productos de todos los paquetes que pertenescan a la clase terapeutica
                        for (int subNodeProduc = 0; subNodeProduc < totalProdu; subNodeProduc++) {
                            count = getNumberOfSubNodes(source, indexProd, "Packs", "Prds.");
                            totalPacks += count;

                            indexProd += count + 1;
                        }

                        // se escribes la cantidad correcta de filas con la clase terapeutica correspondiente
                        for (int indexCT = 0; indexCT < totalPacks; indexCT++) {
                            Row row = sheet.createRow(indexTarget++);
                            Cell cellCT = row.createCell(3);

                            cellCT.setCellType(Cell.CELL_TYPE_STRING);
                            cellCT.setCellValue(helper.createRichTextString(ct));

                            cellCT = null;
                            row = null;
                        }

                        indexRow += (totalPacks + totalProdu);
                    } else
                        indexRow++;

                    type = null;
                } else
                    indexRow++;
            } else
                indexRow++;
        } catch (NullPointerException ex) {
            Logger.getLogger(IOExcel.class.getName()).log(Level.SEVERE, String.format("indexRow: %d", indexRow),
                    ex);

            Util.showException("Ocurrio un error procesando las Clases Terapeuticas", ex);
        }
    }
}

From source file:das.pf.io.IOExcel.java

License:Open Source License

/**
 * Este metodo se encarga de escribir o llenar todos los productos en la hoja de destino u objetivo,
 * que se encuentran en la hoja fuente./*ww  w  . ja  v a 2  s  .  c o  m*/
 * 
 * @param sheet
 *          Intancia que modela la hoja objetivo o la hoja que se desea trabajar.
 * 
 * @param source
 *          Instancia que modela la hoja que contiene todos los productos.
 * 
 * @param start 
 *          Indica la posicion de la primer fila donde se encuentran los productos en
 *          la hoja fuente.
 */
private void writeProducts(Sheet sheet, Sheet source, int start) {
    AtomicInteger rowIndex = new AtomicInteger(3);

    final CreationHelper helper = sheet.getWorkbook().getCreationHelper();

    Stream<Row> rows = getRows(source, start).stream().filter((Row r) -> {
        Cell type = r.getCell(2);

        return type != null && type.getRichStringCellValue().getString().equals("Prds.");
    });

    if (rows != null) {
        rows.forEach(r -> {
            String product = r.getCell(6).getRichStringCellValue().getString()
                    .replaceFirst("\\[[0-9]+/[0-9]+\\]", "");

            int numbeerOfSubNodes = getNumberOfSubNodes(source, r.getRowNum(), "Packs", "Prds.");

            for (int subNodes = 0; subNodes < numbeerOfSubNodes; subNodes++) {
                Row row = sheet.getRow(rowIndex.getAndIncrement());

                if (row != null) {
                    Cell cellProductSubNode = row.createCell(5);

                    cellProductSubNode.setCellType(Cell.CELL_TYPE_STRING);
                    cellProductSubNode.setCellValue(helper.createRichTextString(product));

                    cellProductSubNode = null;
                    row = null;
                }
            }
        });
    }
}

From source file:das.pf.io.IOExcel.java

License:Open Source License

/**
 * Este metodo se encarga de escribir los datos correspondientes a los Key Competitors
 * /*from   w w  w  .  jav a  2s. co  m*/
 * @param sheet
 *          Instancia que modela la hoja en la que se va a trabajar.
 * 
 * @param startRow
 *          Indica el indice de la primer fila en la que se trabajara.
 * 
 *  @param endRow
 *          Indica el indice para la ultima fila que se desea escribir.
 * 
 * @param indexColumSource
 *          Indica el indice de la celda donde se tomara como parametro los datos
 * 
 * @param indexColumnProduct 
 *          Indica el indice de la celda donde estan los productos.
 */
private void writeKeyCompetitors(Sheet sheet, int startRow, int endRow, int indexColumSource,
        int indexColumnProduct) {
    CreationHelper helper = sheet.getWorkbook().getCreationHelper();
    int index = 6;

    for (int indexRow = startRow; indexRow < (endRow + startRow); indexRow++) {
        Row row = sheet.getRow(indexRow);

        if (row != null) {
            Cell cellKeyCompetitor = row.createCell(index);
            Cell cellSource = row.getCell(indexColumSource);

            if (cellSource != null) {
                cellKeyCompetitor.setCellType(Cell.CELL_TYPE_STRING);

                if (cellSource.getRichStringCellValue().getString().trim().equals("Generico"))
                    cellKeyCompetitor.setCellValue(helper.createRichTextString("Genricos"));
                else {
                    Cell cellProduct = row.getCell(indexColumnProduct);

                    if (cellProduct != null)
                        cellKeyCompetitor.setCellValue(cellProduct.getRichStringCellValue().getString());
                }
            }

            cellKeyCompetitor = null;
            cellSource = null;
        }

        row = null;
    }
}

From source file:das.pf.io.IOExcel.java

License:Open Source License

private XmlContry writeContries(Sheet sheet, int startRow, int column, Path pathFile) {
    CreationHelper helper = sheet.getWorkbook().getCreationHelper();

    XmlContry contry = Util.getContryByAcronym(getAcromynName(pathFile));

    if (contry != null) {
        try {/* w w  w  .  j av  a2  s .co  m*/
            for (int index = startRow; index < sheet.getLastRowNum() + 1; index++) {
                Row row = sheet.getRow(index);

                if (row != null) {
                    Cell cellContry = row.createCell(column);

                    cellContry.setCellType(Cell.CELL_TYPE_STRING);
                    cellContry.setCellValue(helper.createRichTextString(contry.getName()));

                    updateMessages(String.format("Escribiendo el pais: %s en la fila: %d", contry.getName(),
                            index + 1));
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Error al escribir la columna Pais", ex);

            Util.showException("Error al escribir la columna Pais", ex);
        }
    }

    return contry;
}

From source file:das.pf.io.IOExcel.java

License:Open Source License

private void writeRegions(XmlContry contry, Sheet sheet, int startRow, int column) {
    CreationHelper helper = sheet.getWorkbook().getCreationHelper();
    XmlRegion region = Util.getRegionByContry(contry);

    if (region != null) {
        for (int index = startRow; index < sheet.getLastRowNum() + 1; index++) {
            Row r = sheet.getRow(index);

            try {
                if (r != null) {
                    Cell cellRegion = r.createCell(column);

                    cellRegion.setCellType(Cell.CELL_TYPE_STRING);
                    cellRegion.setCellValue(helper.createRichTextString(region.getName()));

                    updateMessages(String.format("Escribiendo la region: %s en la fila: %d", region.getName(),
                            r.getRowNum() + 1));
                }/* w  ww.  j av a2s .  com*/
            } catch (Exception ex) {
                Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Error al escribir la columna Region",
                        ex);

                Util.showException("Error al escribir la columna Region", ex);
            }
        }
    }
}

From source file:Data.Database.java

public void dumpExcel() throws FileNotFoundException, IOException {
    //Workbook wb = new HSSFWorkbook();
    Workbook wb = new XSSFWorkbook();
    CreationHelper createHelper = wb.getCreationHelper();
    Sheet sheet = wb.createSheet("leaguedata");

    // set headers on excel sheet
    Row row = sheet.createRow((short) 0);
    String headers[] = new String[] { "Team", "Player", "Position", "Age", "Yrs Played", "GP", "G", "A", "PTS",
            "+/-", "STP", "SOG", "SH%", "Hits", "Blocks", "TOI", "G/60", "A/60", "PTS/60", "STP/60", "SOG/60",
            "Hits/60", "Blocks/60" };

    for (int i = 0; i < headers.length; i++) {
        Cell cell = row.createCell(i);//from ww  w . j  a  va  2s  .co  m
        cell.setCellValue(createHelper.createRichTextString(headers[i]));
        CellStyle cellStyle = wb.createCellStyle();
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        cell.setCellStyle(cellStyle);
    }

    // add player data
    int track = 2;

    //        // dump ALL players!!!!!
    //        for (Map.Entry<String, Player> entry : players.entrySet()){
    //            Row newrow = sheet.createRow((short)track);
    //            entry.getValue().dumpExcel(newrow, "null");
    //            track++;
    //        }
    //        
    //                // Write the output to a file
    //        FileOutputStream fileOut = new FileOutputStream("RFHL_allplayers.xlsx");
    //        wb.write(fileOut);
    //        fileOut.close();

    // dump fantasy teams!!!
    for (int i = 0; i < fh_teams.size(); i++) {
        track = fh_teams.get(i).dumpExcel(sheet, track);
        track++;
    }

    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("RFHL.xlsx");
    wb.write(fileOut);
    fileOut.close();

}