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:ch.javasoft.metabolic.generate.ExcelGenerator.java

License:BSD License

public ExcelGenerator(MetabolicNetwork net) {
    this.net = net;
    workbook = new HSSFWorkbook();
    styleBoldItalic = getCellStyle(HSSFFont.BOLDWEIGHT_BOLD, true);
    initMetabolites();/*w  ww.ja v  a 2  s  .  c  o  m*/
    initReactions();
}

From source file:cn.edu.zucc.chenxg.preview.ToHtml.java

License:Apache License

private void fontStyle(CellStyle style) {
    Font font = wb.getFontAt(style.getFontIndex());

    if (font.getBoldweight() >= HSSFFont.BOLDWEIGHT_BOLD)
        out.format("  font-weight: bold;%n");
    if (font.getItalic())
        out.format("  font-style: italic;%n");

    int fontheight = font.getFontHeightInPoints();
    if (fontheight == 9) {
        //fix for stupid ol Windows
        fontheight = 10;/*from   w  w w .j  av  a 2 s. com*/
    }
    out.format("  font-size: %dpt;%n", fontheight);

    // Font color is handled with the other colors
}

From source file:cn.mario256.blog.ExcelView.java

License:Open Source License

/**
 * ?Excel//from w w  w .  j  a v a2  s . c  o  m
 * 
 * @param model
 *            ?
 * @param workbook
 *            HSSFWorkbook
 * @param request
 *            HttpServletRequest
 * @param response
 *            HttpServletResponse
 */
public void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Assert.notEmpty(properties);

    HSSFSheet sheet;
    if (StringUtils.isNotEmpty(sheetName)) {
        sheet = workbook.createSheet(sheetName);
    } else {
        sheet = workbook.createSheet();
    }
    int rowNumber = 0;
    if (titles != null && titles.length > 0) {
        HSSFRow header = sheet.createRow(rowNumber);
        header.setHeight((short) 400);
        for (int i = 0; i < properties.length; i++) {
            HSSFCell cell = header.createCell(i);
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
            cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            HSSFFont font = workbook.createFont();
            font.setFontHeightInPoints((short) 11);
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            cellStyle.setFont(font);
            cell.setCellStyle(cellStyle);
            if (i == 0) {
                HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
                HSSFComment comment = patriarch
                        .createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 4, 4));
                comment.setString(new HSSFRichTextString("P" + "o" + "w" + "e" + "r" + "e" + "d" + " " + "B"
                        + "y" + " " + "S" + "H" + "O" + "P" + "+" + "+"));
                cell.setCellComment(comment);
            }
            if (titles.length > i && titles[i] != null) {
                cell.setCellValue(titles[i]);
            } else {
                cell.setCellValue(properties[i]);
            }
            if (widths != null && widths.length > i && widths[i] != null) {
                sheet.setColumnWidth(i, widths[i]);
            } else {
                sheet.autoSizeColumn(i);
            }
        }
        rowNumber++;
    }
    if (data != null) {
        for (Object item : data) {
            HSSFRow row = sheet.createRow(rowNumber);
            for (int i = 0; i < properties.length; i++) {
                HSSFCell cell = row.createCell(i);
                if (converters != null && converters.length > i && converters[i] != null) {
                    Class<?> clazz = PropertyUtils.getPropertyType(item, properties[i]);
                    ConvertUtils.register(converters[i], clazz);
                    cell.setCellValue(BeanUtils.getProperty(item, properties[i]));
                    ConvertUtils.deregister(clazz);
                    if (clazz.equals(Date.class)) {
                        DateConverter dateConverter = new DateConverter();
                        dateConverter.setPattern(DEFAULT_DATE_PATTERN);
                        ConvertUtils.register(dateConverter, Date.class);
                    }
                } else {
                    cell.setCellValue(BeanUtils.getProperty(item, properties[i]));
                }
                if (rowNumber == 0 || rowNumber == 1) {
                    if (widths != null && widths.length > i && widths[i] != null) {
                        sheet.setColumnWidth(i, widths[i]);
                    } else {
                        sheet.autoSizeColumn(i);
                    }
                }
            }
            rowNumber++;
        }
    }
    if (contents != null && contents.length > 0) {
        rowNumber++;
        for (String content : contents) {
            HSSFRow row = sheet.createRow(rowNumber);
            HSSFCell cell = row.createCell(0);
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            HSSFFont font = workbook.createFont();
            font.setColor(HSSFColor.GREY_50_PERCENT.index);
            cellStyle.setFont(font);
            cell.setCellStyle(cellStyle);
            cell.setCellValue(content);
            rowNumber++;
        }
    }
    response.setContentType("application/force-download");
    if (StringUtils.isNotEmpty(filename)) {
        response.setHeader("Content-disposition",
                "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
    } else {
        response.setHeader("Content-disposition", "attachment");
    }
}

From source file:co.turnus.analysis.data.bottlenecks.io.XlsAlgoBottlenecksDataWriter.java

License:Open Source License

public void write(AlgoBottlenecksData report, File file) {
    try {//from  ww  w .ja  va 2  s.com
        HSSFWorkbook workbook = new HSSFWorkbook();

        titleFont = workbook.createFont();
        titleFont.setFontName("Arial");
        titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"));

        HotspotsDataAnalyser analyzer = new HotspotsDataAnalyser(report);
        writeSummary(workbook, report.getNetwork(), analyzer);
        writeActorClassesTable(workbook, analyzer);
        writeActorsTable(workbook, analyzer);
        writeActionActorClassTable(workbook, analyzer);
        writeActionActorTable(workbook, analyzer);

        // check if there are also impact analysis data
        ImpactData impactData = report.getImpactData();
        if (impactData != null) {
            writeImpactAnalysis(workbook, impactData);
        }

        OutputStream out = new FileOutputStream(file);
        out = new BufferedOutputStream(out);
        workbook.write(out);
        out.close();
    } catch (Exception e) {
        throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause());
    }

}

From source file:co.turnus.analysis.data.buffers.io.XlsBufferMinimizationDataWriter.java

License:Open Source License

public void write(BufferMinimizationData report, File file) {
    try {/*  w ww . j a  va 2  s. c o m*/
        HSSFWorkbook workbook = new HSSFWorkbook();

        titleFont = workbook.createFont();
        titleFont.setFontName("Arial");
        titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        int solutionId = 1;
        for (BuffersData data : report.getBuffersData()) {
            writeData(workbook, data, report.getNetwork(), report.getAlgorithm(), solutionId++);
        }

        OutputStream out = new FileOutputStream(file);
        out = new BufferedOutputStream(out);
        workbook.write(out);
        out.close();
    } catch (Exception e) {
        throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause());
    }
}

From source file:co.turnus.analysis.data.partitioning.io.XlsPartitioningDataWriter.java

License:Open Source License

public void write(PartitioningData report, File file) {
    try {// w w w.j av a  2  s.c o m
        HSSFWorkbook workbook = new HSSFWorkbook();

        titleFont = workbook.createFont();
        titleFont.setFontName("Arial");
        titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        int solutionId = 1;
        for (PartitionsData data : report.getPartitionsData()) {
            writeData(workbook, data, report.getNetwork(), report.getAlgorithm(), solutionId++);
        }

        OutputStream out = new FileOutputStream(file);
        out = new BufferedOutputStream(out);
        workbook.write(out);
        out.close();
    } catch (Exception e) {
        throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause());
    }

}

From source file:co.turnus.analysis.data.pipelining.io.XlsSimplePipeliningDataWriter.java

License:Open Source License

public void write(SimplePipelingData report, File file) {
    try {/*from  w w  w.  j a v  a2 s  .  com*/

        HSSFWorkbook workbook = new HSSFWorkbook();

        titleFont = workbook.createFont();
        titleFont.setFontName("Arial");
        titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"));

        HSSFSheet sheet = workbook.createSheet("Pipelinable <Actor, Action>");
        // Action Actor Class Results
        Cell cell = sheet.createRow(0).createCell(0);
        HSSFRichTextString title = new HSSFRichTextString("Action and Actor Pipelining Results");
        title.applyFont(titleFont);
        cell.setCellValue(title);

        Row row = sheet.createRow(1);
        sheet.addMergedRegion(new CellRangeAddress(1, 3, 0, 0));
        row.createCell(0).setCellValue("Actor");
        sheet.addMergedRegion(new CellRangeAddress(1, 3, 1, 1));
        row.createCell(1).setCellValue("Action");
        sheet.addMergedRegion(new CellRangeAddress(1, 3, 2, 2));
        row.createCell(2).setCellValue("pipelinable");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 3, 10));
        row.createCell(3).setCellValue("Consecutive Executions");
        sheet.addMergedRegion(new CellRangeAddress(1, 3, 11, 11));
        row.createCell(11).setCellValue("Splittable Actions");

        row = sheet.createRow(2);
        sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 6));
        row.createCell(3).setCellValue("Pipelinable");
        sheet.addMergedRegion(new CellRangeAddress(2, 2, 7, 10));
        row.createCell(7).setCellValue("Unconstrained");
        row = sheet.createRow(3);
        row.createCell(3).setCellValue("min");
        row.createCell(4).setCellValue("mean");
        row.createCell(5).setCellValue("max");
        row.createCell(6).setCellValue("var");
        row.createCell(7).setCellValue("min");
        row.createCell(8).setCellValue("mean");
        row.createCell(9).setCellValue("max");
        row.createCell(10).setCellValue("var");

        int rowId = 4;
        Map<Actor, Map<Action, SimpleActionPipeliningData>> table = report.asTable().rowMap();
        for (Map<Action, SimpleActionPipeliningData> ac : table.values()) {
            for (SimpleActionPipeliningData data : ac.values()) {
                row = sheet.createRow(rowId);
                row.createCell(0).setCellValue(data.getActor().getId());
                row.createCell(1).setCellValue(data.getAction().getId());

                row.createCell(2).setCellValue(data.isPipelinable());

                StatisticalData stat = data.getPipelinableRepetitions();
                if (stat.getSamples() > 0) {
                    row.createCell(3).setCellValue(stat.getMin());
                    row.createCell(4).setCellValue(stat.getMean());
                    row.createCell(5).setCellValue(stat.getMax());
                    row.createCell(6).setCellValue(stat.getVariance());
                } else {
                    row.createCell(3).setCellValue("-");
                    row.createCell(4).setCellValue("-");
                    row.createCell(5).setCellValue("-");
                    row.createCell(6).setCellValue("-");
                }

                stat = data.getUnconstrainedRepetitions();
                if (stat.getSamples() > 0) {
                    row.createCell(7).setCellValue(stat.getMin());
                    row.createCell(8).setCellValue(stat.getMean());
                    row.createCell(9).setCellValue(stat.getMax());
                    row.createCell(10).setCellValue(stat.getVariance());
                } else {
                    row.createCell(7).setCellValue("-");
                    row.createCell(8).setCellValue("-");
                    row.createCell(9).setCellValue("-");
                    row.createCell(10).setCellValue("-");
                }

                StringBuffer b = new StringBuffer();
                for (Action action : data.getSplittableActions()) {
                    b.append(action.getId()).append(" ");
                }
                row.createCell(11).setCellValue(b.toString());

                rowId++;
            }
        }

        OutputStream out = new FileOutputStream(file);
        out = new BufferedOutputStream(out);
        workbook.write(out);
        out.close();

    } catch (Exception e) {
        throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause());
    }
}

From source file:co.turnus.profiling.io.XlsHalsteadAnalysisWriter.java

License:Open Source License

public void write(SourceCodeData report, File file) {
    try {/*from  www  .  j  a v  a2s.  c om*/
        HSSFWorkbook workbook = new HSSFWorkbook();

        titleFont = workbook.createFont();
        titleFont.setFontName("Arial");
        titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"));

        writeSummary(workbook, report.getNetwork(), report);
        writeActorClassesTable(workbook, report);

        OutputStream out = new FileOutputStream(file);
        out = new BufferedOutputStream(out);
        workbook.write(out);
        out.close();
    } catch (Exception e) {
        throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause());
    }

}

From source file:co.turnus.profiling.io.XlsProfilingDataWriter.java

License:Open Source License

public void write(File file, ProfilingData data) {
    try {/*from w  w w. j  av  a  2s .c  o m*/
        HSSFWorkbook workbook = new HSSFWorkbook();

        titleFont = workbook.createFont();
        titleFont.setFontName("Arial");
        titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"));

        // writeSummary(workbook, data.getNetwork(), data);
        writeFifosData(workbook, data);

        OutputStream out = new FileOutputStream(file);
        out = new BufferedOutputStream(out);
        workbook.write(out);
        out.close();
    } catch (Exception e) {
        throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause());
    }
}

From source file:com.abacus.reports.ExcelBuilder.java

@Override
protected void buildExcelDocument(Map<String, Object> map, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // get data model which is passed by the Spring container
    List headerlist = (List) map.get("header");
    List<Object[]> data = (List) map.get("data");
    String reportname = String.valueOf(map.get("report_name"));

    // create a new Excel sheet
    HSSFSheet sheet = workbook.createSheet(reportname);
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition", "attachment; filename=" + reportname + ".xls");
    OutputStream outStream = response.getOutputStream();
    sheet.setDefaultColumnWidth(30);/*from   w  w w.ja v  a 2s. com*/

    // create style for header cells
    CellStyle style = workbook.createCellStyle();
    HSSFFont font = workbook.createFont();
    HSSFPalette palette = workbook.getCustomPalette();
    HSSFColor color = palette.findSimilarColor(152, 35, 17);
    short paindex = color.getIndex();
    font.setFontName("Trebuchet MS");
    style.setFillForegroundColor(paindex);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(HSSFColor.WHITE.index);
    style.setFont(font);

    // create header row
    HSSFRow header = sheet.createRow(0);
    int row = 0;
    for (Object headerlist1 : headerlist) {

        header.createCell(row).setCellValue(String.valueOf(headerlist1));
        header.getCell(row).setCellStyle(style);
        row++;
    }

    CellStyle style2 = workbook.createCellStyle();
    HSSFFont font2 = workbook.createFont();
    font2.setFontName("Trebuchet MS");
    style2.setFont(font2);

    System.out.println("data.size(): " + data.size());
    int rownum = 1;
    // create data rows         
    for (int rowCount = 0; rowCount < data.size(); rowCount++) {
        HSSFRow aRow = sheet.createRow(rownum);
        Object[] value = data.get(rowCount);
        int col = 0;
        for (Object value1 : value) {
            HSSFCell cell = aRow.createCell(col++);
            cell.setCellStyle(style2);
            if (value1 instanceof java.lang.String)
                cell.setCellValue(String.valueOf(value1));
            if (value1 instanceof java.lang.Integer)
                cell.setCellValue(Integer.parseInt(String.valueOf(value1)));
            if (value1 instanceof java.lang.Boolean)
                cell.setCellValue(Integer.parseInt(String.valueOf(value1)));
            if (value1 instanceof java.lang.Double)
                cell.setCellValue(Double.parseDouble(String.valueOf(value1)));
            if (value1 instanceof java.lang.Float)
                cell.setCellValue(Float.parseFloat(String.valueOf(value1)));
        }
        rownum++;
    }
    workbook.write(outStream);
    outStream.close();
}