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:org.etudes.mneme.impl.AttachmentServiceImpl.java

License:Apache License

/**
 * Creates True False tab for answers Item Analysis
 *
 * @param tf_questions List of True False questions
 * @param workbook Workbook object//w  ww. jav  a2 s  .c om
 * @param assessment Assessment object
 */
void createTrueFalseTab(List<Question> tf_questions, HSSFWorkbook workbook, Assessment assessment) {
    if (tf_questions == null || tf_questions.size() == 0)
        return;

    String assmtId = assessment.getId();
    HSSFSheet sheet = null;
    HSSFRow row;

    boolean headerRowDone = false;
    for (Iterator it = tf_questions.iterator(); it.hasNext();) {
        Question q = (Question) it.next();

        List<Answer> answers = this.submissionService.findSubmissionAnswers(assessment, q,
                FindAssessmentSubmissionsSort.userName_a, null, null);
        if (answers == null || answers.size() == 0)
            return;

        if (!headerRowDone) {
            sheet = workbook.createSheet("TrueFalse");

            HSSFRow headerRow = sheet.createRow((short) 0);

            HSSFCellStyle style = workbook.createCellStyle();
            HSSFFont font = workbook.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            style.setFont(font);
            // Printing header row
            HSSFCell cell0 = headerRow.createCell((short) (0));
            cell0.setCellStyle(style);
            cell0.setCellValue(this.messages.getFormattedMessage("item_analysis_question", null));
            HSSFCell cell1 = headerRow.createCell((short) (1));
            cell1.setCellStyle(style);
            cell1.setCellValue(this.messages.getFormattedMessage("true-header", null));
            HSSFCell cell2 = headerRow.createCell((short) (2));
            cell2.setCellStyle(style);
            cell2.setCellValue(this.messages.getFormattedMessage("false-header", null));

            headerRowDone = true;
        }

        int trueCount = 0, falseCount = 0;

        for (Answer answer : answers) {
            TypeSpecificAnswer a = answer.getTypeSpecificAnswer();
            if (a instanceof TrueFalseAnswerImpl) {
                TrueFalseAnswerImpl tf = (TrueFalseAnswerImpl) a;
                if (tf.getAnswer().equals("true"))
                    trueCount++;
                if (tf.getAnswer().equals("false"))
                    falseCount++;
            }
        }
        int rowNum = sheet.getLastRowNum() + 1;
        row = sheet.createRow(rowNum);
        String quest_desc = stripHtml(q.getDescription());
        row.createCell((short) 0).setCellValue(quest_desc);
        if (((TrueFalseQuestionImpl) q.getTypeSpecificQuestion()).getCorrectAnswer().equals("true"))
            row.createCell((short) 1).setCellValue("*" + trueCount + "*");
        else
            row.createCell((short) 1).setCellValue(trueCount);
        if (((TrueFalseQuestionImpl) q.getTypeSpecificQuestion()).getCorrectAnswer().equals("false"))
            row.createCell((short) 2).setCellValue("*" + falseCount + "*");
        else
            row.createCell((short) 2).setCellValue(falseCount);

    }
}

From source file:org.executequery.gui.importexport.DefaultExcelWorkbookBuilder.java

License:Open Source License

public void addRowHeader(List<String> values) {

    if (currentRow > 0) {

        currentRow++;//from  w  w  w  . ja  v a 2s.c  om
    }

    HSSFFont font = createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    HSSFCellStyle style = createStyle();
    style.setFont(font);

    fillRow(values, createRow(currentRow), style);
}

From source file:org.exoplatform.addon.pulse.service.ws.RestActivitiesStatistic.java

License:Open Source License

private HSSFWorkbook buildExportDataForExcel(String maxColumn, String filter, Date fromDate,
        boolean isExportNewUsersData, boolean isExportLoginCountData, boolean isExportForumActiveUsersData,
        boolean isExportNewForumPostsData, boolean isExportPlfDownloadsData, boolean isExportUserConnectionData,
        boolean isExportSocialPostData, boolean isExportEmailNotificationData) throws Exception {
    ChartData data = buildExportData(maxColumn, filter, fromDate, isExportPlfDownloadsData);
    String fileName = "export_" + maxColumn + "_" + filter + "_from_" + partString(fromDate, "yyyy.MM.dd")
            + ".xls";

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet worksheet = workbook.createSheet(fileName);

    // index from 0,0... cell A1 is cell(0,0)

    HSSFCellStyle headerCellStyle = workbook.createCellStyle();
    HSSFFont hSSFFont = workbook.createFont();
    hSSFFont.setFontName(HSSFFont.FONT_ARIAL);
    hSSFFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    hSSFFont.setColor(HSSFColor.BLACK.index);
    headerCellStyle.setFont(hSSFFont);/*from   w ww. j av  a2 s . co  m*/

    HSSFRow headerRow = worksheet.createRow((short) 0);
    HSSFCell cellA1 = headerRow.createCell(0);
    cellA1.setCellValue("Statistics");
    cellA1.setCellStyle(headerCellStyle);

    for (int i = 0; i < data.getListTitle().size(); i++) {
        HSSFCell cell = headerRow.createCell(i + 1);
        cell.setCellValue(data.getListTitle().get(i));
        cell.setCellStyle(headerCellStyle);
    }

    HSSFCell totalCell = headerRow.createCell(data.getListTitle().size() + 1);
    totalCell.setCellValue("Total");
    totalCell.setCellStyle(headerCellStyle);

    int rowIndex = 1;
    if (isExportNewUsersData) {
        HSSFRow metricRow = worksheet.createRow(rowIndex);
        HSSFCell metricCell = metricRow.createCell(0);
        metricCell.setCellValue("New Users Registration");
        Long total = 0L;
        for (int i = 0; i < data.getNewUsersData().size(); i++) {
            total += data.getNewUsersData().get(i);
            HSSFCell cell = metricRow.createCell(i + 1);
            cell.setCellValue(data.getNewUsersData().get(i));
        }
        HSSFCell metricTotalCell = metricRow.createCell(data.getNewUsersData().size() + 1);
        metricTotalCell.setCellValue(total);

        rowIndex++;
    }

    if (isExportLoginCountData) {
        HSSFRow metricRow = worksheet.createRow(rowIndex);
        HSSFCell metricCell = metricRow.createCell(0);
        metricCell.setCellValue("Nb Unique Login");
        Long total = 0L;
        for (int i = 0; i < data.getLoginCountData().size(); i++) {
            total += data.getLoginCountData().get(i);
            HSSFCell cell = metricRow.createCell(i + 1);
            cell.setCellValue(data.getLoginCountData().get(i));
        }
        HSSFCell metricTotalCell = metricRow.createCell(data.getLoginCountData().size() + 1);
        metricTotalCell.setCellValue(total);

        rowIndex++;
    }

    if (isExportForumActiveUsersData) {
        HSSFRow metricRow = worksheet.createRow(rowIndex);
        HSSFCell metricCell = metricRow.createCell(0);
        metricCell.setCellValue("Forum Active Users Average");
        Long total = 0L;
        int itemHasData = 0;
        for (int i = 0; i < data.getForumActiveUsersData().size(); i++) {
            total += data.getForumActiveUsersData().get(i);
            if (data.getForumActiveUsersData().get(i) > 0)
                itemHasData++;
            HSSFCell cell = metricRow.createCell(i + 1);
            cell.setCellValue(data.getForumActiveUsersData().get(i));
        }
        HSSFCell metricTotalCell = metricRow.createCell(data.getForumActiveUsersData().size() + 1);
        Long average = itemHasData > 0 ? total / itemHasData : 0L;
        metricTotalCell.setCellValue(average);

        rowIndex++;
    }

    if (isExportNewForumPostsData) {
        HSSFRow metricRow = worksheet.createRow(rowIndex);
        HSSFCell metricCell = metricRow.createCell(0);
        metricCell.setCellValue("New Forum Posts");
        Long total = 0L;
        for (int i = 0; i < data.getNewForumPostsData().size(); i++) {
            total += data.getNewForumPostsData().get(i);
            HSSFCell cell = metricRow.createCell(i + 1);
            cell.setCellValue(data.getNewForumPostsData().get(i));
        }
        HSSFCell metricTotalCell = metricRow.createCell(data.getNewForumPostsData().size() + 1);
        metricTotalCell.setCellValue(total);

        rowIndex++;
    }

    if (isExportUserConnectionData) {
        HSSFRow metricRow = worksheet.createRow(rowIndex);
        HSSFCell metricCell = metricRow.createCell(0);
        metricCell.setCellValue("New User connections");
        Long total = 0L;
        for (int i = 0; i < data.getUserConnectionData().size(); i++) {
            total += data.getUserConnectionData().get(i);
            HSSFCell cell = metricRow.createCell(i + 1);
            cell.setCellValue(data.getUserConnectionData().get(i));
        }
        HSSFCell metricTotalCell = metricRow.createCell(data.getUserConnectionData().size() + 1);
        metricTotalCell.setCellValue(total);

        rowIndex++;
    }

    if (isExportSocialPostData) {
        HSSFRow metricRow = worksheet.createRow(rowIndex);
        HSSFCell metricCell = metricRow.createCell(0);
        metricCell.setCellValue("New posts in activities stream");
        Long total = 0L;
        for (int i = 0; i < data.getSocialPostData().size(); i++) {
            total += data.getSocialPostData().get(i);
            HSSFCell cell = metricRow.createCell(i + 1);
            cell.setCellValue(data.getSocialPostData().get(i));
        }
        HSSFCell metricTotalCell = metricRow.createCell(data.getSocialPostData().size() + 1);
        metricTotalCell.setCellValue(total);

        rowIndex++;
    }

    if (isExportEmailNotificationData) {
        HSSFRow metricRow = worksheet.createRow(rowIndex);
        HSSFCell metricCell = metricRow.createCell(0);
        metricCell.setCellValue("Number of notification emails sent");
        Long total = 0L;
        for (int i = 0; i < data.getEmailNotificationData().size(); i++) {
            total += data.getEmailNotificationData().get(i);
            HSSFCell cell = metricRow.createCell(i + 1);
            cell.setCellValue(data.getEmailNotificationData().get(i));
        }
        HSSFCell metricTotalCell = metricRow.createCell(data.getEmailNotificationData().size() + 1);
        metricTotalCell.setCellValue(total);

        rowIndex++;
    }

    if (isExportPlfDownloadsData) {
        HSSFRow metricRow = worksheet.createRow(rowIndex);
        HSSFCell metricCell = metricRow.createCell(0);
        metricCell.setCellValue("PLF Downloads");
        Long total = 0L;
        for (int i = 0; i < data.getPlfDownloadsData().size(); i++) {
            total += data.getPlfDownloadsData().get(i);
            HSSFCell cell = metricRow.createCell(i + 1);
            cell.setCellValue(data.getPlfDownloadsData().get(i));
        }
        HSSFCell metricTotalCell = metricRow.createCell(data.getPlfDownloadsData().size() + 1);
        metricTotalCell.setCellValue(total);

        rowIndex++;
    }
    return workbook;
}

From source file:org.extremecomponents.table.view.ExtendXlsView.java

License:Apache License

private Map initStyles(HSSFWorkbook wb, short fontHeight) {
    Map result = new HashMap();
    HSSFCellStyle titleStyle = wb.createCellStyle();
    HSSFCellStyle textStyle = wb.createCellStyle();
    HSSFCellStyle boldStyle = wb.createCellStyle();
    HSSFCellStyle numericStyle = wb.createCellStyle();
    HSSFCellStyle numericStyleBold = wb.createCellStyle();
    HSSFCellStyle moneyStyle = wb.createCellStyle();
    HSSFCellStyle moneyStyleBold = wb.createCellStyle();
    HSSFCellStyle percentStyle = wb.createCellStyle();
    HSSFCellStyle percentStyleBold = wb.createCellStyle();

    result.put("titleStyle", titleStyle);
    result.put("textStyle", textStyle);
    result.put("boldStyle", boldStyle);
    result.put("numericStyle", numericStyle);
    result.put("numericStyleBold", numericStyleBold);
    result.put("moneyStyle", moneyStyle);
    result.put("moneyStyleBold", moneyStyleBold);
    result.put("percentStyle", percentStyle);
    result.put("percentStyleBold", percentStyleBold);

    HSSFDataFormat format = wb.createDataFormat();

    // Global fonts
    HSSFFont font = wb.createFont();// w  w w  .  ja v  a2  s  .co m
    font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
    font.setColor(HSSFColor.BLACK.index);
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setFontHeightInPoints(fontHeight);

    HSSFFont fontBold = wb.createFont();
    fontBold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontBold.setColor(HSSFColor.BLACK.index);
    fontBold.setFontName(HSSFFont.FONT_ARIAL);
    fontBold.setFontHeightInPoints(fontHeight);

    // Money Style
    moneyStyle.setFont(font);
    moneyStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    moneyStyle.setDataFormat(format.getFormat(moneyFormat));

    // Money Style Bold
    moneyStyleBold.setFont(fontBold);
    moneyStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    moneyStyleBold.setDataFormat(format.getFormat(moneyFormat));

    // Percent Style
    percentStyle.setFont(font);
    percentStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    percentStyle.setDataFormat(format.getFormat(percentFormat));

    // Percent Style Bold
    percentStyleBold.setFont(fontBold);
    percentStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    percentStyleBold.setDataFormat(format.getFormat(percentFormat));

    // Standard Numeric Style
    numericStyle.setFont(font);
    numericStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);

    // Standard Numeric Style Bold
    numericStyleBold.setFont(fontBold);
    numericStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT);

    // Title Style
    titleStyle.setFont(font);
    titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    titleStyle.setBottomBorderColor(HSSFColor.BLACK.index);
    titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    titleStyle.setLeftBorderColor(HSSFColor.BLACK.index);
    titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
    titleStyle.setRightBorderColor(HSSFColor.BLACK.index);
    titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
    titleStyle.setTopBorderColor(HSSFColor.BLACK.index);
    titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

    // Standard Text Style
    textStyle.setFont(font);
    textStyle.setWrapText(true);

    // Standard Text Style
    boldStyle.setFont(fontBold);
    boldStyle.setWrapText(true);

    return result;
}

From source file:org.gbif.portal.web.download.ExcelFileWriter.java

License:Open Source License

/**
 * Write out the delimited file./*w ww  .ja va  2 s.  c om*/
 * 
 * @throws IOException 
 */
public void writeFile() throws Exception {

    //Create FieldFormatter - the object that is i18n aware
    FieldFormatter ff = new FieldFormatter(downloadFields, messageSource, locale, hostUrl);

    //stick requested fields into list of strings
    List<String> requestedFieldNames = new ArrayList<String>();
    for (Field field : downloadFields)
        requestedFieldNames.add(field.getFieldName());

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet(messageSource.getMessage(sheetName, null, sheetName, locale));

    //create a titles style
    HSSFCellStyle titlesStyle = workbook.createCellStyle();
    titlesStyle.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
    titlesStyle.setFillBackgroundColor(HSSFColor.DARK_GREEN.index);
    HSSFFont font = workbook.createFont();
    font.setColor(HSSFColor.WHITE.index);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    titlesStyle.setFont(font);

    //write out the field headings
    for (int i = 0; i < downloadFields.size(); i++) {
        Field field = downloadFields.get(i);
        HSSFCell cell = getCell(sheet, 0, i);
        cell.setCellStyle(titlesStyle);
        setText(cell, messageSource.getMessage(field.getFieldI18nNameKey(), null, field.getFieldI18nNameKey(),
                locale));
    }

    //Create Results outputter - the object that knows about the required format
    ResultsOutputter resultsOutputter = new ExcelResultsOutputter(workbook, sheet, downloadFieldMappings,
            requestedFieldNames, ff);

    //check for citation
    if (addCitation && zipped) {
        DataResourceAuditor cro = new DataResourceAuditor();
        cro.setNextResultsOutputter(resultsOutputter);
        resultsOutputter = cro;
    }

    //pass both to the query manager
    outputProcess.process(resultsOutputter);

    //write out the workbook
    workbook.write(outputStream);
    outputStream.flush();

    //close the file stream
    if (zipped)
        ((ZipOutputStream) outputStream).closeEntry();

    //write out the citation
    if (addCitation && zipped) {
        downloadUtils.outputCitation(outputStream, (DataResourceAuditor) resultsOutputter, citationFileName,
                locale, hostUrl);
    }

    //write out the rights
    if (addRights && zipped) {
        downloadUtils.outputRights(outputStream, (DataResourceAuditor) resultsOutputter, rightsFileName, locale,
                hostUrl);
    }

    //log usage
    if (logEventId != null && resultsOutputter instanceof DataResourceAuditor) {
        downloadUtils.logDownloadUsage((DataResourceAuditor) resultsOutputter, logEventId);
    }

    //run secondary outputs
    if (zipped && secondaryDownloadOutputs != null) {
        downloadUtils.addSecondaryOutputs((ZipOutputStream) outputStream, secondaryDownloadOutputs);
    }

    //once returned rename the file to indicate the file has been written
    signalFileWriteComplete();
}

From source file:org.gbif.portal.web.view.ExcelView.java

License:Open Source License

/**
 * @see org.springframework.web.servlet.view.document.AbstractExcelView#buildExcelDocument(java.util.Map, org.apache.poi.hssf.usermodel.HSSFWorkbook, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*w ww  . j a  v a 2  s . c  o m*/
@SuppressWarnings("unchecked")
protected void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) {

    Locale locale = RequestContextUtils.getLocale(request);

    //create results sheet
    String sheetTitle = messageSource.getMessage(resultsSheetTitleI18nKey, null, locale);
    HSSFSheet resultsSheet = workbook.createSheet(sheetTitle);
    resultsSheet.setDefaultColumnWidth((short) (defaultColumnWidth));

    //create a titles style
    HSSFCellStyle titlesStyle = workbook.createCellStyle();
    titlesStyle.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
    titlesStyle.setFillBackgroundColor(HSSFColor.DARK_GREEN.index);
    HSSFFont font = workbook.createFont();
    font.setColor(HSSFColor.WHITE.index);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    titlesStyle.setFont(font);

    //create a hyperlink style
    HSSFCellStyle hyperlinkStyle = workbook.createCellStyle();
    HSSFFont hyperLinkFont = workbook.createFont();
    hyperLinkFont.setColor(HSSFColor.BLUE.index);
    hyperlinkStyle.setFont(hyperLinkFont);

    //reused cell reference
    HSSFCell cell = null;

    //write results sheet
    List<Field> fields = (List<Field>) request.getAttribute("requestedFields");
    List results = (List) request.getAttribute("results");

    int currentRow = 0;

    //column headings
    for (int i = 0; i < fields.size(); i++) {
        cell = getCell(resultsSheet, currentRow, i);
        cell.setCellStyle(titlesStyle);
        String title = messageSource.getMessage(fields.get(i).getFieldI18nNameKey(), null, locale);
        setText(cell, title);
        short titleLength = (short) (title.length() * charWidth);
        short columnWidth = resultsSheet.getColumnWidth((short) i);
        //update column width for long columns
        if (columnWidth < titleLength) {
            resultsSheet.setColumnWidth((short) i, (short) (titleLength));
        }
    }

    currentRow++;
    //results
    for (int i = 0; i < results.size(); i++) {

        Object result = results.get(i);

        for (int j = 0; j < fields.size(); j++) {

            Field field = fields.get(j);
            cell = getCell(resultsSheet, currentRow, j);

            try {
                short textWidth = defaultColumnWidth;
                String propertyValue = field.getRenderValue(request, messageSource, locale, result);
                if (propertyValue != null)
                    setText(cell, propertyValue);
                if (field instanceof UrlField) {
                    if (propertyValue != null && propertyValue.length() < urlMaxLength) {
                        String linkFormula = "HYPERLINK(\"" + propertyValue + "\")";
                        cell.setCellFormula(linkFormula);
                        cell.setCellStyle(hyperlinkStyle);
                    }
                }
                if (propertyValue != null) {

                    int textWidthInt = propertyValue.length() * charWidth;
                    if (textWidthInt > 32768) {
                        textWidth = Short.MAX_VALUE;
                    } else {
                        textWidth = (short) textWidthInt;
                    }
                }

                //update column width for long columns
                short columnWidth = resultsSheet.getColumnWidth((short) j);

                if (textWidth > columnWidth) {
                    resultsSheet.setColumnWidth((short) j, (short) textWidth);
                }
            } catch (Exception e) {
                logger.warn(e.getMessage(), e);
            }
        }
        currentRow++;
    }

    //set up details sheet
    HSSFSheet detailsSheet = workbook
            .createSheet(messageSource.getMessage(detailsSheetTitleI18nKey, null, locale));
    detailsSheet.setColumnWidth((short) 0, (short) 6000);
    detailsSheet.setColumnWidth((short) 1, (short) Short.MAX_VALUE);
    ;
    List<FilterDTO> filters = (List) request.getAttribute("filters");
    CriteriaDTO criteria = (CriteriaDTO) request.getAttribute("criteria");
    String query = FilterUtils.getQueryDescription(filters, criteria, messageSource, locale);
    cell = getCell(detailsSheet, 0, 0);
    cell.setCellStyle(titlesStyle);
    setText(cell, messageSource.getMessage("occurrence.search.description", null, locale));
    cell = getCell(detailsSheet, 0, 1);
    setText(cell, query);
    //add url for search
    cell = getCell(detailsSheet, 1, 0);
    cell.setCellStyle(titlesStyle);
    setText(cell, messageSource.getMessage("occurrence.search.url", null, locale));
    cell = getCell(detailsSheet, 1, 1);
    cell.setCellStyle(hyperlinkStyle);
    String url = "http://" + request.getHeader("host") + request.getContextPath() + "/occurrences/search.htm?"
            + CriteriaUtil.getUrl(criteria);
    setText(cell, url);
    //there is a formula limit in Excel of 255 characters
    if (url != null && url.length() < urlMaxLength) {
        String link = "HYPERLINK(\"" + url + "\")";
        cell.setCellFormula(link);
    }
    //add url for download page
    cell = getCell(detailsSheet, 2, 0);
    cell.setCellStyle(titlesStyle);
    setText(cell, messageSource.getMessage("occurrence.search.download.url", null, locale));
    cell = getCell(detailsSheet, 2, 1);
    cell.setCellStyle(hyperlinkStyle);
    String downloadurl = "http://" + request.getHeader("host") + request.getContextPath()
            + "/occurrences/download.htm?" + CriteriaUtil.getUrl(criteria);
    setText(cell, downloadurl);
    if (downloadurl != null && downloadurl.length() < urlMaxLength) {
        String link = "HYPERLINK(\"" + downloadurl + "\")";
        cell.setCellFormula(link);
    }
    //add date for this download
    cell = getCell(detailsSheet, 3, 0);
    cell.setCellStyle(titlesStyle);
    setText(cell, messageSource.getMessage("occurrence.search.download.date", null, locale));
    cell = getCell(detailsSheet, 3, 1);
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
    setText(cell, sdf.format(new Date(System.currentTimeMillis())));
}

From source file:org.goobi.production.flow.helper.SearchResultHelper.java

License:Open Source License

@SuppressWarnings("deprecation")
public HSSFWorkbook getResult(List<SearchColumn> columnList, String filter, String order,
        boolean showClosedProcesses, boolean showArchivedProjects) {
    List<SearchColumn> sortedList = new ArrayList<>(columnList.size());
    for (SearchColumn sc : columnList) {
        if (!sc.getTableName().startsWith("metadata")) {
            sortedList.add(sc);/*ww w.  j  a v  a2  s . c o  m*/
        }
    }
    for (SearchColumn sc : columnList) {
        if (sc.getTableName().startsWith("metadata")) {
            sortedList.add(sc);
        }
    }
    columnList = sortedList;

    @SuppressWarnings("rawtypes")
    List list = search(columnList, filter, order, showClosedProcesses, showArchivedProjects);

    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Search results");

    // create title row
    int titleColumnNumber = 0;
    HSSFRow title = sheet.createRow(0);
    int columnNumber = 0;
    for (SearchColumn sc : columnList) {
        HSSFCell titleCell = title.createCell(titleColumnNumber++);
        titleCell.setCellValue(Helper.getTranslation(sc.getValue()));
        HSSFCellStyle cellStyle = wb.createCellStyle();
        HSSFFont cellFont = wb.createFont();
        cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        cellStyle.setFont(cellFont);
        titleCell.setCellStyle(cellStyle);
    }

    int rowNumber = 1;
    for (Object obj : list) {
        Object[] objArr = (Object[]) obj;
        HSSFRow row = sheet.createRow(rowNumber++);
        columnNumber = 0;
        for (Object entry : objArr) {
            HSSFCell cell = row.createCell(columnNumber++);
            if (entry != null) {
                cell.setCellValue(((String) entry).replace("\"", ""));
            } else {
                cell.setCellValue("");
            }
        }
    }

    sheet.createFreezePane(0, 1);
    for (int i = 0; i < columnList.size(); i++) {
        sheet.autoSizeColumn(i);
        if (sheet.getColumnWidth(i) > 15000) {
            sheet.setColumnWidth(i, 15000);
        }
    }

    return wb;
}

From source file:org.grible.excel.ExcelFile.java

License:Open Source License

public String saveToFile(Table table, String filePath) {
    try {/*from  w w  w.  j  a va 2 s .c  o  m*/
        FileOutputStream fileOut = new FileOutputStream(filePath);
        Sheet worksheet = workbook.createSheet(table.getName());

        Row row1 = worksheet.createRow(0);

        Font keyFont = workbook.createFont();
        keyFont.setColor(HSSFColor.WHITE.index);
        keyFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        CellStyle keyCellStyle = workbook.createCellStyle();
        keyCellStyle.setFont(keyFont);
        keyCellStyle.setFillForegroundColor(HSSFColor.BLACK.index);
        keyCellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
        keyCellStyle.setAlignment(CellStyle.ALIGN_CENTER);

        Key[] keys = null;
        String[][] values = null;
        if (ServletHelper.isJson()) {
            keys = table.getTableJson().getKeys();
            values = table.getTableJson().getValues();
        } else {
            keys = table.getKeys();
            values = table.getValues();
        }
        for (int i = 0; i < keys.length; i++) {
            Cell cell = row1.createCell(i);
            cell.setCellValue(keys[i].getName());
            cell.setCellStyle(keyCellStyle);
        }

        for (int i = 0; i < values.length; i++) {
            Row excelRow = worksheet.createRow(i + 1);
            for (int j = 0; j < values[i].length; j++) {
                Cell cell = excelRow.createCell(j);
                cell.setCellValue(values[i][j]);
            }
        }

        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
        return "success";
    } catch (Exception e) {
        return e.getLocalizedMessage();
    }
}

From source file:org.hsh.bfr.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 {
                if (progress != null) {
                    progress.setVisible(true);
                    progress.setStringPainted(true);
                    progress.setString("Exporting Excel Datei...");
                    progress.setMinimum(0);
                    progress.setMaximum(myDB.getRowCount());
                    progress.setValue(0);
                }//from ww w.  j  a  v  a2 s  . c om

                HSSFWorkbook wb = new HSSFWorkbook();
                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:org.ivan.service.ExcelExporter.java

public <T extends Object> File createExcel(List<T> objects, String fileName, String sheetName) {

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet(sheetName);

    HSSFFont font = workbook.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFont(font);// www  .j  a  v a 2  s.c o m

    int cellNum = 0;
    int rowNum = 0;
    List<String> headers = getHeadersFromGetMethods(objects.get(0));
    Row row = sheet.createRow(rowNum++);
    for (int i = 0; i < headers.size(); i++) {
        String cup = headers.get(i);
        Cell cell = row.createCell(cellNum++);
        cell.setCellValue(cup);
        cell.setCellStyle(style);
    }
    for (T obj : objects) {

        cellNum = 0;
        List<String> parameters = getValuesRecursive(obj);
        row = sheet.createRow(rowNum++);
        for (String parameter : parameters) {

            Cell cell = row.createCell(cellNum++);
            cell.setCellValue(parameter);
            sheet.autoSizeColumn(cellNum);
        }

    }

    try {
        FileOutputStream out = new FileOutputStream(new File(fileName));
        workbook.write(out);
        out.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}