Example usage for org.apache.poi.hssf.usermodel HSSFSheet autoSizeColumn

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet autoSizeColumn

Introduction

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

Prototype

@Override
public void autoSizeColumn(int column) 

Source Link

Document

Adjusts the column width to fit the contents.

This process can be relatively slow on large sheets, so this should normally only be called once per column, at the end of your processing.

Usage

From source file:org.sourcecodemetrics.report.generators.RawDataGenerator.java

License:Open Source License

private static void generatePackages(IProject project, HSSFWorkbook workbook) throws IntrospectionException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
    HSSFSheet worksheet = workbook.createSheet("Raw package metrics");

    // generation of header row
    HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    for (int i = 0; i < packageMetrics.size(); i++) {
        String title = packageMetrics.get(i);
        HSSFCell cell = headerRow.createCell(i);
        cell.setCellValue(title);//from   w ww  . j  ava  2  s .c  om
    }

    // generation of package metrics
    for (IPackage pkg : project.getPackages()) {
        if (!pkg.isTests() && !pkg.getSourceFiles().isEmpty()) {

            HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());

            // writing out the name of the package
            HSSFCell nameCell = row.createCell(0);
            nameCell.setCellValue(pkg.getName());

            for (int i = 1; i < packageMetrics.size(); i++) {

                String propertyName = packageMetrics.get(i);
                Method getter = pkg.getClass().getMethod("get" + propertyName);
                Object metricValue = getter.invoke(pkg);

                HSSFCell cell = row.createCell(i);

                if (metricValue instanceof Integer) {
                    cell.setCellValue((Integer) metricValue);
                } else if (metricValue instanceof Double) {
                    cell.setCellValue((Double) metricValue);
                } else if (metricValue instanceof String) {
                    cell.setCellValue((String) metricValue);
                }
            }
        }
    }

    // autosizing the main column
    worksheet.autoSizeColumn(0);
}

From source file:org.sourcecodemetrics.report.generators.RawDataGenerator.java

License:Open Source License

private static void generateClasses(IProject project, HSSFWorkbook workbook) throws NoSuchMethodException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    HSSFSheet worksheet = workbook.createSheet("Raw class metrics");

    // generation of header row
    HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    for (int i = 0; i < classMetrics.size(); i++) {
        String title = classMetrics.get(i);
        HSSFCell cell = headerRow.createCell(i);
        cell.setCellValue(title);// w  ww .  jav  a 2 s  .  c om
    }

    // generation of class metrics
    for (IPackage pkg : project.getPackages()) {
        if (!pkg.isTests() && !pkg.getSourceFiles().isEmpty()) {
            for (ISourceFile sf : pkg.getSourceFiles()) {
                for (IClass c : sf.getClasses()) {
                    HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());

                    // writing out the name of the package
                    HSSFCell packageCell = row.createCell(0);
                    packageCell.setCellValue(pkg.getName());

                    // writing out the name of the class
                    HSSFCell classCell = row.createCell(1);
                    classCell.setCellValue(c.getName());

                    // writing values of the metrics
                    for (int i = 2; i < classMetrics.size(); i++) {
                        String propertyName = classMetrics.get(i);
                        Method getter = c.getClass().getMethod("get" + propertyName);
                        Object metricValue = getter.invoke(c);

                        HSSFCell cell = row.createCell(i);

                        if (metricValue instanceof Integer) {
                            cell.setCellValue((Integer) metricValue);
                        } else if (metricValue instanceof Double) {
                            cell.setCellValue((Double) metricValue);
                        } else if (metricValue instanceof String) {
                            cell.setCellValue((String) metricValue);
                        } else if (metricValue instanceof Boolean) {
                            Boolean value = (Boolean) metricValue;
                            cell.setCellValue(value ? 1 : 0);
                        }
                    }
                }
            }
        }
    }

    // autosizing the main columns
    for (int i = 0; i < 2; i++) {
        worksheet.autoSizeColumn(i);
    }
}

From source file:org.sourcecodemetrics.report.generators.RawDataGenerator.java

License:Open Source License

private static void generateMethods(IProject project, HSSFWorkbook workbook) throws NoSuchMethodException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    HSSFSheet worksheet = workbook.createSheet("Raw method metrics");

    // generation of header row
    HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    for (int i = 0; i < methodMetrics.size(); i++) {
        String title = methodMetrics.get(i);
        HSSFCell cell = headerRow.createCell(i);
        cell.setCellValue(title);//from w ww .  j ava 2 s . c o  m
    }

    // generation of method metrics
    for (IPackage pkg : project.getPackages()) {
        if (!pkg.isTests() && !pkg.getSourceFiles().isEmpty()) {
            if (!pkg.isTests() && !pkg.getSourceFiles().isEmpty()) {
                for (ISourceFile sf : pkg.getSourceFiles()) {
                    for (IClass c : sf.getClasses()) {
                        for (IMethod m : c.getMethods()) {
                            HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());

                            // writing out the name of the package
                            HSSFCell packageCell = row.createCell(0);
                            packageCell.setCellValue(pkg.getName());

                            // writing out the name of the class
                            HSSFCell classCell = row.createCell(1);
                            classCell.setCellValue(c.getName());

                            // writing out the name of the method
                            HSSFCell methodCell = row.createCell(2);
                            methodCell.setCellValue(m.getName());

                            for (int i = 3; i < methodMetrics.size(); i++) {
                                String propertyName = methodMetrics.get(i);
                                Method getter = m.getClass().getMethod("get" + propertyName);
                                Object metricValue = getter.invoke(m);

                                HSSFCell cell = row.createCell(i);

                                if (metricValue instanceof Integer) {
                                    cell.setCellValue((Integer) metricValue);
                                } else if (metricValue instanceof Double) {
                                    cell.setCellValue((Double) metricValue);
                                } else if (metricValue instanceof String) {
                                    cell.setCellValue((String) metricValue);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    // autosizing the main columns
    for (int i = 0; i < 3; i++) {
        worksheet.autoSizeColumn(i);
    }
}

From source file:org.sourcecodemetrics.report.generators.ReportGeneratorImpl.java

License:Open Source License

@Override
public void generateReport(IProject project, String filePath) {
    try {/*ww  w  . j  a va 2  s  . c  om*/
        FileOutputStream fileOut = new FileOutputStream(filePath);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet worksheet = workbook.createSheet("Source Code Metrics");

        // creation of the header row
        whiteStyle = workbook.createCellStyle();
        whiteStyle.setFillForegroundColor(HSSFColor.WHITE.index);
        whiteStyle.setFillBackgroundColor(HSSFColor.WHITE.index);
        whiteStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        dottedBlueStyle = workbook.createCellStyle();
        dottedBlueStyle.setFillForegroundColor(HSSFColor.BLACK.index);
        dottedBlueStyle.setFillBackgroundColor(HSSFColor.AQUA.index);
        dottedBlueStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);

        blueStyle = workbook.createCellStyle();
        blueStyle.setFillForegroundColor(HSSFColor.AQUA.index);
        blueStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        HSSFFont font = workbook.createFont();
        font.setColor(HSSFColor.RED.index);
        redBlueStyle = workbook.createCellStyle();
        redBlueStyle.setFillForegroundColor(HSSFColor.AQUA.index);
        redBlueStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        redBlueStyle.setFont(font);

        dottedYellowStyle = workbook.createCellStyle();
        dottedYellowStyle.setFillForegroundColor(HSSFColor.BLACK.index);
        dottedYellowStyle.setFillBackgroundColor(HSSFColor.YELLOW.index);
        dottedYellowStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);

        yellowStyle = workbook.createCellStyle();
        yellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index);
        yellowStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        redYellowStyle = workbook.createCellStyle();
        redYellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index);
        redYellowStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        redYellowStyle.setFont(font);

        dottedStyle = workbook.createCellStyle();
        dottedStyle.setFillForegroundColor(HSSFColor.BLACK.index);
        dottedStyle.setFillBackgroundColor(HSSFColor.WHITE.index);
        dottedStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);

        redWhiteStyle = workbook.createCellStyle();
        redWhiteStyle.setFillForegroundColor(HSSFColor.WHITE.index);
        redWhiteStyle.setFillBackgroundColor(HSSFColor.WHITE.index);
        redWhiteStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        redWhiteStyle.setFont(font);

        HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
        for (int i = 0; i < headings.size(); i++) {
            String title = headings.get(i);
            HSSFCell cell = headerRow.createCell(i);
            cell.setCellValue(title);
            cell.setCellStyle(whiteStyle);
        }

        for (IPackage ip : project.getPackages()) {
            if (!ip.isTests() && !ip.getSourceFiles().isEmpty()) {
                PackageGenerator.generate(ip, worksheet, workbook);
            }
        }

        // adjusting first three columns
        try {
            for (int i = 0; i < 3; i++) {
                worksheet.autoSizeColumn(i);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            logger.log(Level.SEVERE, "Exception when trying to adjust columns", e);
        }

        // setting constant width to other columns
        for (int i = 3; i < headings.size(); i++) {
            worksheet.setColumnWidth(i, 2000);
        }

        // writing out the statistics to the report
        StatisticsGenerator.generateStatistics(project, workbook);

        // writing the raw data to the report
        RawDataGenerator.generateRawData(project, workbook);

        worksheet.createFreezePane(3, 1);

        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:org.sourcecodemetrics.report.generators.StatisticsGenerator.java

License:Open Source License

public static void generateStatistics(IProject project, HSSFWorkbook workbook) {

    if (blueStyle == null) {
        blueStyle = workbook.createCellStyle();
        blueStyle.setFillForegroundColor(HSSFColor.AQUA.index);
        blueStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    }//from ww  w  .j ava 2  s  .c om

    HSSFSheet worksheet = workbook.createSheet("Statistics");

    // creation of the header row
    HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    HSSFFont font = workbook.createFont();
    font.setColor(HSSFColor.WHITE.index);
    for (int i = 0; i < headings.size(); i++) {
        String title = headings.get(i);
        HSSFCell cell = headerRow.createCell(i);
        cell.setCellValue(title);
        cell.setCellStyle(blueStyle);
    }

    // writing out all of the values of the metrics
    HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    HSSFCell cell = row.createCell(0);
    cell.setCellValue("A");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Abstractness");
    cell = row.createCell(3);
    if (project.getPackageAMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageAMin());
    }
    cell = row.createCell(4);
    if (project.getPackageAMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageAMax());
    }
    cell = row.createCell(5);
    if (project.getPackageAAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageAAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("AC");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Afferent Coupling");
    cell = row.createCell(3);
    if (project.getPackageACMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageACMin());
    }
    cell = row.createCell(4);
    if (project.getPackageACMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageACMax());
    }
    cell = row.createCell(5);
    if (project.getPackageACAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageACAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("C");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Coverage");
    cell = row.createCell(3);
    if (project.getPackageCoverageMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageCoverageMin());
    }
    cell = row.createCell(4);
    if (project.getPackageCoverageMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageCoverageMax());
    }
    cell = row.createCell(5);
    if (project.getPackageCoverageAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageCoverageAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("D");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Distance");
    cell = row.createCell(3);
    if (project.getPackageDMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageDMin());
    }
    cell = row.createCell(4);
    if (project.getPackageDMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageDMax());
    }
    cell = row.createCell(5);
    if (project.getPackageDAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageDAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("EC");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Efferent Coupling");
    cell = row.createCell(3);
    if (project.getPackageECMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageECMin());
    }
    cell = row.createCell(4);
    if (project.getPackageECMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageECMax());
    }
    cell = row.createCell(5);
    if (project.getPackageECAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageECAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("I");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Instability");
    cell = row.createCell(3);
    if (project.getPackageIMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageIMin());
    }
    cell = row.createCell(4);
    if (project.getPackageIMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageIMax());
    }
    cell = row.createCell(5);
    if (project.getPackageIAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageIAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOC");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Code");
    cell = row.createCell(3);
    if (project.getPackageLocMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageLocMin());
    }
    cell = row.createCell(4);
    if (project.getPackageLocMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageLocMax());
    }
    cell = row.createCell(6);
    if (project.getLOC() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getLOC());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOCm");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Comments");
    cell = row.createCell(3);
    if (project.getPackageLocmMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageLocmMin());
    }
    cell = row.createCell(4);
    if (project.getPackageLocmMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageLocmMax());
    }
    cell = row.createCell(6);
    if (project.getLOCm() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getLOCm());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NCP");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Classes in Package");
    cell = row.createCell(3);
    if (project.getPackageNCPMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNCPMin());
    }
    cell = row.createCell(4);
    if (project.getPackageNCPMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNCPMax());
    }
    cell = row.createCell(6);
    if (project.getPackageNCPSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNCPSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NIP");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Interfaces in Package");
    cell = row.createCell(3);
    if (project.getPackageNIPMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNIPMin());
    }
    cell = row.createCell(4);
    if (project.getPackageNIPMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNIPMax());
    }
    cell = row.createCell(6);
    if (project.getPackageNIPSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNIPSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Loose Class Coupling");
    cell = row.createCell(3);
    if (project.getClassLCCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCCMax());
    }
    cell = row.createCell(4);
    if (project.getClassLCCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCCMin());
    }
    cell = row.createCell(5);
    if (project.getClassLCCAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCCAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM1");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 1");
    cell = row.createCell(3);
    if (project.getClassLCOM1Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM1Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM1Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM1Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM1Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM1Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM2");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 2");
    cell = row.createCell(3);
    if (project.getClassLCOM2Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM2Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM2Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM2Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM2Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM2Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM3");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 3");
    cell = row.createCell(3);
    if (project.getClassLCOM3Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM3Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM3Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM3Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM3Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM3Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM4");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 4");
    cell = row.createCell(3);
    if (project.getClassLCOM4Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM4Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM4Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM4Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM4Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM4Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM5");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 5");
    cell = row.createCell(3);
    if (project.getClassLCOM5Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM5Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM5Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM5Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM5Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM5Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Code");
    cell = row.createCell(3);
    if (project.getClassLOCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLOCMin());
    }
    cell = row.createCell(4);
    if (project.getClassLOCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLOCMax());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOCm");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Comments");
    cell = row.createCell(3);
    if (project.getClassLOCmMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLOCmMin());
    }
    cell = row.createCell(4);
    if (project.getClassLOCmMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLOCmMax());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NAK");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number of Assertions per KLOC");
    cell = row.createCell(3);
    if (project.getClassNAKMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNAKMin());
    }
    cell = row.createCell(4);
    if (project.getClassNAKMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNAKMax());
    }
    cell = row.createCell(5);
    if (project.getClassNAKAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNAKAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Children");
    cell = row.createCell(3);
    if (project.getClassNOCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOCMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOCMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOCSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOCSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOF");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Fields");
    cell = row.createCell(3);
    if (project.getClassNOFMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOFMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOFMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOFMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOFSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOFSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOM");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Methods");
    cell = row.createCell(3);
    if (project.getClassNOMMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOMMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOMMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOMMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOMSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOMSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOSF");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Static Fields");
    cell = row.createCell(3);
    if (project.getClassNOSFMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSFMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOSFMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSFMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOSFSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSFSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOSM");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Static Methods");
    cell = row.createCell(3);
    if (project.getClassNOSMMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSMMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOSMMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSMMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOSMSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSMSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NTM");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number of Test Methods");
    cell = row.createCell(3);
    if (project.getClassNTMMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNTMMin());
    }
    cell = row.createCell(4);
    if (project.getClassNTMMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNTMMax());
    }
    cell = row.createCell(6);
    if (project.getClassNTMSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNTMSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("TCC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Tight Class Coupling");
    cell = row.createCell(3);
    if (project.getClassTCCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassTCCMin());
    }
    cell = row.createCell(4);
    if (project.getClassTCCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassTCCMax());
    }
    cell = row.createCell(5);
    if (project.getClassTCCAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassTCCAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("WMC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Weighted Method Count");
    cell = row.createCell(3);
    if (project.getClassWMCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassWMCMin());
    }
    cell = row.createCell(4);
    if (project.getClassWMCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassWMCMax());
    }
    cell = row.createCell(6);
    if (project.getClassWMCSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassWMCSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOC");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Code");
    cell = row.createCell(3);
    if (project.getMethodLOCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodLOCMin());
    }
    cell = row.createCell(4);
    if (project.getMethodLOCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodLOCMax());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOCm");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Comments");
    cell = row.createCell(3);
    if (project.getMethodLOCmMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodLOCmMin());
    }
    cell = row.createCell(4);
    if (project.getMethodLOCmMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodLOCmMax());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NBD");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("Nested Block Depth");
    cell = row.createCell(3);
    if (project.getMethodNBDMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNBDMin());
    }
    cell = row.createCell(4);
    if (project.getMethodNBDMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNBDMax());
    }
    cell = row.createCell(5);
    if (project.getMethodNBDAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNBDAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOP");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Parameters");
    cell = row.createCell(3);
    if (project.getMethodNOPMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNOPMin());
    }
    cell = row.createCell(4);
    if (project.getMethodNOPMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNOPMax());
    }
    cell = row.createCell(6);
    if (project.getMethodNOPSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNOPSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("VG");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("McGabe's Cyclomatic Complexity");
    cell = row.createCell(3);
    if (project.getMethodVGMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodVGMin());
    }
    cell = row.createCell(4);
    if (project.getMethodVGMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodVGMax());
    }
    cell = row.createCell(5);
    if (project.getMethodVGAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodVGAvg());
    }

    // adjusting first three columns
    try {
        for (int i = 0; i < 7; i++) {
            worksheet.autoSizeColumn(i);
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        logger.log(Level.SEVERE, "Exception when trying to adjust columns", e);
    }

    // setting constant width to other columns
    for (int i = 3; i < 7; i++) {
        worksheet.setColumnWidth(i, 2700);
    }
}

From source file:org.tdl.vireo.controller.SubmissionController.java

@SuppressWarnings("unchecked")
private void processBatchExport(HttpServletResponse response, User user, String packagerName,
        NamedSearchFilterGroup filter) throws IOException {
    AbstractPackager<?> packager = packagerUtility.getPackager(packagerName);

    List<SubmissionListColumn> columns = filter.getColumnsFlag() ? filter.getSavedColumns()
            : user.getSubmissionViewColumns();
    switch (packagerName.trim()) {
    case "Excel":
        List<Submission> submissions = submissionRepo.batchDynamicSubmissionQuery(filter, columns);

        HSSFWorkbook workbook = new HSSFWorkbook();

        HSSFSheet worksheet = workbook.createSheet();

        int rowCount = 0;

        HSSFRow header = worksheet.createRow(rowCount++);

        for (int i = 0; i < columns.size(); i++) {
            SubmissionListColumn column = columns.get(i);
            header.createCell(i).setCellValue(column.getTitle());
        }/* w  ww .j  a va2  s  .c  om*/

        for (Submission submission : submissions) {
            ExportPackage exportPackage = packagerUtility.packageExport(packager, submission, columns);
            if (exportPackage.isMap()) {
                Map<String, String> rowData = (Map<String, String>) exportPackage.getPayload();
                HSSFRow row = worksheet.createRow(rowCount++);
                for (int i = 0; i < columns.size(); i++) {
                    SubmissionListColumn column = columns.get(i);
                    row.createCell(i).setCellValue(rowData.get(column.getTitle()));
                }
            }
        }

        for (int i = 0; i < columns.size(); i++) {
            worksheet.autoSizeColumn(i);
        }

        response.setContentType(packager.getMimeType());
        response.setHeader("Content-Disposition",
                "inline; filename=" + packagerName + "." + packager.getFileExtension());
        workbook.write(response.getOutputStream());

        break;
    case "MarcXML21":
    case "DSpaceMETS":
    case "ProQuest":
        try {
            ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());

            // TODO: need a more dynamic way to achieve this
            if (packagerName.equals("ProQuest")) {
                // TODO: add filter for UMI Publication true
            }

            for (Submission submission : submissionRepo.batchDynamicSubmissionQuery(filter, columns)) {
                ExportPackage exportPackage = packagerUtility.packageExport(packager, submission);

                if (exportPackage.isFile()) {
                    File exportFile = (File) exportPackage.getPayload();
                    if (packagerName.equals("MarcXML21")) {
                        zos.putNextEntry(new ZipEntry("MarcXML21/" + exportFile.getName()));
                    } else {
                        zos.putNextEntry(new ZipEntry(exportFile.getName()));
                    }
                    zos.write(Files.readAllBytes(exportFile.toPath()));
                    zos.closeEntry();
                }

            }
            zos.close();

            response.setContentType(packager.getMimeType());
            response.setHeader("Content-Disposition",
                    "inline; filename=" + packagerName + "." + packager.getFileExtension());
        } catch (Exception e) {
            response.setContentType("application/json");
            ApiResponse apiResponse = new ApiResponse(ERROR, "Something went wrong with the export!");
            PrintWriter out = response.getWriter();
            out.print(objectMapper.writeValueAsString(apiResponse));
            out.close();
        }
        break;
    case "DSpaceSimple":
        try {
            ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
            for (Submission submission : submissionRepo.batchDynamicSubmissionQuery(filter, columns)) {
                String submissionName = "submission_" + submission.getId() + "/";
                zos.putNextEntry(new ZipEntry(submissionName));

                StringBuilder contentsText = new StringBuilder();
                ExportPackage exportPackage = packagerUtility.packageExport(packager, submission);

                if (exportPackage.isMap()) {
                    for (Map.Entry<String, File> fileEntry : ((Map<String, File>) exportPackage.getPayload())
                            .entrySet()) {
                        zos.putNextEntry(new ZipEntry(submissionName + fileEntry.getKey()));
                        contentsText.append("MD " + fileEntry.getKey() + "\n");
                        zos.write(Files.readAllBytes(fileEntry.getValue().toPath()));
                        zos.closeEntry();
                    }
                }

                // LICENSES
                for (FieldValue ldfv : submission.getLicenseDocumentFieldValues()) {
                    Path path = assetService.getAssetsAbsolutePath(ldfv.getValue());
                    byte[] fileBytes = Files.readAllBytes(path);
                    zos.putNextEntry(new ZipEntry(submissionName + ldfv.getFileName()));
                    contentsText.append(ldfv.getFileName() + " bundle:LICENSE\n");
                    zos.write(fileBytes);
                    zos.closeEntry();
                }

                // PRIMARY_DOC
                FieldValue primaryDoc = submission.getPrimaryDocumentFieldValue();
                Path path = assetService.getAssetsAbsolutePath(primaryDoc.getValue());
                byte[] fileBytes = Files.readAllBytes(path);
                zos.putNextEntry(new ZipEntry(submissionName + primaryDoc.getFileName()));
                contentsText.append(primaryDoc.getFileName() + "  bundle:CONTENT  primary:true\n");
                zos.write(fileBytes);
                zos.closeEntry();

                // SUPPLEMENTAL_DOCS
                // supplemental, source, administrative
                // ask Stephanie about administrative
                List<FieldValue> supplDocs = submission.getSupplementalAndSourceDocumentFieldValues();
                for (FieldValue supplDoc : supplDocs) {
                    Path supplPath = assetService.getAssetsAbsolutePath(supplDoc.getValue());
                    byte[] supplFileBytes = Files.readAllBytes(supplPath);
                    zos.putNextEntry(new ZipEntry(submissionName + supplDoc.getFileName()));
                    contentsText.append(supplDoc.getFileName() + "  bundle:CONTENT\n");
                    zos.write(supplFileBytes);
                    zos.closeEntry();
                }

                // CONTENTS_FILE
                zos.putNextEntry(new ZipEntry(submissionName + "contents"));
                zos.write(contentsText.toString().getBytes());
                zos.closeEntry();

                zos.closeEntry();
            }
            zos.close();

            response.setContentType(packager.getMimeType());
            response.setHeader("Content-Disposition",
                    "inline; filename=" + packagerName + "." + packager.getFileExtension());
        } catch (Exception e) {
            response.setContentType("application/json");

            ApiResponse apiResponse = new ApiResponse(ERROR, "Something went wrong with the export!");

            PrintWriter out = response.getWriter();
            out.print(objectMapper.writeValueAsString(apiResponse));
            out.close();
        }
        break;

    default:
        response.setContentType("application/json");

        ApiResponse apiResponse = new ApiResponse(ERROR, "No packager " + packagerName + " found!");
        PrintWriter out = response.getWriter();
        out.print(objectMapper.writeValueAsString(apiResponse));
        out.close();
    }

    response.getOutputStream().close();
}

From source file:org.whitley.object.handler.TutorialHandler.java

/**
 * makeScheduleList method.//from w ww.  j a v a 2  s  .  co  m
 * Write excel spreadsheet containing information on tutorial schedule
 * @param workbook: Target excel workbook
 * @param timetable: Filled out Timetable
 * @param sheetName: Name of the Sheet
 * @since 1.0
 */
private void makeScheduleList(HSSFWorkbook workbook, ArrayList<TuteTable> timetable, String sheetName) {
    int row_counter = 0;
    HSSFSheet stream_Sheet = workbook.createSheet(sheetName);
    HSSFRow stream_row;
    HSSFCell stream_cell;
    ArrayList<String> data;
    HSSFFormulaEvaluator.evaluateAllFormulaCells(workbook);
    for (TuteTable stream : timetable) {
        data = new ArrayList<>();
        String stream_day = stream.getStream().getStream_day().toString();
        data.add(stream_day);
        String stream_start = stream.getStream().getStream_start();
        data.add(stream_start);
        String stream_end = stream.getStream().getStream_end();
        data.add(stream_end);
        String stream_code = stream.getSubject().getCode();
        data.add(stream_code);
        String stream_name = stream.getSubject().getName();
        data.add(stream_name);
        String stream_room = stream.getRoom().getRoomName();
        data.add(stream_room);

        stream_row = stream_Sheet.createRow(row_counter);
        row_counter++;
        for (int i = 0; i < data.size() - 1; i++) {
            stream_cell = stream_row.createCell(i);
            stream_cell.setCellValue(data.get(i));
        }
    }
    for (int i = 0; i < 6; i++) {
        stream_Sheet.autoSizeColumn(i);
    }

}

From source file:org.whitley.object.handler.TutorialHandler.java

/**
/**//from  w w w.j  a v a2  s . co m
 * makeTutorialDetailList method.
 * Write excel spreadsheet containing information on tutorial details.
 * @param workbook: Target excel workbook
 * @param timetable: Filled out Timetable
 * @param sheetName: Name of the Sheet
 * @since 1.0
 */
private void makeTutorialDetailList(HSSFWorkbook workbook, ArrayList<TuteTable> timetable, String sheetName) {
    int row_counter = 0;
    HSSFSheet stream_Sheet = workbook.createSheet(sheetName);
    HSSFRow stream_row;
    HSSFCell stream_cell;
    ArrayList<String> data;
    HSSFFormulaEvaluator.evaluateAllFormulaCells(workbook);
    for (TuteTable stream : timetable) {
        stream_row = stream_Sheet.createRow(row_counter);
        stream_cell = stream_row.createCell(0);
        stream_cell.setCellValue("Subject Code");
        stream_cell = stream_row.createCell(1);
        stream_cell.setCellValue(stream.getSubject().getCode());
        row_counter++;
        stream_row = stream_Sheet.createRow(row_counter);
        stream_cell = stream_row.createCell(0);
        stream_cell.setCellValue("Subject Name");
        stream_cell = stream_row.createCell(1);
        stream_cell.setCellValue(stream.getSubject().getName());
        row_counter++;
        stream_row = stream_Sheet.createRow(row_counter);
        stream_cell = stream_row.createCell(0);
        stream_cell.setCellValue("Subject Tutor");
        stream_cell = stream_row.createCell(1);
        stream_cell.setCellValue(stream.getSubject().getTutor().getName());
        row_counter++;
        stream_row = stream_Sheet.createRow(row_counter);
        stream_cell = stream_row.createCell(0);
        stream_cell.setCellValue("Stream Time");
        stream_cell = stream_row.createCell(1);
        stream_cell.setCellValue(stream.getStream().toFormattedString());
        row_counter++;
        stream_row = stream_Sheet.createRow(row_counter);
        stream_cell = stream_row.createCell(0);
        stream_cell.setCellValue("Tutorial Room");
        stream_cell = stream_row.createCell(1);
        stream_cell.setCellValue(stream.getRoom().getRoomName());
        row_counter++;
        for (TuteStudent student : stream.getSubject().getStudents()) {
            stream_row = stream_Sheet.createRow(row_counter);
            stream_cell = stream_row.createCell(1);
            stream_cell.setCellValue(student.toString());
            row_counter++;
        }
        row_counter++;

    }
    stream_Sheet.autoSizeColumn(0);
    stream_Sheet.autoSizeColumn(1);
}

From source file:pe.gob.mef.gescon.web.ui.BaseLegalMB.java

public void postProcessXLS(Object document) {
    HSSFWorkbook wb = (HSSFWorkbook) document;
    HSSFSheet sheet = wb.getSheetAt(0);

    //Para los datos
    HSSFCellStyle centerStyle = wb.createCellStyle();
    centerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

    HSSFCellStyle centerGrayStyle = wb.createCellStyle();
    centerGrayStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    centerGrayStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    centerGrayStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    HSSFCellStyle grayBG = wb.createCellStyle();
    grayBG.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    grayBG.setFillPattern(CellStyle.SOLID_FOREGROUND);
    int i = 1;/*from  w w  w.  ja v  a 2 s  .c om*/
    for (BaseLegal b : this.getListaBaseLegal()) {
        HSSFRow row = sheet.getRow(i);
        for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
            HSSFCell cell = row.getCell(j);
            if (i % 2 == 0) {
                if (j > 0) {
                    cell.setCellStyle(centerGrayStyle);
                } else {
                    cell.setCellStyle(grayBG);
                    cell.setCellValue(b.getVnumero());
                }
            } else {
                if (j > 0) {
                    cell.setCellStyle(centerStyle);
                } else {
                    cell.setCellValue(b.getVnumero());
                }
            }
        }
        i++;
    }

    // Para la cabecera
    HSSFRow header = sheet.getRow(0);
    HSSFCellStyle headerStyle = wb.createCellStyle();
    HSSFFont font = wb.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
    headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
    headerStyle.setFont(font);

    for (int j = 0; j < header.getPhysicalNumberOfCells(); j++) {
        HSSFCell cell = header.getCell(j);
        cell.setCellStyle(headerStyle);
        sheet.autoSizeColumn(j);
    }
}

From source file:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java

public void postProcessXLS(Object document) {
    HSSFWorkbook wb = (HSSFWorkbook) document;
    HSSFSheet sheet = wb.getSheetAt(0);

    //Para los datos
    HSSFCellStyle centerStyle = wb.createCellStyle();
    centerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

    HSSFCellStyle centerGrayStyle = wb.createCellStyle();
    centerGrayStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    centerGrayStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    centerGrayStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    HSSFCellStyle grayBG = wb.createCellStyle();
    grayBG.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    grayBG.setFillPattern(CellStyle.SOLID_FOREGROUND);
    int i = 1;//from  w w w . j a  v  a2 s  .co m
    for (Conocimiento c : this.getListaBuenaPractica()) {
        HSSFRow row = sheet.getRow(i);
        for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
            HSSFCell cell = row.getCell(j);
            if (i % 2 == 0) {
                if (j > 0) {
                    cell.setCellStyle(centerGrayStyle);
                } else {
                    cell.setCellStyle(grayBG);
                    cell.setCellValue(c.getVtitulo());
                }
            } else {
                if (j > 0) {
                    cell.setCellStyle(centerStyle);
                } else {
                    cell.setCellValue(c.getVtitulo());
                }
            }
        }
        i++;
    }

    // Para la cabecera
    HSSFRow header = sheet.getRow(0);
    HSSFCellStyle headerStyle = wb.createCellStyle();
    HSSFFont font = wb.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
    headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
    headerStyle.setFont(font);

    for (int j = 0; j < header.getPhysicalNumberOfCells(); j++) {
        HSSFCell cell = header.getCell(j);
        cell.setCellStyle(headerStyle);
        sheet.autoSizeColumn(j);
    }
}