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

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

Introduction

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

Prototype


public void setUnderline(byte underline) 

Source Link

Document

set type of text underlining to use

Usage

From source file:net.sf.jasperreports.engine.export.JRXlsMetadataExporter.java

License:Open Source License

/**
 *
 *//*from  w  ww .  jav a  2s .  c  om*/
protected HSSFFont getLoadedFont(JRFont font, short forecolor, Map<Attribute, Object> attributes,
        Locale locale) {

    HSSFFont cellFont = null;
    String fontName = font.getFontName();
    FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(fontName, locale);
    if (fontInfo != null) {
        //fontName found in font extensions
        FontFamily family = fontInfo.getFontFamily();
        String exportFont = family.getExportFont(getExporterKey());
        if (exportFont != null) {
            fontName = exportFont;
        }
    }

    boolean isFontSizeFixEnabled = getCurrentItemConfiguration().isFontSizeFixEnabled();

    short superscriptType = HSSFFont.SS_NONE;

    if (attributes != null && attributes.get(TextAttribute.SUPERSCRIPT) != null) {
        Object value = attributes.get(TextAttribute.SUPERSCRIPT);
        if (TextAttribute.SUPERSCRIPT_SUPER.equals(value)) {
            superscriptType = HSSFFont.SS_SUPER;
        } else if (TextAttribute.SUPERSCRIPT_SUB.equals(value)) {
            superscriptType = HSSFFont.SS_SUB;
        }
    }
    for (int i = 0; i < loadedFonts.size(); i++) {
        HSSFFont cf = (HSSFFont) loadedFonts.get(i);
        short fontSize = (short) font.getFontsize();
        if (isFontSizeFixEnabled) {
            fontSize -= 1;
        }
        if (cf.getFontName().equals(fontName) && (cf.getColor() == forecolor)
                && (cf.getFontHeightInPoints() == fontSize)
                && ((cf.getUnderline() == HSSFFont.U_SINGLE) ? (font.isUnderline()) : (!font.isUnderline()))
                && (cf.getStrikeout() == font.isStrikeThrough())
                && ((cf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) ? (font.isBold()) : (!font.isBold()))
                && (cf.getItalic() == font.isItalic()) && (cf.getTypeOffset() == superscriptType)) {
            cellFont = cf;
            break;
        }
    }

    if (cellFont == null) {

        cellFont = workbook.createFont();
        cellFont.setFontName(fontName);
        cellFont.setColor(forecolor);
        short fontSize = (short) font.getFontsize();
        if (isFontSizeFixEnabled) {
            fontSize -= 1;
        }
        cellFont.setFontHeightInPoints(fontSize);

        if (font.isUnderline()) {
            cellFont.setUnderline(HSSFFont.U_SINGLE);
        }
        if (font.isStrikeThrough()) {
            cellFont.setStrikeout(true);
        }
        if (font.isBold()) {
            cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        }
        if (font.isItalic()) {
            cellFont.setItalic(true);
        }

        cellFont.setTypeOffset(superscriptType);
        loadedFonts.add(cellFont);
    }
    return cellFont;
}

From source file:opn.greenwebs.Hyperlinks.java

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

    //cell style for hyperlinks
    //by default hyperlinks are blue and underlined
    HSSFCellStyle hlink_style = wb.createCellStyle();
    HSSFFont hlink_font = wb.createFont();
    hlink_font.setUnderline(HSSFFont.U_SINGLE);
    hlink_font.setColor(HSSFColor.BLUE.index);
    hlink_style.setFont(hlink_font);/*from w  ww  .  j a v  a  2 s.  c  o m*/

    HSSFCell cell;
    HSSFSheet sheet = wb.createSheet("Hyperlinks");

    //URL
    cell = sheet.createRow(0).createCell(0);
    cell.setCellValue("URL Link");
    HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
    link.setAddress("http://poi.apache.org/");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    //link to a file in the current directory
    cell = sheet.createRow(1).createCell(0);
    cell.setCellValue("File Link");
    link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
    link.setAddress("link1.xls");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    //e-mail link
    cell = sheet.createRow(2).createCell(0);
    cell.setCellValue("Email Link");
    link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);
    //note, if subject contains white spaces, make sure they are url-encoded
    link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    //link to a place in this workbook

    //create a target sheet and cell
    HSSFSheet sheet2 = wb.createSheet("Target Sheet");
    sheet2.createRow(0).createCell(0).setCellValue("Target Cell");

    cell = sheet.createRow(3).createCell(0);
    cell.setCellValue("Worksheet Link");
    link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
    link.setAddress("'Target Sheet'!A1");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    FileOutputStream out = new FileOutputStream("hssf-links.xls");
    wb.write(out);
    out.close();
}

From source file:org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPFont.java

License:Apache License

/**
 * Override of Initialize() implementation
 * @param attributes the array of Attribute instances; may be empty, will
 *                  never be null//from   ww  w.  j av a2  s. c o  m
 * @param parent the parent ElementProcessor; may be null
 * @exception IOException if anything is wrong
 */
public void initialize(final Attribute[] attributes, final ElementProcessor parent) throws IOException {
    super.initialize(attributes, parent);
    EPStyle pstyle = (EPStyle) parent;
    if (pstyle.isValid()) {
        Hashtable colorhash = pstyle.getColorHash();
        HSSFColor color = null;

        HSSFCellStyle style = pstyle.getStyle();
        //style.setFillForegroundColor(
        Workbook workbook = getWorkbook();
        HSSFFont font = workbook.createFont();
        style.setFont(font);
        font.setFontHeightInPoints((short) getUnit());
        //font.setFontName(getFont());
        font.setItalic(getItalic());
        if (getBold()) {
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        } else {
            font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
        }
        font.setUnderline((byte) getUnderline());
        font.setStrikeout(getStrikeThrough());

        color = (HSSFColor) colorhash.get(pstyle.getForegroundColor().toString());
        //System.out.println(pstyle.getForegroundColor().toString());
        if (color == null)
            color = new HSSFColor.BLACK();
        font.setColor(color.getIndex());
        hssfFont = font;
    }
}

From source file:org.deployom.core.AuditService.java

License:Open Source License

public HSSFWorkbook saveAudit() {

    // Create book
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFCreationHelper creationHelper = workbook.getCreationHelper();

    // Default Style
    HSSFCellStyle style = workbook.createCellStyle();
    style.setWrapText(true);/*w  w w .  j  a  v  a  2 s  . co m*/
    HSSFFont font = workbook.createFont();
    font.setFontName("Courier New");
    style.setFont(font);
    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);

    // Header Style
    HSSFCellStyle styleHeader = workbook.createCellStyle();
    styleHeader.cloneStyleFrom(style);
    styleHeader.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    font = workbook.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(HSSFColor.WHITE.index);
    styleHeader.setFillForegroundColor(IndexedColors.BLACK.getIndex());
    styleHeader.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    styleHeader.setFont(font);

    // Error Style
    HSSFCellStyle styleError = workbook.createCellStyle();
    styleError.cloneStyleFrom(style);
    styleError.setFillForegroundColor(IndexedColors.CORAL.getIndex());
    styleError.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    styleError.setWrapText(true);

    // Link Style
    HSSFCellStyle styleLink = workbook.createCellStyle();
    styleLink.cloneStyleFrom(style);
    font = workbook.createFont();
    font.setUnderline(HSSFFont.U_SINGLE);
    font.setColor(IndexedColors.BLUE.getIndex());
    styleLink.setFont(font);

    // Create Summary
    HSSFSheet summarySheet = workbook.createSheet("Summary");
    int summaryRownum = 0;
    int summaryCellnum = 0;

    //Create a new row in current sheet
    Row summaryRow = summarySheet.createRow(summaryRownum++);

    // 0
    Cell summaryCell = summaryRow.createCell(summaryCellnum++);
    summaryCell.setCellValue("Job");
    summaryCell.setCellStyle(styleHeader);

    // 1
    summaryCell = summaryRow.createCell(summaryCellnum++);
    summaryCell.setCellValue("Finished");
    summaryCell.setCellStyle(styleHeader);

    // 2
    summaryCell = summaryRow.createCell(summaryCellnum++);
    summaryCell.setCellValue("Errors");
    summaryCell.setCellStyle(styleHeader);

    for (Job job : releaseService.getJobs()) {

        // Open Job
        JobService jobService = new JobService(siteService.getSiteName(), job.getJobName());

        // Create Sheet
        HSSFSheet sheet = workbook.createSheet(job.getJobName());

        int rownum = 0;
        int cellnum = 0;
        int errors = 0;

        //Create a new row in current sheet
        Row row = sheet.createRow(rownum++);

        // 0
        Cell cell = row.createCell(cellnum++);
        cell.setCellValue("Host");
        cell.setCellStyle(styleHeader);

        // 1
        cell = row.createCell(cellnum++);
        cell.setCellValue("Service");
        cell.setCellStyle(styleHeader);

        // 2
        cell = row.createCell(cellnum++);
        cell.setCellValue("Command");
        cell.setCellStyle(styleHeader);

        // 3
        cell = row.createCell(cellnum++);
        cell.setCellValue("Executable");
        cell.setCellStyle(styleHeader);

        // 4
        cell = row.createCell(cellnum++);
        cell.setCellValue("Error");
        cell.setCellStyle(styleHeader);

        // 5
        cell = row.createCell(cellnum++);
        cell.setCellValue("Output");
        cell.setCellStyle(styleHeader);

        // Check all hosts
        for (Host host : jobService.getHosts()) {

            // Check all services
            for (Service service : host.getServices()) {

                // Get a Commands
                for (Command command : service.getCommands()) {

                    //Create a new row in current sheet
                    row = sheet.createRow(rownum++);
                    cellnum = 0;

                    // 0
                    cell = row.createCell(cellnum++);
                    cell.setCellValue(host.getHostName());
                    cell.setCellStyle(style);

                    // 1
                    cell = row.createCell(cellnum++);
                    cell.setCellValue(service.getServiceName());
                    cell.setCellStyle(style);

                    // 2
                    cell = row.createCell(cellnum++);
                    cell.setCellValue(command.getTitle());
                    cell.setCellStyle(style);

                    // 3
                    cell = row.createCell(cellnum++);
                    cell.setCellValue(command.getExec());
                    cell.setCellStyle(style);

                    // 4
                    cell = row.createCell(cellnum++);
                    cell.setCellValue("N");
                    cell.setCellStyle(style);

                    // 5
                    cell = row.createCell(cellnum++);
                    if (command.getOut().length() > 1024) {
                        cell.setCellValue(command.getOut().substring(0, 1024) + "...");
                    } else {
                        cell.setCellValue(command.getOut());
                    }
                    cell.setCellStyle(style);

                    // Error
                    if (command.isError() == true) {
                        row.getCell(0).setCellStyle(styleError);
                        row.getCell(1).setCellStyle(styleError);
                        row.getCell(2).setCellStyle(styleError);
                        row.getCell(3).setCellStyle(styleError);
                        row.getCell(4).setCellStyle(styleError);
                        row.getCell(5).setCellStyle(styleError);
                        row.getCell(4).setCellValue("Y");
                        errors++;
                    }
                }
            }
        }

        // Set Size
        sheet.setColumnWidth(0, 6000);
        sheet.setColumnWidth(1, 4000);
        sheet.setColumnWidth(2, 8000);
        sheet.setColumnWidth(3, 14000);
        sheet.setColumnWidth(4, 3000);
        sheet.setColumnWidth(5, 20000);

        // Summary
        summaryRow = summarySheet.createRow(summaryRownum++);
        summaryCellnum = 0;

        // 0
        summaryCell = summaryRow.createCell(summaryCellnum++);
        summaryCell.setCellValue(job.getJobName());
        summaryCell.setCellStyle(style);

        // Set Link
        HSSFHyperlink link = creationHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
        link.setAddress("" + job.getJobName() + "!A1");
        summaryCell.setHyperlink(link);
        summaryCell.setCellStyle(styleLink);

        // 1
        summaryCell = summaryRow.createCell(summaryCellnum++);
        summaryCell.setCellValue(jobService.getJob().getFinished());
        summaryCell.setCellStyle(style);

        // 2
        summaryCell = summaryRow.createCell(summaryCellnum++);
        summaryCell.setCellValue(errors);
        summaryCell.setCellStyle(style);

        // If errors found
        if (errors > 0) {
            summaryRow.getCell(0).setCellStyle(styleError);
            summaryRow.getCell(1).setCellStyle(styleError);
            summaryRow.getCell(2).setCellStyle(styleError);
        }
    }

    // Set Summary Size
    summarySheet.setColumnWidth(0, 6000);
    summarySheet.setColumnWidth(1, 10000);
    summarySheet.setColumnWidth(2, 4000);

    // Save
    try {
        FileOutputStream out = new FileOutputStream(new File(getFileName()));
        workbook.write(out);
        out.close();
        logger.log(Level.INFO, "{0} generated successfully..", getFileName());

        return workbook;
    } catch (FileNotFoundException ex) {
        logger.log(Level.WARNING, "Audit: {0}", ex);
    } catch (IOException ex) {
        logger.log(Level.WARNING, "Audit: {0}", ex);
    }

    return null;
}

From source file:org.oep.cmon.report.portlet.util.ActionUtil.java

License:Apache License

/**
 * This is function excel report detail//from   w w  w  .j a  v  a2s  . c o  m
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param resourceRequest
 * @param resourceResponse
 */
public static void excelbaocaochitiet(ResourceRequest resourceRequest, ResourceResponse resourceResponse) {
    try {
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("new sheet");
        HSSFFont Row2_font = workbook.createFont();
        Row2_font.setFontName(HSSFFont.FONT_ARIAL);
        Row2_font.setFontHeightInPoints((short) 13);
        Row2_font.setUnderline(HSSFFont.U_SINGLE);

        HSSFFont ngaythang_font = workbook.createFont();
        ngaythang_font.setFontName(HSSFFont.FONT_ARIAL);
        ngaythang_font.setFontHeightInPoints((short) 13);
        ngaythang_font.setItalic(true);

        HSSFFont style_font = workbook.createFont();
        style_font.setFontHeightInPoints((short) 13);

        HSSFFont trangthai_font = workbook.createFont();
        trangthai_font.setFontName(HSSFFont.FONT_ARIAL);
        trangthai_font.setFontHeightInPoints((short) 11);
        trangthai_font.setItalic(true);

        /*define a cell style*/
        HSSFFont tableHeaderFont = (HSSFFont) workbook.createFont();
        tableHeaderFont.setBoldweight((short) 3500);
        HSSFFont titleFont = (HSSFFont) workbook.createFont();
        titleFont.setBoldweight((short) 3500);
        titleFont.setFontHeightInPoints((short) 13);

        HSSFFont titleTongStyle_font = (HSSFFont) workbook.createFont();
        titleTongStyle_font.setFontHeightInPoints((short) 13);
        titleTongStyle_font.setBoldweight((short) 3500);

        HSSFCellStyle styleCellCenter = (HSSFCellStyle) workbook.createCellStyle();
        styleCellCenter.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleCellCenter.setBorderTop(HSSFCellStyle.BORDER_THIN);
        styleCellCenter.setBorderRight(HSSFCellStyle.BORDER_THIN);
        styleCellCenter.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        styleCellCenter.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleCellCenter.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleCellCenter.setWrapText(true);

        HSSFCellStyle styleCellLeft = (HSSFCellStyle) workbook.createCellStyle();
        styleCellLeft.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleCellLeft.setBorderTop(HSSFCellStyle.BORDER_THIN);
        styleCellLeft.setBorderRight(HSSFCellStyle.BORDER_THIN);
        styleCellLeft.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        styleCellLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        styleCellLeft.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleCellLeft.setWrapText(true);

        HSSFCellStyle styleCellRight = (HSSFCellStyle) workbook.createCellStyle();
        styleCellRight.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleCellRight.setBorderTop(HSSFCellStyle.BORDER_THIN);
        styleCellRight.setBorderRight(HSSFCellStyle.BORDER_THIN);
        styleCellRight.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        styleCellRight.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
        styleCellRight.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleCellRight.setWrapText(true);

        HSSFCellStyle titleTongStyle = (HSSFCellStyle) workbook.createCellStyle();
        titleTongStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        titleTongStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        titleTongStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        titleTongStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        titleTongStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
        titleTongStyle.setFont(titleTongStyle_font);

        HSSFCellStyle titleLinhvucStyle = (HSSFCellStyle) workbook.createCellStyle();
        titleLinhvucStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        titleLinhvucStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        titleLinhvucStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        titleLinhvucStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        titleLinhvucStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        titleLinhvucStyle.setFont(titleTongStyle_font);

        HSSFCellStyle styleQuochieu = (HSSFCellStyle) workbook.createCellStyle();
        styleQuochieu.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleQuochieu.setFont(style_font);

        HSSFCellStyle styleRow2 = (HSSFCellStyle) workbook.createCellStyle();
        styleRow2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleRow2.setFont(Row2_font);

        HSSFCellStyle ngaythang_style = (HSSFCellStyle) workbook.createCellStyle();
        ngaythang_style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
        ngaythang_style.setFont(ngaythang_font);

        HSSFCellStyle style_trangthai = (HSSFCellStyle) workbook.createCellStyle();
        style_trangthai.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style_trangthai.setFont(trangthai_font);

        HSSFCellStyle style_tungay_denngay = (HSSFCellStyle) workbook.createCellStyle();
        style_tungay_denngay.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style_tungay_denngay.setFont(trangthai_font);

        HSSFCellStyle styleHeader = (HSSFCellStyle) workbook.createCellStyle();
        styleHeader.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleHeader.setBorderTop(HSSFCellStyle.BORDER_THIN);
        styleHeader.setBorderRight(HSSFCellStyle.BORDER_THIN);
        styleHeader.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        styleHeader.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleHeader.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleHeader.setFont(tableHeaderFont);
        styleHeader.setWrapText(true);

        HSSFCellStyle styleTitle = (HSSFCellStyle) workbook.createCellStyle();
        styleTitle.setFont(titleFont);
        styleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleTitle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        /*end style*/
        int rowNum = 0;
        String[] header = { "STT", "Lnh vc",
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.tenhoso"),
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.sohoso"),
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.trangthai"),
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.diachi"),
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.dienthoai"),
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.nguoinophoso"),
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.chuhoso"),
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.ngaynhan"),
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.ngaytra"),
                "Tnh trng\n h s",
                LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.ghichu") };
        int[] width = { 1200, 3750, 3750, 4200, 3650, 3650, 3650, 3650, 3750, 3750, 3750, 3750, 3750 };

        String[] listloaihoso = null;
        if (Validator.isNotNull(ParamUtil.getParameterValues(resourceRequest, "chon_hoso"))) {
            listloaihoso = ParamUtil.getParameterValues(resourceRequest, "chon_hoso");
        }
        String ngaynhan_tungay = "";
        if (Validator.isNotNull(ParamUtil.getString(resourceRequest, "ngaynhan_tungay"))) {
            ngaynhan_tungay = ParamUtil.getString(resourceRequest, "ngaynhan_tungay");
        }
        String ngaynhan_denngay = "";
        if (Validator.isNotNull(ParamUtil.getString(resourceRequest, "ngaynhan_denngay"))) {
            ngaynhan_denngay = ParamUtil.getString(resourceRequest, "ngaynhan_denngay");
        }
        String trangthai_hoso = "";
        if (Validator.isNotNull(ParamUtil.getString(resourceRequest, "trangthai_hoso"))) {
            trangthai_hoso = ParamUtil.getString(resourceRequest, "trangthai_hoso");
        }
        String tinhtrang = "";
        if (Validator.isNotNull(ParamUtil.getString(resourceRequest, "tinhtrang_hoso"))) {
            tinhtrang = ParamUtil.getString(resourceRequest, "tinhtrang_hoso");
        }
        String loaidangky = "";
        if (Validator.isNotNull(ParamUtil.getString(resourceRequest, "loaidangky_hoso"))) {
            loaidangky = ParamUtil.getString(resourceRequest, "loaidangky_hoso");
        }
        String ten_donvi = "";
        if (Validator.isNotNull(ParamUtil.getString(resourceRequest, "chon_donvi"))) {
            ten_donvi = ParamUtil.getString(resourceRequest, "chon_donvi");
        }
        List<Baocaochitiet> list = BaocaochitietLocalServiceUtil.hienthiDanhsachBaocao(listloaihoso,
                ngaynhan_tungay, ngaynhan_denngay, trangthai_hoso, tinhtrang, loaidangky, QueryUtil.ALL_POS,
                QueryUtil.ALL_POS);

        sheet.addMergedRegion(new Region(rowNum, (short) 0, (short) 0, (short) 2));
        HSSFRow Quochieu = sheet.createRow(rowNum);
        HSSFCell Quochieucell_1 = Quochieu.createCell(0);
        HSSFCell Quochieucell_2 = Quochieu.createCell(3);
        Quochieucell_1.setCellStyle(styleQuochieu);
        Quochieucell_2.setCellStyle(styleQuochieu);
        Quochieucell_1.setCellValue(LanguageUtil.get(
                (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.qlc"));
        sheet.addMergedRegion(new Region(rowNum, (short) 3, (short) 0, (short) 12));
        Quochieucell_2.setCellValue(LanguageUtil.get(
                (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.chxhcnvn"));
        rowNum = rowNum + 1;

        sheet.addMergedRegion(new Region(rowNum, (short) 0, (short) 1, (short) 2));
        HSSFRow Row_2 = sheet.createRow(rowNum);
        //HSSFCell Quan = Row_2.createCell(0);
        //Quan.setCellValue(LanguageUtil.get((PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG) ,resourceRequest.getLocale(),"vn.dtt.cmon.report.excel.qlc"));
        //Quan.setCellStyle(styleRow2);

        sheet.addMergedRegion(new Region(rowNum, (short) 3, (short) 1, (short) 12));
        HSSFCell Tieungu = Row_2.createCell(3);
        Tieungu.setCellValue(LanguageUtil.get(
                (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.dltdhp"));
        Tieungu.setCellStyle(styleRow2);
        rowNum = rowNum + 1;

        Calendar dateTime = Calendar.getInstance();
        SimpleDateFormat ngay_format = new SimpleDateFormat("dd");
        SimpleDateFormat thang_format = new SimpleDateFormat("MM");
        SimpleDateFormat nam_format = new SimpleDateFormat("yyyy");
        Date time = dateTime.getTime();
        String day = ngay_format.format(time);
        String month = thang_format.format(time);
        String year = nam_format.format(time);
        sheet.addMergedRegion(new Region(rowNum, (short) 0, (short) 2, (short) 10));
        HSSFRow Row_3 = sheet.createRow(rowNum);
        HSSFCell ngaythang = Row_3.createCell(0);
        ngaythang.setCellValue(ten_donvi + ", "
                + LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.ngay")
                + " " + day + " "
                + LanguageUtil
                        .get((PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                                resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.thang")
                + " " + month + " "
                + LanguageUtil.get(
                        (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                        resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.nam")
                + " " + year);
        ngaythang.setCellStyle(ngaythang_style);
        rowNum = rowNum + 1;

        sheet.addMergedRegion(new Region(rowNum, (short) 0, rowNum, (short) 10));
        HSSFRow titleRow = sheet.createRow(rowNum);
        HSSFCell titleCell = titleRow.createCell(0);
        titleCell.setCellValue(LanguageUtil.get(
                (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.tieude"));
        titleCell.setCellStyle(styleTitle);
        if (ngaynhan_tungay != "" && ngaynhan_denngay != "") {
            rowNum = rowNum + 1;
            sheet.addMergedRegion(new Region(rowNum, (short) 0, rowNum, (short) 10));
            HSSFRow TimeReportRow = sheet.createRow(rowNum);
            HSSFCell TimeReportCell = TimeReportRow.createCell(0);
            TimeReportCell.setCellValue(LanguageUtil.get(
                    (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                    resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.tungay") + ": " + ngaynhan_tungay
                    + " "
                    + LanguageUtil.get(
                            (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                            resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.denngay")
                    + ": " + ngaynhan_denngay);
            TimeReportCell.setCellStyle(style_tungay_denngay);
        } else if (ngaynhan_tungay != "" && ngaynhan_denngay == "") {
            rowNum = rowNum + 1;
            ngaynhan_denngay = "01/12/" + ngaynhan_tungay.substring(6, 10);
            sheet.addMergedRegion(new Region(rowNum, (short) 0, rowNum, (short) 10));
            HSSFRow TimeReportRow = sheet.createRow(rowNum);
            HSSFCell TimeReportCell = TimeReportRow.createCell(0);
            TimeReportCell.setCellValue(LanguageUtil.get(
                    (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                    resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.tungay") + ": " + ngaynhan_tungay
                    + " "
                    + LanguageUtil.get(
                            (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                            resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.denngay")
                    + ": " + ngaynhan_denngay);
            TimeReportCell.setCellStyle(style_tungay_denngay);
        } else if (ngaynhan_tungay == "" && ngaynhan_denngay != "") {
            rowNum = rowNum + 1;
            ngaynhan_tungay = "01/01/" + ngaynhan_denngay.substring(6, 10);
            sheet.addMergedRegion(new Region(rowNum, (short) 0, rowNum, (short) 10));
            HSSFRow TimeReportRow = sheet.createRow(rowNum);
            HSSFCell TimeReportCell = TimeReportRow.createCell(0);
            TimeReportCell.setCellValue(LanguageUtil.get(
                    (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                    resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.tungay") + ": " + ngaynhan_tungay
                    + " "
                    + LanguageUtil.get(
                            (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                            resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.denngay")
                    + ": " + ngaynhan_denngay);
            TimeReportCell.setCellStyle(style_tungay_denngay);
        } else {
            rowNum = rowNum + 1;
            ngaynhan_tungay = "01/01/" + year;
            ngaynhan_denngay = "01/12/" + year;
            sheet.addMergedRegion(new Region(rowNum, (short) 0, rowNum, (short) 10));
            HSSFRow TimeReportRow = sheet.createRow(rowNum);
            HSSFCell TimeReportCell = TimeReportRow.createCell(0);
            TimeReportCell.setCellValue(LanguageUtil.get(
                    (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                    resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.tungay") + ": " + ngaynhan_tungay
                    + " "
                    + LanguageUtil.get(
                            (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                            resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.denngay")
                    + ": " + ngaynhan_denngay);
            TimeReportCell.setCellStyle(style_tungay_denngay);
        }
        if (!trangthai_hoso.equals("")) {
            rowNum = rowNum + 1;
            sheet.addMergedRegion(new Region(rowNum, (short) 0, rowNum, (short) 10));
            HSSFRow TimeReportRow = sheet.createRow(rowNum);
            HSSFCell TimeReportCell = TimeReportRow.createCell(0);
            TimeReportCell
                    .setCellValue("("
                            + LanguageUtil.get(
                                    (PortletConfig) resourceRequest
                                            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                                    resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.trangthai")
                            + ": " + TrangThaiHoSoLocalServiceUtil
                                    .getTrangThaiHoSo(Long.parseLong(trangthai_hoso)).getTrangThai()
                            + ")");
            TimeReportCell.setCellStyle(style_trangthai);
        }
        rowNum = rowNum + 3;
        HSSFRow headerRow = (HSSFRow) sheet.createRow(rowNum);
        int colNum = 0;
        for (int i = 0; i < header.length; i++) {
            HSSFCell cell = headerRow.createCell(colNum);
            cell.setCellStyle(styleHeader);
            cell.setCellValue(header[i]);
            sheet.setColumnWidth(i, width[i]);
            colNum++;
        }
        rowNum++;
        long count = 0;
        if (list != null && list.size() > 0) {
            long linhvucId = 0L;
            for (int a = 0; a < list.size(); a++) {
                String tinh_trang = "";
                if (Validator.isNotNull(list.get(a).getNGAYTRAKETQUA())
                        && Validator.isNotNull(list.get(a).getNGAYHENTRAKETQUA())) {
                    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
                    Date ngaytra = df.parse(list.get(a).getNGAYTRAKETQUA());
                    Date ngayhentra = df.parse(list.get(a).getNGAYHENTRAKETQUA());
                    if (ngaytra.before(ngayhentra)) {
                        tinh_trang = "Sm hn";
                    } else if (ngaytra.equals(ngayhentra)) {
                        tinh_trang = "ng hn";
                    } else if (ngaytra.after(ngayhentra)) {
                        tinh_trang = "Tr hn";
                    }
                }
                //khai bao dong va cac cell
                HSSFRow row = (HSSFRow) sheet.createRow(rowNum);
                HSSFCell cell = row.createCell(0);
                HSSFCell cell1 = row.createCell(1);
                HSSFCell cell2 = row.createCell(2);
                HSSFCell cell3 = row.createCell(3);
                HSSFCell cell4 = row.createCell(4);
                HSSFCell cell5 = row.createCell(5);
                HSSFCell cell6 = row.createCell(6);
                HSSFCell cell7 = row.createCell(7);
                HSSFCell cell8 = row.createCell(8);
                HSSFCell cell9 = row.createCell(9);
                HSSFCell cell10 = row.createCell(10);
                HSSFCell cell11 = row.createCell(11);
                HSSFCell cell12 = row.createCell(12);
                //set style cho cac cell
                cell.setCellStyle(styleCellCenter);
                cell1.setCellStyle(styleCellLeft);
                cell2.setCellStyle(styleCellCenter);
                cell3.setCellStyle(styleCellCenter);
                cell4.setCellStyle(styleCellCenter);
                cell5.setCellStyle(styleCellCenter);
                cell6.setCellStyle(styleCellCenter);
                cell7.setCellStyle(styleCellCenter);
                cell8.setCellStyle(styleCellCenter);
                cell9.setCellStyle(styleCellCenter);
                cell10.setCellStyle(styleCellCenter);
                cell11.setCellStyle(styleCellCenter);
                cell12.setCellStyle(styleCellCenter);
                //set gia tri cho cac cell
                cell.setCellValue((a + 1));
                cell1.setCellValue(NhomThuTucHanhChinhLocalServiceUtil
                        .getNhomThuTucHanhChinh(list.get(a).getLINHVUCID()).getTen());
                cell2.setCellValue(list.get(a).getTEN());
                cell3.setCellValue(list.get(a).getMASOHOSO());
                cell4.setCellValue(list.get(a).getTRANGTHAI());
                cell5.setCellValue(list.get(a).getDIACHIHIENNAY());
                cell6.setCellValue(list.get(a).getDIENTHOAIDIDONG());
                cell7.setCellValue(list.get(a).getHOTENNGUOINOPHOSO());
                cell8.setCellValue(list.get(a).getNGUOIDAIDIENPHAPLUAT());
                cell9.setCellValue(list.get(a).getNGAYNHANHOSO());
                cell10.setCellValue(list.get(a).getNGAYTRAKETQUA());
                cell11.setCellValue(tinh_trang);
                cell12.setCellValue(list.get(a).getGHICHU());
                count = a;
                rowNum++;
            }
            count = count + 1;
        } else {
            //khai bao dong va cac cell
            HSSFRow row = (HSSFRow) sheet.createRow(rowNum);
            HSSFCell cell = row.createCell(0);
            HSSFCell cell1 = row.createCell(1);
            HSSFCell cell2 = row.createCell(2);
            HSSFCell cell3 = row.createCell(3);
            HSSFCell cell4 = row.createCell(4);
            HSSFCell cell5 = row.createCell(5);
            HSSFCell cell6 = row.createCell(6);
            HSSFCell cell7 = row.createCell(7);
            HSSFCell cell8 = row.createCell(8);
            HSSFCell cell9 = row.createCell(9);
            HSSFCell cell10 = row.createCell(10);
            HSSFCell cell11 = row.createCell(11);
            HSSFCell cell12 = row.createCell(12);
            //set style cho cac cell
            cell.setCellStyle(styleCellCenter);
            cell1.setCellStyle(styleCellLeft);
            cell2.setCellStyle(styleCellCenter);
            cell3.setCellStyle(styleCellCenter);
            cell4.setCellStyle(styleCellCenter);
            cell5.setCellStyle(styleCellCenter);
            cell6.setCellStyle(styleCellCenter);
            cell7.setCellStyle(styleCellCenter);
            cell8.setCellStyle(styleCellCenter);
            cell9.setCellStyle(styleCellCenter);
            cell10.setCellStyle(styleCellCenter);
            cell11.setCellStyle(styleCellCenter);
            cell12.setCellStyle(styleCellCenter);
            //set gia tri cho cac cell
            cell.setCellValue("");
            cell1.setCellValue("");
            cell2.setCellValue("");
            cell3.setCellValue("");
            cell4.setCellValue("");
            cell5.setCellValue("");
            cell6.setCellValue("");
            cell7.setCellValue("");
            cell8.setCellValue("");
            cell9.setCellValue("");
            cell10.setCellValue("");
            cell11.setCellValue("");
            cell12.setCellValue("");
            count = 0;
            rowNum++;
        }
        sheet.addMergedRegion(new Region(rowNum, (short) 0, rowNum, (short) 11));
        HSSFRow rowTong = (HSSFRow) sheet.createRow(rowNum);
        HSSFCell cell = rowTong.createCell(0);
        HSSFCell cell1 = rowTong.createCell(1);
        HSSFCell cell2 = rowTong.createCell(2);
        HSSFCell cell3 = rowTong.createCell(3);
        HSSFCell cell4 = rowTong.createCell(4);
        HSSFCell cell5 = rowTong.createCell(5);
        HSSFCell cell6 = rowTong.createCell(6);
        HSSFCell cell7 = rowTong.createCell(7);
        HSSFCell cell8 = rowTong.createCell(8);
        HSSFCell cell9 = rowTong.createCell(9);
        HSSFCell cell10 = rowTong.createCell(10);
        HSSFCell cell11 = rowTong.createCell(11);
        HSSFCell cell12 = rowTong.createCell(12);
        //set style cho cac cell
        cell.setCellStyle(titleTongStyle);
        cell1.setCellStyle(styleCellCenter);
        cell2.setCellStyle(styleCellCenter);
        cell3.setCellStyle(styleCellCenter);
        cell4.setCellStyle(styleCellCenter);
        cell5.setCellStyle(styleCellCenter);
        cell6.setCellStyle(styleCellCenter);
        cell7.setCellStyle(styleCellCenter);
        cell8.setCellStyle(styleCellCenter);
        cell9.setCellStyle(styleCellCenter);
        cell10.setCellStyle(styleCellCenter);
        cell11.setCellStyle(styleCellCenter);
        cell12.setCellStyle(styleCellCenter);
        //set value for cells of rowtong 
        cell.setCellValue(LanguageUtil.get(
                (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                resourceRequest.getLocale(), "vn.dtt.cmon.report.baocaochitiet.tonghoso"));
        cell12.setCellValue(count);

        rowNum = rowNum + 2;
        sheet.addMergedRegion(new Region(rowNum, (short) 1, rowNum, (short) 2));
        HSSFRow nguoilap_baocaoRow = sheet.createRow(rowNum);
        HSSFCell nguoilap_Cell = nguoilap_baocaoRow.createCell(1);
        nguoilap_Cell.setCellValue(LanguageUtil.get(
                (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.nguoilap"));
        nguoilap_Cell.setCellStyle(styleTitle);

        sheet.addMergedRegion(new Region(rowNum, (short) 7, rowNum, (short) 10));
        HSSFCell title_nguoibaocao_Cell = nguoilap_baocaoRow.createCell(7);
        title_nguoibaocao_Cell.setCellValue(LanguageUtil.get(
                (PortletConfig) resourceRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG),
                resourceRequest.getLocale(), "vn.dtt.cmon.report.excel.nguoibaocao"));
        title_nguoibaocao_Cell.setCellStyle(styleTitle);

        rowNum = rowNum + 4;

        if (Validator.isNotNull(resourceRequest.getAttribute("THEME_DISPLAY"))) {
            CongChuc congchuc = new CongChucImpl();
            ThemeDisplay themdisplay = (ThemeDisplay) resourceRequest.getAttribute("THEME_DISPLAY");
            User user = themdisplay.getUser();
            TaiKhoanNguoiDung taikhoan = new TaiKhoanNguoiDungImpl();
            taikhoan = TaiKhoanNguoiDungLocalServiceUtil.findByTaiKhoanNguoiDungId(user.getUserId());
            congchuc = ActionUtil.getCongchucByTaiKhoanNguoiDungId(taikhoan.getId());

            sheet.addMergedRegion(new Region(rowNum, (short) 1, rowNum, (short) 2));
            HSSFRow nguoi_baocaoRow = sheet.createRow(rowNum);
            HSSFCell nguoibaocao_Cell = nguoi_baocaoRow.createCell(1);
            nguoibaocao_Cell.setCellValue(congchuc.getHoVaTen());
            nguoibaocao_Cell.setCellStyle(styleTitle);
        }

        resourceResponse.setContentType("application/vnd.ms-excel;charset=utf-8");
        resourceResponse.addProperty(HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate");
        resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=Baocaochitiet.xls");
        OutputStream out = resourceResponse.getPortletOutputStream();
        workbook.write(out);
        out.flush();
        out.close();
    } catch (Exception e) {
    }
}

From source file:org.openmicroscopy.shoola.util.file.ExcelWriter.java

License:Open Source License

/** Creates the fonts that are going to be used in the styles. */
private void createFonts() {
    HSSFFont font;
    /* Hyperlink font. */
    font = workbook.createFont();/*w w w  .  j  a v a 2  s  . c  o  m*/
    font.setUnderline(HSSFFont.U_SINGLE);
    font.setColor(HSSFColor.BLUE.index);
    fontMap.put(HYPERLINK, font);

    /* Default Font. */
    font = workbook.createFont();
    fontMap.put(DEFAULT, font);

    /* Bold Font. */
    font = workbook.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontMap.put(BOLD_DEFAULT, font);

    /* Underline Font. */
    font = workbook.createFont();
    font.setUnderline(HSSFFont.U_SINGLE);
    fontMap.put(UNDERLINE_DEFAULT, font);

    /* Italic Font. */
    font = workbook.createFont();
    font.setItalic(true);
    fontMap.put(ITALIC_DEFAULT, font);

    /* Italic, underline Font. */
    font = workbook.createFont();
    font.setItalic(true);
    font.setUnderline(HSSFFont.U_SINGLE);
    fontMap.put(ITALIC_UNDERLINE_DEFAULT, font);

    /* Italic, bold Font. */
    font = workbook.createFont();
    font.setItalic(true);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontMap.put(BOLD_ITALIC_DEFAULT, font);

    /* Italic, bold, underline Font. */
    font = workbook.createFont();
    font.setItalic(true);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setUnderline(HSSFFont.U_SINGLE);
    fontMap.put(BOLD_ITALIC_UNDERLINE_DEFAULT, font);

    /* Italic, bold, underline Font. */
    font = workbook.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setUnderline(HSSFFont.U_SINGLE);
    fontMap.put(BOLD_UNDERLINE_DEFAULT, font);

    /* 12 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 12);
    fontMap.put(PLAIN_12, font);

    /* 14 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 14);
    fontMap.put(PLAIN_14, font);

    /* 14 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 14);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontMap.put(BOLD_14, font);

    /* 18 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 18);
    fontMap.put(PLAIN_18, font);

    /* 18 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 18);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontMap.put(BOLD_18, font);
}

From source file:org.orbeon.oxf.util.XLSUtils.java

License:Open Source License

public static void copyFont(HSSFFont destination, HSSFFont source) {
    destination.setBoldweight(source.getBoldweight());
    destination.setColor(source.getColor());
    destination.setFontHeight(source.getFontHeight());
    destination.setFontHeightInPoints(source.getFontHeightInPoints());
    destination.setFontName(source.getFontName());
    destination.setItalic(source.getItalic());
    destination.setStrikeout(source.getStrikeout());
    destination.setTypeOffset(source.getTypeOffset());
    destination.setUnderline(source.getUnderline());
}

From source file:poi.hssf.usermodel.examples.OfficeDrawing.java

License:Apache License

private static void drawSheet4(HSSFSheet sheet4, HSSFWorkbook wb) {
    // Create the drawing patriarch.  This is the top level container for
    // all shapes. This will clear out any existing shapes for that sheet.
    HSSFPatriarch patriarch = sheet4.createDrawingPatriarch();

    // Create a couple of textboxes
    HSSFTextbox textbox1 = patriarch//from w  ww  . ja v a 2s .  c o m
            .createTextbox(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 2, 2));
    textbox1.setString(new HSSFRichTextString("This is a test"));
    HSSFTextbox textbox2 = patriarch
            .createTextbox(new HSSFClientAnchor(0, 0, 900, 100, (short) 3, 3, (short) 3, 4));
    textbox2.setString(new HSSFRichTextString("Woo"));
    textbox2.setFillColor(200, 0, 0);
    textbox2.setLineStyle(HSSFSimpleShape.LINESTYLE_DOTGEL);

    // Create third one with some fancy font styling.
    HSSFTextbox textbox3 = patriarch
            .createTextbox(new HSSFClientAnchor(0, 0, 900, 100, (short) 4, 4, (short) 5, 4 + 1));
    HSSFFont font = wb.createFont();
    font.setItalic(true);
    font.setUnderline(HSSFFont.U_DOUBLE);
    HSSFRichTextString string = new HSSFRichTextString("Woo!!!");
    string.applyFont(2, 5, font);
    textbox3.setString(string);
    textbox3.setFillColor(0x08000030);
    textbox3.setLineStyle(HSSFSimpleShape.LINESTYLE_NONE); // no line around the textbox.
    textbox3.setNoFill(true); // make it transparent
}

From source file:ubic.pubmedgate.interactions.evaluation.CreateInteractionSpreadsheet.java

License:Apache License

public void populate(Collection<NormalizedConnection> pairsNormalized) throws Exception {
    int row = 1;// w  ww  .  j a  va2 s  . co  m
    boolean unseenSetup = SLReader.isUnseenSetup();

    HSSFFont textFont = workbook.createFont();
    textFont.setUnderline(HSSFFont.U_SINGLE);
    textFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    Map<String, String> pairToPMID = XMLReader.getPairIDToPMID();
    Map<String, Double> scores = SLReader.getScores();

    List<String> positivePredictions = SLReader.getPositivePredictions();
    List<String> positiveAnnotations = SLReader.getPositives();

    LoadInteractionSpreadsheet allSpreadSheet = AllCuratorsCombined.getFinal2000Results();
    Set<String> previousAccepts = allSpreadSheet.getAcceptedPairs();
    Collection<String> previousEvaluated = allSpreadSheet.getAllPairs();

    for (NormalizedConnection nc : pairsNormalized) {
        String pair = nc.pairID;
        if (row > 65000) {
            save();
            init();
            filename += "overflow.xls";
            row = 1;
        }

        HSSFRow r = spreadsheet.getRow(row);
        if (r == null) {
            r = spreadsheet.createRow(row);
        }
        int col = schema.getPosition("sentence");
        HSSFCell c = r.createCell(col);
        c.setCellType(HSSFCell.CELL_TYPE_STRING);

        HSSFRichTextString richString = XMLReader.getRichStringSentence(pair, textFont);
        c.setCellValue(richString);

        String pmid = pairToPMID.get(pair);

        ExcelUtil.setValue(spreadsheet, row, schema.getPosition("PMID"), pmid);
        ExcelUtil.setValue(spreadsheet, row, schema.getPosition("PairID"), pair);

        String partnerAText = XMLReader.getPartnerAText(pair);
        String partnerBText = XMLReader.getPartnerBText(pair);

        ExcelUtil.setValue(spreadsheet, row, schema.getPosition("RegionAName"), partnerAText);
        ExcelUtil.setValue(spreadsheet, row, schema.getPosition("RegionBName"), partnerBText);

        ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Score"), scores.get(pair));
        ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Prediction"),
                "" + positivePredictions.contains(pair));
        if (!unseenSetup) {
            ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Previous Annotation"),
                    "" + positiveAnnotations.contains(pair));
        } else {
            ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Previous Annotation"), "none");
        }

        // if it was normalized
        if (nc.regionA != null) {
            ExcelUtil.setValue(spreadsheet, row, schema.getPosition("RegionAResolve"), nc.regionA);
            // check for exact match
            if (nc.regionA.equalsIgnoreCase(partnerAText)) {
                ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Resolve Evaluation A"), "Accept");
            }
        }
        if (nc.regionB != null) {
            ExcelUtil.setValue(spreadsheet, row, schema.getPosition("RegionBResolve"), nc.regionB);
            // check for exact match
            if (nc.regionB.equalsIgnoreCase(partnerBText)) {
                ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Resolve Evaluation B"), "Accept");
            }
        }

        String acceptString;
        if (previousEvaluated.contains(pair)) {
            if (previousAccepts.contains(pair)) {
                acceptString = "Accept";
            } else {
                acceptString = "Reject";
            }
        } else {
            acceptString = "Not done";
        }
        ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Previous Annotation"), acceptString);

        ExcelUtil.setFormula(spreadsheet, row, schema.getPosition("LinkToAbstract"),
                "HYPERLINK(\"http://www.ncbi.nlm.nih.gov/pubmed/" + pmid + "\", \"PubMed\")");

        row++;
    }

}