Example usage for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD

List of usage examples for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD.

Prototype

short BOLDWEIGHT_BOLD

To view the source code for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD.

Click Source Link

Document

Bold boldness (bold)

Usage

From source file:com.vportal.portlet.vdoc.service.util.ReportUtil.java

License:Open Source License

public static void createCellBold(HSSFRow row, short column, String value, HSSFWorkbook wb) {

    HSSFCellStyle style = wb.createCellStyle();
    HSSFFont font = wb.createFont();/*from ww w. j a  v a2 s. co  m*/
    font.setColor((short) 0xc);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    style.setFont(font);
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    style.setBorderBottom(HSSFCellStyle.SOLID_FOREGROUND);
    style.setBorderLeft(HSSFCellStyle.SOLID_FOREGROUND);
    style.setBorderRight(HSSFCellStyle.SOLID_FOREGROUND);
    style.setBorderTop(HSSFCellStyle.SOLID_FOREGROUND);

    HSSFCell cell = row.getCell(column);
    if (cell == null)
        cell = row.createCell(column);
    //cell.setEncoding(wb.ENCODING_UTF_16);
    cell.setCellValue(value);
    cell.setCellStyle(style);
}

From source file:com.zrx.authority.util.ObjectExcelView.java

@Override
protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // TODO Auto-generated method stub
    Date date = new Date();
    String filename = Tools.date2Str(date, "yyyyMMddHHmmss");
    HSSFSheet sheet;//from w  w w.  ja  va  2  s  .c o m
    HSSFCell cell;
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
    sheet = workbook.createSheet("sheet1");

    List<String> titles = (List<String>) model.get("titles");
    int len = titles.size();
    HSSFCellStyle headerStyle = workbook.createCellStyle(); //?
    headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    HSSFFont headerFont = workbook.createFont(); //
    headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    headerFont.setFontHeightInPoints((short) 11);
    headerStyle.setFont(headerFont);
    short width = 20, height = 25 * 20;
    sheet.setDefaultColumnWidth(width);
    for (int i = 0; i < len; i++) { //
        String title = titles.get(i);
        cell = getCell(sheet, 0, i);
        cell.setCellStyle(headerStyle);
        setText(cell, title);
    }
    sheet.getRow(0).setHeight(height);

    HSSFCellStyle contentStyle = workbook.createCellStyle(); //?
    contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    List<PageData> varList = (List<PageData>) model.get("varList");
    int varCount = varList.size();
    for (int i = 0; i < varCount; i++) {
        PageData vpd = varList.get(i);
        for (int j = 0; j < len; j++) {
            String varstr = vpd.getString("var" + (j + 1)) != null ? vpd.getString("var" + (j + 1)) : "";
            cell = getCell(sheet, i + 1, j);
            cell.setCellStyle(contentStyle);
            setText(cell, varstr);
        }

    }

}

From source file:Controlador.ControladorCargueMasivo.java

public static HSSFWorkbook obtenerExcel(DataModel contenidoCeldas, DataModel cabecerasCeldas,
        String nombreHoja) {// w  w w  .  j ava 2 s . com

    HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
    HSSFSheet hssfSheet = hssfWorkbook.createSheet(nombreHoja);
    int numeroFila = 0;
    int numeroColumna = 0;
    HSSFRow hssfRow = hssfSheet.createRow(numeroFila++);
    HSSFCellStyle hssfCellStyleCabecera = hssfWorkbook.createCellStyle();
    hssfCellStyleCabecera.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    hssfCellStyleCabecera.setFillBackgroundColor(new HSSFColor.BLACK().getIndex());
    HSSFFont hssfFont = hssfWorkbook.createFont();
    hssfFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    hssfFont.setColor(HSSFColor.WHITE.index);
    hssfCellStyleCabecera.setFont(hssfFont);
    String columnaCabecera;
    HSSFCell hssfCell = null;
    List cabecerasExcel = (List) cabecerasCeldas.getWrappedData();
    for (int i = 0; i < cabecerasExcel.size(); i++) {
        columnaCabecera = (String) cabecerasExcel.get(i);
        hssfCell = hssfRow.createCell((short) numeroColumna++);
        hssfCell.setCellValue(columnaCabecera);
        hssfCell.setCellStyle(hssfCellStyleCabecera);
    }
    List contenidoExcel = (List) contenidoCeldas.getWrappedData();
    List fila = null;
    Object valor;
    for (int i = 0; i < contenidoExcel.size(); i++) {
        fila = (List) contenidoExcel.get(i);
        hssfRow = hssfSheet.createRow(numeroFila++);
        numeroColumna = 0;
        for (int x = 0; x < fila.size(); x++) {
            valor = fila.get(x);
            hssfCell = hssfRow.createCell((short) numeroColumna++);
            hssfCell.setCellValue((String) valor);
        }
    }
    return hssfWorkbook;
}

From source file:corner.orm.tapestry.service.excel.ExcelService.java

License:Apache License

/**
 * ?titleStyle/*w  w w.j  a va 2s.  c o  m*/
 * 
 * @return
 */
protected HSSFCellStyle getTitleStyle(HSSFWorkbook wb) {
    // create title Style
    HSSFCellStyle titleRowStyle = wb.createCellStyle();
    titleRowStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    HSSFFont titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 12);
    titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    titleRowStyle.setFont(titleFont);
    return titleRowStyle;
}

From source file:dao.ExportacaoParaExcel.java

public void Exportar(String nomeArquivo, Date dataInicial, Date dataFinal, FiltroData filtroData) {

    try {//from w w  w. j  a va2  s . com
        FileOutputStream arquivo = new FileOutputStream(new File(nomeArquivo));

        //controla linha posicionada
        int linha = 0;

        HSSFCellStyle style = this.workbook.createCellStyle();
        HSSFFont font = this.workbook.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        style.setFont(font);

        HSSFRow row = firstSheet.createRow(linha);

        this.AdicionaLinha(row, 0, "Data Inicial: ");
        this.AdicionaLinha(row, 1, new SimpleDateFormat("dd-MM-yyyy").format(dataInicial));

        this.AdicionaLinha(row, 3, "Data Final: ");
        this.AdicionaLinha(row, 4, new SimpleDateFormat("dd-MM-yyyy").format(dataFinal));

        linha += 1;
        row = firstSheet.createRow(linha);

        int coluna = 2;

        this.linhaCabecalho = linha;

        //futuramente pode ser continuada a implementacao das diferentes formas de visualizao
        //            switch (filtroData) {
        //
        //                case Diario:
        //                    this.ExportacaoDiariaNova(dataInicial, dataFinal, row, linha);
        //                    break;
        //
        //                case Mensal:
        ArrayList<String> colunasExcel = RetornaColunas(filtroData, dataInicial, dataFinal);

        for (String item : colunasExcel) {

            this.AdicionaLinhaBold(row, style, coluna, item);

            coluna += 1;

        }

        this.ExportacaoMensal(dataInicial, dataFinal, row, style, linha);

        //                    break;
        //
        //            }
        this.workbook.write(arquivo);
        arquivo.close();

        utils.Utils.notificacao("Exportao concluda com sucesso", Utils.TipoNotificacao.ok, 0);

    } catch (Exception ex) {
        utils.Utils.notificacao("No foi possvel gerar o arquivo de exportao",
                Utils.TipoNotificacao.erro, 0);
        Utils.log("Falha ao gerar relatrio Excel", ex.toString(), LogTipo.ERRO);

    }

}

From source file:dbedit.actions.ExportExcelAction.java

License:Open Source License

@Override
protected void performThreaded(ActionEvent e) throws Exception {
    boolean selection = false;
    JTable table = ResultSetTable.getInstance();
    if (table.getSelectedRowCount() > 0 && table.getSelectedRowCount() != table.getRowCount()) {
        Object option = Dialog.show("Excel", "Export", Dialog.QUESTION_MESSAGE,
                new Object[] { "Everything", "Selection" }, "Everything");
        if (option == null || "-1".equals(option.toString())) {
            return;
        }/*w  w w .ja  v a2  s.c om*/
        selection = "Selection".equals(option);
    }
    List list = ((DefaultTableModel) table.getModel()).getDataVector();
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet();
    HSSFRow row = sheet.createRow(0);
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    HSSFFont font = workbook.createFont();
    font.setColor(HSSFColor.WHITE.index);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    style.setFont(font);
    for (int i = 0; i < table.getColumnCount(); i++) {
        HSSFCell cell = row.createCell(i);
        cell.setCellValue(new HSSFRichTextString(table.getColumnName(i)));
        cell.setCellStyle(style);
        sheet.setColumnWidth(i, (table.getColumnModel().getColumn(i).getPreferredWidth() * 45));
    }
    int count = 1;
    for (int i = 0; i < list.size(); i++) {
        if (!selection || table.isRowSelected(i)) {
            List data = (List) list.get(i);
            row = sheet.createRow(count++);
            for (int j = 0; j < data.size(); j++) {
                Object o = data.get(j);
                HSSFCell cell = row.createCell(j);
                if (o instanceof Number) {
                    cell.setCellValue(((Number) o).doubleValue());
                } else if (o != null) {
                    if (ResultSetTable.isLob(j)) {
                        cell.setCellValue(
                                new HSSFRichTextString(Context.getInstance().getColumnTypeNames()[j]));
                    } else {
                        cell.setCellValue(new HSSFRichTextString(o.toString()));
                    }
                }
            }
        }
    }
    sheet.createFreezePane(0, 1);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    workbook.write(byteArrayOutputStream);
    FileIO.saveAndOpenFile("export.xls", byteArrayOutputStream.toByteArray());
}

From source file:de.bund.bfr.knime.openkrise.db.exports.ExcelExport.java

License:Open Source License

public void doExport(final String filename, final MyDBTable myDB, final JProgressBar progress,
        final boolean exportFulltext, final String zeilen2Do) {
    //filename = "C:/Users/Armin/Documents/private/freelance/BfR/Data/100716/Matrices_BLS-Liste.xls";
    Runnable runnable = new Runnable() {
        public void run() {
            try (HSSFWorkbook wb = new HSSFWorkbook()) {
                if (progress != null) {
                    progress.setVisible(true);
                    progress.setStringPainted(true);
                    progress.setString("Exporting Excel File...");
                    progress.setMinimum(0);
                    progress.setMaximum(myDB.getRowCount());
                    progress.setValue(0);
                }//from   w  ww .j a  va  2s . c  om

                HSSFSheet sheet = wb.createSheet(myDB.getActualTable().getTablename());
                // Create Titel
                cs = wb.createCellStyle();
                cs.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                cs.setFont(font);
                HSSFRow row0 = sheet.createRow(0);
                //row0.setRowStyle(cs);
                colLfd = 0;
                for (int j = 0; j < myDB.getColumnCount(); j++) {
                    if (myDB.getColumn(j).isVisible()) {
                        HSSFCell cell = row0.createCell(colLfd);
                        colLfd++;
                        cell.setCellValue(myDB.getColumn(j).getColumnName());
                        cell.setCellStyle(cs);
                    }
                }
                //String[] mnTable = myDB.getActualTable().getMNTable();
                MyTable[] myFs = myDB.getActualTable().getForeignFields();
                for (int i = 1; i <= myDB.getRowCount(); i++) {
                    if (progress != null)
                        progress.setValue(i);
                    //System.out.println(myDB.getValueAt(i, 0) + "_" + myDB.isVisible());
                    HSSFRow rowi = sheet.createRow(i);
                    for (int j = 0; j < myDB.getColumnCount(); j++) {
                        Object res = null;
                        if (j > 0 && myFs != null && myFs.length > j - 1 && myFs[j - 1] != null
                                && myFs[j - 1].getTablename().equals("DoubleKennzahlen")) {
                            //if (j > 0 && mnTable != null && j-1 < mnTable.length && mnTable[j - 1] != null && mnTable[j - 1].equals("DBL")) {
                            getDblVal(myDB, i - 1, j, row0, rowi);
                            /*
                            getDblVal(myDB, i-1, j, "Einzelwert", row0, rowi);
                            getDblVal(myDB, i-1, j, "Wiederholungen", row0, rowi);
                            getDblVal(myDB, i-1, j, "Mittelwert", row0, rowi);
                            getDblVal(myDB, i-1, j, "Median", row0, rowi);
                            getDblVal(myDB, i-1, j, "Minimum", row0, rowi);
                            getDblVal(myDB, i-1, j, "Maximum", row0, rowi);
                            getDblVal(myDB, i-1, j, "Standardabweichung", row0, rowi);
                            getDblVal(myDB, i-1, j, "LCL95", row0, rowi);
                            getDblVal(myDB, i-1, j, "UCL95", row0, rowi);
                            getDblVal(myDB, i-1, j, "Verteilung", row0, rowi);
                            getDblVal(myDB, i-1, j, "Funktion (Zeit)", row0, rowi);
                            getDblVal(myDB, i-1, j, "Funktion (?)", row0, rowi);
                            getDblVal(myDB, i-1, j, "Undefiniert (n.d.)", row0, rowi);
                            */
                        } else {
                            if (exportFulltext) {
                                res = myDB.getVisibleCellContent(i - 1, j);
                            } else {
                                res = myDB.getValueAt(i - 1, j);
                            }
                            //MyLogger.handleMessage(res);
                            if (res != null)
                                rowi.createCell(j).setCellValue(res.toString());
                            else
                                rowi.createCell(j);
                        }
                    }
                }

                try {
                    FileOutputStream fileOut = new FileOutputStream(filename);
                    wb.write(fileOut);
                    fileOut.close();
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(progress, e.getMessage(), "Export Problem",
                            JOptionPane.OK_OPTION);
                }

                if (progress != null) {
                    progress.setValue(myDB.getRowCount());
                    progress.setVisible(false);
                }
            } catch (Exception e) {
                MyLogger.handleException(e);
            }
        }
    };

    Thread thread = new Thread(runnable);
    thread.start();
}

From source file:de.jwic.ecolib.tableviewer.export.ExcelExportControl.java

License:Apache License

private HSSFWorkbook createWorkBook() {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Sheet");
    HSSFRow row = sheet.createRow(0);//from   w  w w .j a  v a2 s  .c om

    // Style for title cells
    HSSFFont font = wb.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(HSSFColor.BLUE.index);

    HSSFCellStyle styleTitle = wb.createCellStyle();
    styleTitle.setFont(font);

    // Style for data date cells
    font = wb.createFont();
    HSSFCellStyle styleDate = wb.createCellStyle();
    styleDate.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));

    short col = 0;
    TableModel model = tableViewer.getModel();
    Iterator<TableColumn> it = model.getColumnIterator();

    // create title in the sheet
    while (it.hasNext()) {
        TableColumn column = it.next();
        if (!isColumnVisible(column)) {
            continue;
        }
        sheet.setColumnWidth(col, (short) (column.getWidth() * 40));
        HSSFCell cell = row.createCell(col++);
        cell.setCellValue(column.getTitle());
        cell.setCellStyle(styleTitle);
    }

    // add the datas from the table viewer
    IContentProvider<?> contentProvider = model.getContentProvider();
    Iterator<?> iter = contentProvider.getContentIterator(new Range());

    try {
        renderRows(iter, 0, model, sheet, styleDate);
    } catch (Throwable t) {
        log.error("Error rendering rows", t);
    }

    return wb;
}

From source file:devcup.search4u.xlsview.ConvertResultsToXLS.java

public void createXLSTable() throws IOException {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Result sheet");

    //create headerRow
    Row headerRow = sheet.createRow(0);/* ww  w .j a va2s .c  om*/

    HSSFCellStyle headerStyle = workbook.createCellStyle();
    HSSFCellStyle style = workbook.createCellStyle();

    HSSFFont partFont = workbook.createFont();
    //partFont.setItalic(true);
    partFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    partFont.setUnderline(HSSFFont.U_DOUBLE);

    HSSFFont defaultFont = workbook.createFont();
    defaultFont.setFontHeightInPoints((short) 10);
    defaultFont.setFontName("Arial");
    defaultFont.setColor(HSSFColor.BLACK.index);
    defaultFont.setItalic(false);

    HSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 11);
    font.setFontName("Arial");
    font.setColor(HSSFColor.BLUE_GREY.index);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setItalic(true);

    //style=(HSSFCellStyle) headerRow.getRowStyle();       
    //style.setFillPattern(CellStyle.SOLID_FOREGROUND);       
    headerStyle.setWrapText(true);
    headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
    //style.setFillBackgroundColor(HSSFColor.ROYAL_BLUE.index);
    //style.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index);
    //style.setHidden(false);
    //style.setIndention(indent);
    headerStyle.setFont(font);

    //create a new cell in headerRow
    Cell headerCell;
    headerCell = headerRow.createCell(0);
    headerCell.setCellValue("?");
    headerCell.setCellStyle(headerStyle);
    //sheet.autoSizeColumn(0);
    sheet.setColumnWidth(0, 7000);

    headerCell = headerRow.createCell(1);
    headerCell.setCellValue("  ");
    headerCell.setCellStyle(headerStyle);
    //sheet.autoSizeColumn(1);
    sheet.setColumnWidth(1, 12000);

    /*headerCell = headerRow.createCell(2);
    headerCell.setCellValue("?  ");
    headerCell.setCellStyle(style);
    sheet.autoSizeColumn(2);
    //sheet.setColumnWidth(2, 7000);
    */

    headerCell = headerRow.createCell(2);
    headerCell.setCellValue(" ?");
    headerCell.setCellStyle(headerStyle);
    //sheet.autoSizeColumn(3);
    sheet.setColumnWidth(2, 18000);

    style.setWrapText(true);
    style.setFont(defaultFont);

    //create another Rows
    int rowNum = 1;
    for (SearchResult searchResult : searchResultsList) {
        for (String key : searchResult.getRelevDocsPath()) {
            //for (String key : searchResult.getDocumentsFragments().keySet()) {
            for (ObjectPair<Integer, String> pair : searchResult.getDocumentsFragments().get(key)) {

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

                Cell cell;
                cell = row.createCell(0);
                cell.setCellValue(searchResult.getQuery());
                cell.setCellStyle(style);

                cell = row.createCell(1);
                cell.setCellValue(key);
                cell.setCellStyle(style);

                //cell = row.createCell(2);
                //cell.setCellValue(pair.getFirst());
                //cell.setCellStyle(style);

                cell = row.createCell(2);
                cell.setCellValue(labeledStringToRichTextString(pair.getSecond(), partFont));
                cell.setCellStyle(style);

            }
        }
    }

    try {
        FileOutputStream out = new FileOutputStream(new File(resultXMLPath));
        workbook.write(out);
        out.close();
        System.out.println("Excel written successfully..");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Documentos.ClaseAlmacenGeneral.java

private static void createTituloCell(HSSFWorkbook wb, Row row, int column, short halign, short valign,
        String strContenido) {//from w w  w.  ja va 2  s  . co m
    CreationHelper ch = wb.getCreationHelper();
    Cell cell = row.createCell(column);
    cell.setCellValue(ch.createRichTextString(strContenido));

    HSSFFont cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 11);
    cellFont.setFontName(HSSFFont.FONT_ARIAL);
    cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(valign);
    cellStyle.setFont(cellFont);
    cell.setCellStyle(cellStyle);

}