Example usage for org.apache.poi.ss.usermodel BorderStyle THIN

List of usage examples for org.apache.poi.ss.usermodel BorderStyle THIN

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel BorderStyle THIN.

Prototype

BorderStyle THIN

To view the source code for org.apache.poi.ss.usermodel BorderStyle THIN.

Click Source Link

Document

Thin border

Usage

From source file:com.netsteadfast.greenstep.bsc.command.TimeSeriesAnalysisExcelCommand.java

License:Apache License

private void putTables(XSSFWorkbook wb, XSSFSheet sh, Context context) throws Exception {

    TsaVO tsa = (TsaVO) context.get("tsa");
    @SuppressWarnings("unchecked")
    List<BbTsaMaCoefficients> coefficients = (List<BbTsaMaCoefficients>) context.get("coefficients");
    @SuppressWarnings("unchecked")
    List<TimeSeriesAnalysisResult> tsaResults = (List<TimeSeriesAnalysisResult>) context.get("tsaResults");

    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);//from   w  w  w .  j  a va  2 s. com

    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#f5f5f5")));
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellHeadStyle.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle.setBorderTop(BorderStyle.THIN);
    cellHeadStyle.setBorderRight(BorderStyle.THIN);
    cellHeadStyle.setBorderLeft(BorderStyle.THIN);
    cellHeadStyle.setFont(cellHeadFont);

    XSSFCellStyle cellHeadStyleBlank = wb.createCellStyle();
    cellHeadStyleBlank.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#ffffff")));
    cellHeadStyleBlank.setFont(cellHeadFont);

    XSSFCellStyle cellHeadStyle2 = wb.createCellStyle();
    cellHeadStyle2.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#ffffff")));
    cellHeadStyle2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellHeadStyle2.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle2.setBorderTop(BorderStyle.THIN);
    cellHeadStyle2.setBorderRight(BorderStyle.THIN);
    cellHeadStyle2.setBorderLeft(BorderStyle.THIN);

    sh.setColumnWidth(0, 12000);

    int row = 0;

    // ==============================================================
    Row nowRow = sh.createRow(row);
    Cell cellTitle = nowRow.createCell(0);
    cellTitle.setCellStyle(cellHeadStyleBlank);
    cellTitle.setCellValue("Forecast analysis - " + context.get("visionName"));

    row++;

    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell0a = nowRow.createCell(0);
    cell0a.setCellStyle(cellHeadStyleBlank);
    cell0a.setCellValue("Frequency: " + context.get("frequencyName") + " , Date range: " + context.get("date1")
            + " - " + context.get("date2") + " , " + "Measure data type for: " + context.get("dataFor") + " , "
            + context.get("organizationName") + context.get("employeeName"));

    row++;

    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell0b = nowRow.createCell(0);
    cell0b.setCellStyle(cellHeadStyleBlank);
    cell0b.setCellValue("");

    row++;

    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell1 = nowRow.createCell(0);
    cell1.setCellStyle(cellHeadStyleBlank);
    cell1.setCellValue("Param infornation");

    row++;

    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell2_a = nowRow.createCell(0);
    cell2_a.setCellStyle(cellHeadStyle);
    cell2_a.setCellValue("Item");
    Cell cell2_b = nowRow.createCell(1);
    cell2_b.setCellStyle(cellHeadStyle);
    cell2_b.setCellValue("Value");

    row++;

    // ==============================================================   
    nowRow = sh.createRow(row);
    Cell cell3_a = nowRow.createCell(0);
    cell3_a.setCellStyle(cellHeadStyle2);
    cell3_a.setCellValue("Param name");
    Cell cell3_b = nowRow.createCell(1);
    cell3_b.setCellStyle(cellHeadStyle2);
    cell3_b.setCellValue(tsa.getName());

    row++;

    // ==============================================================   
    nowRow = sh.createRow(row);
    Cell cell4_a = nowRow.createCell(0);
    cell4_a.setCellStyle(cellHeadStyle2);
    cell4_a.setCellValue("Integration order");
    Cell cell4_b = nowRow.createCell(1);
    cell4_b.setCellStyle(cellHeadStyle2);
    cell4_b.setCellValue(tsa.getIntegrationOrder());

    row++;

    // ==============================================================   
    nowRow = sh.createRow(row);
    Cell cell5_a = nowRow.createCell(0);
    cell5_a.setCellStyle(cellHeadStyle2);
    cell5_a.setCellValue("Forecast next");
    Cell cell5_b = nowRow.createCell(1);
    cell5_b.setCellStyle(cellHeadStyle2);
    cell5_b.setCellValue(tsa.getForecastNext());

    row++;

    // ==============================================================   
    nowRow = sh.createRow(row);
    Cell cell6_a = nowRow.createCell(0);
    cell6_a.setCellStyle(cellHeadStyle2);
    cell6_a.setCellValue("Description");
    Cell cell6_b = nowRow.createCell(1);
    cell6_b.setCellStyle(cellHeadStyle2);
    cell6_b.setCellValue(StringUtils.defaultString(tsa.getDescription()).trim());

    row++;

    // ==============================================================
    for (int i = 0; coefficients != null && i < coefficients.size(); i++) {
        BbTsaMaCoefficients coefficient = coefficients.get(i);
        nowRow = sh.createRow(row);
        Cell cell7x_a = nowRow.createCell(0);
        cell7x_a.setCellStyle(cellHeadStyle2);
        cell7x_a.setCellValue("Coefficient (" + (i + 1) + ")");
        Cell cell7x_b = nowRow.createCell(1);
        cell7x_b.setCellStyle(cellHeadStyle2);
        cell7x_b.setCellValue(String.valueOf(coefficient.getSeqValue()));

        row++;
    }

    // ==============================================================

    nowRow = sh.createRow(row);
    Cell cellTitle3a = nowRow.createCell(0);
    cellTitle3a.setCellStyle(cellHeadStyleBlank);
    cellTitle3a.setCellValue("");

    row++;

    // 
    nowRow = sh.createRow(row);
    Cell cellTitle2a = nowRow.createCell(0);
    cellTitle2a.setCellStyle(cellHeadStyle);
    cellTitle2a.setCellValue("KPIs");

    int j = 1;
    TimeSeriesAnalysisResult firstResult = tsaResults.get(0);
    for (int i = 0; i < firstResult.getKpi().getDateRangeScores().size(); i++) {
        DateRangeScoreVO dateRangeScore = firstResult.getKpi().getDateRangeScores().get(i);
        Cell cellTitle2a_dateRange = nowRow.createCell(j);
        j++;
        cellTitle2a_dateRange.setCellStyle(cellHeadStyle);
        cellTitle2a_dateRange.setCellValue(dateRangeScore.getDate());
    }
    for (int i = 0; i < firstResult.getForecastNext().size(); i++) {
        Cell cellTitle2a_dateRange = nowRow.createCell(j);
        j++;
        cellTitle2a_dateRange.setCellStyle(cellHeadStyle);
        cellTitle2a_dateRange.setCellValue("next(" + (i + 1) + ")");
    }

    row++;

    //  Date Range score  Forecast next score
    for (int i = 0; i < tsaResults.size(); i++) {

        nowRow = sh.createRow(row);

        j = 0;
        TimeSeriesAnalysisResult resultModel = tsaResults.get(i);

        Cell cell_kpi = nowRow.createCell(j);
        cell_kpi.setCellStyle(cellHeadStyle);
        cell_kpi.setCellValue(resultModel.getKpi().getName());
        j++;

        for (int n = 0; n < resultModel.getKpi().getDateRangeScores().size(); n++) {
            DateRangeScoreVO dateRangeScore = resultModel.getKpi().getDateRangeScores().get(n);
            Cell cell_dateRangeScore = nowRow.createCell(j);
            cell_dateRangeScore.setCellStyle(cellHeadStyle2);
            cell_dateRangeScore.setCellValue(dateRangeScore.getScore());
            j++;
        }
        for (int n = 0; n < resultModel.getForecastNext().size(); n++) {
            double forecastScore = resultModel.getForecastNext().get(n);
            Cell cell_forecastScore = nowRow.createCell(j);
            cell_forecastScore.setCellStyle(cellHeadStyle2);
            cell_forecastScore.setCellValue(forecastScore);
            j++;
        }

        row++;
    }

}

From source file:com.zxy.commons.poi.excel.ExcelUtils.java

License:Apache License

/**
 * export excel/*from  w  w  w. j av a 2s.com*/
 * 
 * @param sheetName sheet name
 * @param table table
 * @return Workbook
*/
@SuppressWarnings("PMD.ShortVariable")
private static Workbook exportExcel(String sheetName, Table<Integer, String, String> table) {
    Set<Integer> tableRows = table.rowKeySet();
    Set<String> tableColumns = table.columnKeySet();
    // excel
    Workbook wb = new HSSFWorkbook();

    // sheet??
    Sheet sheet = wb.createSheet(sheetName);
    // ???n?
    /*for (int i = 0; i < keys.length; i++) {
    sheet.setColumnWidth((short) i, (short) (35.7 * 150));
    }*/

    // 
    Row row = sheet.createRow((short) 0);

    // ???
    CellStyle cs = wb.createCellStyle();
    CellStyle cs2 = wb.createCellStyle();

    // ?
    Font f1 = wb.createFont();
    Font f2 = wb.createFont();

    // ????
    f1.setFontHeightInPoints((short) 10);
    f1.setColor(IndexedColors.BLACK.getIndex());
    f1.setBold(true);

    // ??
    f2.setFontHeightInPoints((short) 10);
    f2.setColor(IndexedColors.BLACK.getIndex());

    // Font f3=wb.createFont();
    // f3.setFontHeightInPoints((short) 10);
    // f3.setColor(IndexedColors.RED.getIndex());

    // ?????
    cs.setFont(f1);
    cs.setBorderLeft(BorderStyle.THIN);
    cs.setBorderRight(BorderStyle.THIN);
    cs.setBorderTop(BorderStyle.THIN);
    cs.setBorderBottom(BorderStyle.THIN);
    cs.setAlignment(HorizontalAlignment.CENTER);

    // ???
    cs2.setFont(f2);
    cs2.setBorderLeft(BorderStyle.THIN);
    cs2.setBorderRight(BorderStyle.THIN);
    cs2.setBorderTop(BorderStyle.THIN);
    cs2.setBorderBottom(BorderStyle.THIN);
    cs2.setAlignment(HorizontalAlignment.CENTER);
    // ??
    int i = 0;
    for (String tableColumn : tableColumns) {
        Cell cell = row.createCell(i);
        cell.setCellValue(tableColumn);
        cell.setCellStyle(cs);
        i++;
    }
    // ??
    for (Integer tableRow : tableRows) {
        // Row ,Cell  , Row  Cell 0
        // sheet
        checkArgument(tableRow > 0, "Row index must be greater than zero!");
        Row row1 = sheet.createRow(tableRow);
        // row
        Map<String, String> item = table.row(tableRow);
        int j = 0;
        for (Map.Entry<String, String> entry : item.entrySet()) {
            //            for(String v:item.keySet()){
            //                System.out.println(tableRow + "-" + v + "-" + item.get(v));
            Cell cell = row1.createCell(j);
            cell.setCellValue(entry.getValue());
            cell.setCellStyle(cs2);
            j++;
        }
    }
    return wb;
}

From source file:de.symeda.sormas.api.doc.UserRightsGenerator.java

License:Open Source License

@Test
public void generateUserRights() throws FileNotFoundException, IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();

    // Create User Rights sheet
    String safeName = WorkbookUtil.createSafeSheetName("User Rights");
    XSSFSheet sheet = workbook.createSheet(safeName);

    // Initialize cell styles
    // Authorized style
    XSSFCellStyle authorizedStyle = workbook.createCellStyle();
    authorizedStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    authorizedStyle.setFillForegroundColor(new XSSFColor(new Color(0, 153, 0)));
    authorizedStyle.setBorderBottom(BorderStyle.THIN);
    authorizedStyle.setBorderLeft(BorderStyle.THIN);
    authorizedStyle.setBorderTop(BorderStyle.THIN);
    authorizedStyle.setBorderRight(BorderStyle.THIN);
    authorizedStyle.setBorderColor(BorderSide.BOTTOM, new XSSFColor(Color.BLACK));
    authorizedStyle.setBorderColor(BorderSide.LEFT, new XSSFColor(Color.BLACK));
    authorizedStyle.setBorderColor(BorderSide.TOP, new XSSFColor(Color.BLACK));
    authorizedStyle.setBorderColor(BorderSide.RIGHT, new XSSFColor(Color.BLACK));
    // Unauthorized style
    XSSFCellStyle unauthorizedStyle = workbook.createCellStyle();
    unauthorizedStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    unauthorizedStyle.setFillForegroundColor(new XSSFColor(Color.RED));
    unauthorizedStyle.setBorderBottom(BorderStyle.THIN);
    unauthorizedStyle.setBorderLeft(BorderStyle.THIN);
    unauthorizedStyle.setBorderTop(BorderStyle.THIN);
    unauthorizedStyle.setBorderRight(BorderStyle.THIN);
    unauthorizedStyle.setBorderColor(BorderSide.BOTTOM, new XSSFColor(Color.BLACK));
    unauthorizedStyle.setBorderColor(BorderSide.LEFT, new XSSFColor(Color.BLACK));
    unauthorizedStyle.setBorderColor(BorderSide.TOP, new XSSFColor(Color.BLACK));
    unauthorizedStyle.setBorderColor(BorderSide.RIGHT, new XSSFColor(Color.BLACK));
    // Bold style
    XSSFFont boldFont = workbook.createFont();
    boldFont.setBold(true);/* ww w  . j  a va 2 s.com*/
    XSSFCellStyle boldStyle = workbook.createCellStyle();
    boldStyle.setFont(boldFont);

    int rowCounter = 0;

    // Header
    Row headerRow = sheet.createRow(rowCounter++);
    Cell userRightHeadlineCell = headerRow.createCell(0);
    userRightHeadlineCell.setCellValue("User Right");
    userRightHeadlineCell.setCellStyle(boldStyle);
    Cell descHeadlineCell = headerRow.createCell(1);
    descHeadlineCell.setCellValue("Description");
    descHeadlineCell.setCellStyle(boldStyle);
    sheet.setColumnWidth(0, 256 * 35);
    sheet.setColumnWidth(1, 256 * 50);
    for (UserRole userRole : UserRole.values()) {
        String columnCaption = userRole.toString();
        Cell headerCell = headerRow.createCell(userRole.ordinal() + 2);
        headerCell.setCellValue(columnCaption);
        headerCell.setCellStyle(boldStyle);
        sheet.setColumnWidth(userRole.ordinal() + 2, 256 * 14);
    }

    // User right rows
    for (UserRight userRight : UserRight.values()) {
        Row row = sheet.createRow(rowCounter++);

        // User right name
        Cell nameCell = row.createCell(0);
        nameCell.setCellValue(userRight.name());
        nameCell.setCellStyle(boldStyle);

        // User right description
        Cell descCell = row.createCell(1);
        descCell.setCellValue(userRight.toString());

        // Add styled cells for all user roles
        for (UserRole userRole : UserRole.values()) {
            Cell roleRightCell = row.createCell(userRole.ordinal() + 2);
            if (userRole.hasDefaultRight(userRight)) {
                roleRightCell.setCellStyle(authorizedStyle);
                roleRightCell.setCellValue("Yes");
            } else {
                roleRightCell.setCellStyle(unauthorizedStyle);
                roleRightCell.setCellValue("No");
            }
        }
    }

    XssfHelper.addAboutSheet(workbook);

    String filePath = "src/main/resources/doc/SORMAS_User_Rights.xlsx";
    try (OutputStream fileOut = new FileOutputStream(filePath)) {
        workbook.write(fileOut);
    }
    workbook.close();

    //      Desktop.getDesktop().open(new File(filePath));
}

From source file:DSC.ChefReport.java

public static void processChefReport() throws IOException {

    boolean firstFamEntry = true;
    String list[] = { "Standard", "Low Carb", "Kiddies" };
    int excelNumber = 0;
    int sheetNumber = 0;

    for (mealCounter = 0; mealCounter < 3; mealCounter++) {
        workbook = new XSSFWorkbook();
        sheetNumber = 0;/*from   w ww  .  j  a v  a 2s. c om*/
        for (String currRoute : allRoutes) {

            Map<String, Object[]> data = new TreeMap<>();
            data.put(0 + "", new String[] { "Doorstep Chef - Chef Report " + DriverReport.returnWeekInt(), "",
                    "", "Meal Type : " + list[mealCounter] + " " + " " + "Route: " + sheetNumber });
            data.put(1 + "", new String[] { "", "", "", "", "", "", "" });
            data.put(2 + "", new String[] { "Family Size", "Quantity", "Allergies", "Exclusions" });
            int counter = 3;
            XSSFSheet sheet = workbook.createSheet("ChefReports Route - " + sheetNumber);
            int rowNum = 0;
            int cellNum = 0;
            String familysize = "";

            ArrayList<Meal> mealList = new ArrayList<>();
            boolean hasValue = false;

            for (Order order : orders) {
                for (Meal meal : order.getMeals()) {
                    if (meal.getMealType().equals(list[mealCounter]) && order.getRoute().equals(currRoute)) {
                        mealList.add(meal);
                        hasValue = true;
                    }
                }
            }

            mealList.sort(new Comparator<Meal>() {
                @Override
                public int compare(Meal o1, Meal o2) {
                    if (o1.getQuantity() < o2.getQuantity()) {
                        return -1;
                    } else if (o1.getQuantity() > o2.getQuantity()) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });

            if (hasValue) {
                int currQuantity = 0;
                int bulk = 0;
                boolean firstIterate = true;

                for (Meal meal : mealList) {

                    if (meal.getQuantity() != currQuantity) {

                        if (!firstIterate && bulk != 0) {
                            data.put(counter + "",
                                    new String[] { familysize + " Normal *", bulk + "", "", "" });
                            bulk = 0;
                            counter++;
                        }
                        firstIterate = false;

                        switch (meal.getQuantity()) {
                        case 1:
                            familysize = "Single";
                            break;
                        case 2:
                            familysize = "Couple";
                            break;
                        case 3:
                            familysize = "Three";
                            break;
                        case 4:
                            familysize = "Four";
                            break;
                        case 5:
                            familysize = "Five";
                            break;
                        case 6:
                            familysize = "Six";
                            break;
                        default:
                            familysize = "Extra";
                        }
                        currQuantity = meal.getQuantity();
                    }

                    if (meal.getAllergies().equals("-") && meal.getExclusions().equals("-")) {
                        bulk++;
                    } else {
                        data.put(counter + "", new String[] { familysize + " Meal", meal.getQuantity() + "",
                                meal.getAllergies(), meal.getExclusions() });
                        counter++;
                    }

                }
            }

            Set<String> keySet = data.keySet();
            Object[] keys = data.keySet().toArray();
            Arrays.sort(keys);
            ArrayList<Object> keyList = new ArrayList();
            int longestCustomer = 5;
            int totalWidth = 50000;
            boolean isBulk = false;

            for (Object key : keys) {
                keyList.add(data.get(key));
            }

            for (int keyIterate = 0; keyIterate < keySet.size(); keyIterate++) {
                Row row = sheet.createRow(rowNum);
                Object[] arr = data.get(keyIterate + "");

                for (int i = 0; i < arr.length; i++) {
                    XSSFFont font = workbook.createFont();
                    Cell cell = row.createCell(i);
                    cell.setCellValue((String) arr[i]);
                    XSSFCellStyle borderStyle = workbook.createCellStyle();

                    if ((keyIterate + "").equals("0") || (keyIterate + "").equals("1")) {

                        font.setFontName("Calibri");
                        font.setFontHeightInPoints((short) 13);
                        font.setBold(true);
                        borderStyle.setFont(font);
                        borderStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
                        borderStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
                        borderStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
                        borderStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
                        borderStyle.setAlignment(HorizontalAlignment.LEFT);

                    } else {
                        borderStyle.setBorderBottom(BorderStyle.THIN);
                        borderStyle.setBorderTop(BorderStyle.THIN);
                        borderStyle.setBorderLeft(BorderStyle.THIN);
                        borderStyle.setBorderRight(BorderStyle.THIN);
                        if ((arr[0] + "").contains("*")) {
                            isBulk = true;
                            borderStyle.setBorderBottom(BorderStyle.MEDIUM);
                        }
                    }
                    if ((keyIterate + "").equals("2")) {
                        borderStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM);
                        borderStyle.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM);
                        borderStyle.setBorderTop(XSSFCellStyle.BORDER_MEDIUM);
                        borderStyle.setBorderRight(XSSFCellStyle.BORDER_MEDIUM);
                        borderStyle.setAlignment(HorizontalAlignment.CENTER);
                        borderStyle.setFillPattern(XSSFCellStyle.LESS_DOTS);
                        borderStyle.setFillBackgroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
                        XSSFFont font2 = workbook.createFont();
                        font2.setColor(IndexedColors.WHITE.getIndex());
                        borderStyle.setFont(font2);

                    }
                    cell.setCellStyle(borderStyle);

                }

                rowNum++;
                cellNum++;

            }
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 2));

            for (int i = 0; i < 5; i++) {
                switch (i) {
                case 1:
                    sheet.setColumnWidth(i, 3000);
                    break;
                case 2:
                    sheet.setColumnWidth(i, 8000);
                    break;
                default:
                    sheet.setColumnWidth(i, 4000);
                    break;
                }

                if (i == 3) {
                    sheet.setColumnWidth(i, 8000);
                }

            }

            Row rowDate = sheet.createRow(keySet.size() + 1);
            Cell cell = rowDate.createCell(0);
            SimpleDateFormat sf = new SimpleDateFormat("EEE MMM yyyy HH:mm:ss");

            cell.setCellValue(sf.format(Calendar.getInstance().getTime()));
            XSSFCellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setAlignment(XSSFCellStyle.ALIGN_RIGHT);
            cell.setCellStyle(cellStyle);
            sheet.addMergedRegion(new CellRangeAddress(keySet.size() + 1, keySet.size() + 1, 0, 3));

            sheetNumber++;

            creatSheet(list[mealCounter], workbook);

            excelNumber++;
            if (excelNumber == allRoutes.size()) {
                if (!(DSC_Main.generateAllReports)) {
                    chefLoadingObj.setVisible(false);
                    chefLoadingObj.dispose();
                    JOptionPane.showMessageDialog(null, "Chef Reports Successfully Generated.");
                }
            }
        }
    }
}

From source file:DSC.QuantityReport.java

private static void processQuantityReport() {

    int excelNumber = 0;
    int sheetNumber = 0;
    workbook = new XSSFWorkbook();
    Map<String, String[]> data = new TreeMap<>();
    data.put(0 + "", new String[] { "Doorstep Chef - Quantity Report " + currentWeek(), "", "",
            "Week : " + returnWeekInt() + " " + " " });
    data.put(1 + "", new String[] { "", "", "", "", "", "", "" });
    data.put(2 + "", new String[] { "Total Of ", "Single", "Couple", "Three", "Four", "Five", "Six", "Extra" });

    XSSFSheet sheet = workbook.createSheet("Quantity Report " + sheetNumber);
    int rowNum = 0;
    int cellNum = 0;

    for (int i = 3; i < 19; i++) {
        if (i == 3) {
            data.put(i + "",
                    new String[] { "Orders", quantityObj.getCountFamilySize_1() + "",
                            quantityObj.getCountFamilySize_2() + "", quantityObj.getCountFamilySize_3() + "",
                            quantityObj.getCountFamilySize_4() + "", quantityObj.getCountFamilySize_5() + "",
                            quantityObj.getCountFamilySize_6() + "",
                            quantityObj.getCountFamilySizeMoreThanSix() + "" });
        } else if (i == 4) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 5) {
            data.put(i + "", new String[] { "Meals", quantityObj.getQuantityFamSize1() + "",
                    quantityObj.getQuantityFamSize2() + "", quantityObj.getQuantityFamSize3() + "",
                    quantityObj.getQuantityFamSize4() + "", quantityObj.getQuantityFamSize5() + "",
                    quantityObj.getQuantityFamSize6() + "", quantityObj.getQuantityFamSizeMoreThanSix() + "" });
        } else if (i == 6) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 7) {
            data.put(i + "", new String[] { "Standard Meals", quantityObj.getCountFamSize1_Standard() + "",
                    quantityObj.getCountFamSize2_Standard() + "", quantityObj.getCountFamSize3_Standard() + "",
                    quantityObj.getCountFamSize4_Standard() + "", quantityObj.getCountFamSize5_Standard() + "",
                    quantityObj.getCountFamSize6_Standard() + "",
                    quantityObj.getCountFamilySizeMoreThanSix_Standard() + "" });
        } else if (i == 8) {
            data.put(i + "",
                    new String[] { "Low Carb Meals", quantityObj.getCountFamSize1_LC() + "",
                            quantityObj.getCountFamSize2_LC() + "", quantityObj.getCountFamSize3_LC() + "",
                            quantityObj.getCountFamSize4_LC() + "", quantityObj.getCountFamSize5_LC() + "",
                            quantityObj.getCountFamSize6_LC() + "",
                            quantityObj.getCountFamilySizeMoreThanSix_LC() + "" });
        } else if (i == 9) {
            data.put(i + "",
                    new String[] { "Kiddies Meals", quantityObj.getCountFamSize1_KD() + "",
                            quantityObj.getCountFamSize2_KD() + "", quantityObj.getCountFamSize3_KD() + "",
                            quantityObj.getCountFamSize4_KD() + "", quantityObj.getCountFamSize5_KD() + "",
                            quantityObj.getCountFamSize6_KD() + "",
                            quantityObj.getCountFamilySizeMoreThanSix_KD() + "" });
        } else if (i == 10) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 11) {
            data.put(i + "",
                    new String[] { "Totals", quantityObj.totalSingleMeals() + "",
                            quantityObj.totalCoupleMeals() + "", quantityObj.totalThreeMeals() + "",
                            quantityObj.totalFourMeals() + "", quantityObj.totalFiveMeals() + "",
                            quantityObj.totalSixMeals() + "", quantityObj.totalExtraMeals() + "" });
        } else if (i == 12) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 13) {
            data.put(i + "", new String[] { "Standard Individuals", "", "", "", "", "", "",
                    quantityObj.returnTotalStandardMeals() + "" });
        } else if (i == 14) {
            data.put(i + "", new String[] { "Low Carb Individuals", "", "", "", "", "", "",
                    quantityObj.returnTotalLowCarbMeals() + "" });
        } else if (i == 15) {
            data.put(i + "", new String[] { "Kiddies Individuals", "", "", "", "", "", "",
                    quantityObj.returnTotalKiddiesMeals() + "" });
        } else if (i == 16) {
            data.put(i + "", new String[] { "", "", "", "", "", "", "", "" });
        } else if (i == 17) {
            data.put(i + "", new String[] { "Total Clients", "", "", "", "", "", "",
                    quantityObj.returnTotalClients() + "" });
        } else if (i == 18) {

            int totalIndividuals = quantityObj.returnTotalStandardMeals()
                    + quantityObj.returnTotalLowCarbMeals() + quantityObj.returnTotalKiddiesMeals();

            data.put(i + "",
                    new String[] { "Total Individuals", "", "", "", "", "", "", totalIndividuals + "" });
        }//  ww  w .jav  a2  s.  co m
    }

    Set<String> keySet = data.keySet();

    for (int keyIterate = 0; keyIterate < keySet.size(); keyIterate++) {
        Row row = sheet.createRow(rowNum);
        Object[] arr = data.get(keyIterate + "");
        XSSFCellStyle borderStyle = workbook.createCellStyle();
        XSSFCellStyle borderStyle2 = workbook.createCellStyle();
        for (int i = 0; i < arr.length; i++) {
            XSSFFont font = workbook.createFont();
            Cell cell = row.createCell(i);
            cell.setCellValue((String) arr[i]);

            if ((keyIterate + "").equals("0") || (keyIterate + "").equals("1")) {

                font.setFontName("Calibri");
                font.setFontHeightInPoints((short) 13);
                font.setBold(true);
                borderStyle.setFont(font);
                borderStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
                borderStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
                borderStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
                borderStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
                borderStyle.setAlignment(HorizontalAlignment.LEFT);

            } else if (keyIterate > 1 && keyIterate < 12) {
                borderStyle.setBorderBottom(BorderStyle.THIN);
                borderStyle.setBorderTop(BorderStyle.THIN);
                borderStyle.setBorderLeft(BorderStyle.THIN);
                borderStyle.setBorderRight(BorderStyle.THIN);

            }

            if ((keyIterate + "").equals("2")) {
                borderStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM);
                borderStyle.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM);
                borderStyle.setBorderTop(XSSFCellStyle.BORDER_MEDIUM);
                borderStyle.setBorderRight(XSSFCellStyle.BORDER_MEDIUM);
                borderStyle.setAlignment(HorizontalAlignment.CENTER);
                borderStyle.setFillPattern(XSSFCellStyle.LESS_DOTS);
                borderStyle.setFillBackgroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
                XSSFFont font2 = workbook.createFont();
                font2.setColor(IndexedColors.WHITE.getIndex());
                borderStyle.setFont(font2);

            }

            cell.setCellStyle(borderStyle);
        }

        rowNum++;
        cellNum++;
        sheetNumber++;
    }

    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));

    for (int i = 0; i < 8; i++) {
        if (i == 0) {
            sheet.setColumnWidth(i, 5000);
        } else {
            sheet.setColumnWidth(i, 2000);

        }

    }

    try {
        creatSheet(sheetNumber + "", workbook);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "File Could Not Be Found.");
    }

    excelNumber++;

}

From source file:generate.AExcel.java

protected void createCell(IQuote list, IKey iKey) throws Exception {
    List<Map<String, String>> List = list.getOrderItems(quote_id);
    rowCount = List.size();//from  ww w  .j a  v a2  s.com
    CellStyle style = workbook.createCellStyle();
    style.setBorderLeft(BorderStyle.THIN);
    style.setBorderRight(BorderStyle.THIN);
    style.setBorderTop(BorderStyle.THIN);
    style.setBorderBottom(BorderStyle.THIN);
    int rowNum = firstRow;
    for (int i = 0; i < rowCount; i++) {
        Map<String, String> temp = List.get(i);

        sheetrow = worksheet.getRow(rowNum);

        // Before writing value to a row, check if a value exist and shift 
        // it to the next row including all its properties
        // or create a new row
        if (iKey instanceof ProductKey)
            CopyRow.copyRow(workbook, worksheet, RowIndex.row(sheetrow.getRowNum()),
                    RowIndex.row(sheetrow.getRowNum() + 1));

        for (Map.Entry<String, String> entry : temp.entrySet()) {
            int key = iKey.productKeyToInt(entry.getKey());
            value = entry.getValue();

            sheetcell = sheetrow.getCell(key);
            //sheetcell.setCellStyle(style);

            //  
            // Check if the value returned is an integer.
            // If true, set the cell to integer.
            // Else set the cell to string
            StringInt stringInt = new StringInt();
            if (stringInt.isStringInt(value)) {
                sheetcell.setCellValue(new BigDecimal(value).doubleValue());
            } else {
                sheetcell.setCellValue(value);
            }
        }
        nextRow = rowNum;
        rowNum++;
    }
}

From source file:guru.qas.martini.report.DefaultState.java

License:Apache License

protected void colorRow(short color, Row row) {
    short firstCellNum = row.getFirstCellNum();
    short lastCellNum = row.getLastCellNum();
    for (int i = firstCellNum; i <= lastCellNum; i++) {
        Cell cell = row.getCell(i);//w w w  . ja v a2s . c om
        if (null != cell) {
            CellStyle cellStyle = cell.getCellStyle();
            Workbook workbook = cell.getSheet().getWorkbook();
            CellStyle clone = workbook.createCellStyle();

            clone.cloneStyleFrom(cellStyle);
            clone.setFillForegroundColor(color);
            clone.setFillPattern(FillPatternType.SOLID_FOREGROUND);

            BorderStyle borderStyle = cellStyle.getBorderLeftEnum();
            clone.setBorderLeft(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle);
            short borderColor = cellStyle.getLeftBorderColor();
            clone.setLeftBorderColor(0 == borderColor ? IndexedColors.BLACK.getIndex() : borderColor);

            borderStyle = cellStyle.getBorderRightEnum();
            clone.setBorderRight(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle);
            borderColor = cellStyle.getRightBorderColor();
            clone.setRightBorderColor(0 == borderColor ? IndexedColors.BLACK.getIndex() : borderColor);

            borderStyle = cellStyle.getBorderTopEnum();
            clone.setBorderTop(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle);
            borderColor = cellStyle.getTopBorderColor();
            clone.setTopBorderColor(0 == borderColor ? IndexedColors.BLACK.getIndex() : borderColor);

            borderStyle = cellStyle.getBorderBottomEnum();
            clone.setBorderBottom(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle);
            borderColor = cellStyle.getBottomBorderColor();
            clone.setBottomBorderColor(borderColor);
            cell.setCellStyle(clone);
        }
    }
}

From source file:hornet.framework.web.service.export.AbstractTableExportService.java

License:CeCILL license

@Override
public HSSFWorkbook construireXlsModel(final T toExport) {

    // Blank workbook
    final HSSFWorkbook workbook = new HSSFWorkbook();

    // Create a blank sheet
    final HSSFSheet sheet = workbook.createSheet();
    int rownum = 0;

    // Style pour la bordure des cellules
    final CellStyle styleBordure = workbook.createCellStyle();
    styleBordure.setBorderBottom(BorderStyle.THIN);
    styleBordure.setBorderTop(BorderStyle.THIN);
    styleBordure.setBorderRight(BorderStyle.THIN);
    styleBordure.setBorderLeft(BorderStyle.THIN);

    final CellStyle styleEntete = workbook.createCellStyle();
    styleEntete.cloneStyleFrom(styleBordure);
    styleEntete.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    styleEntete.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    // Rcupration du Table VO
    final TableVO tableVo = construireTableauExport(toExport);

    final Collection<String> colTitles = tableVo.getColumnsTitles();
    final Iterator<String> itTitles = colTitles.iterator();

    // Titre des colonnes
    int cellnum = 0;
    final Row xlsRow = sheet.createRow(rownum++);
    while (itTitles.hasNext()) {
        final String title = itTitles.next();
        final Cell cell = xlsRow.createCell(cellnum++);
        cell.setCellValue(title);/*from  w ww .jav  a2 s  .  c o  m*/
        cell.setCellStyle(styleEntete);
    }

    if (tableVo.getRows() != null) {
        final List<RowVO> rows = tableVo.getRows();
        final Iterator<RowVO> itRows = rows.iterator();
        // Lignes
        while (itRows.hasNext()) {
            this.exporteLigne(itRows, rownum, sheet, styleBordure);
            rownum++;
        }

        for (int i = 0; i < cellnum; i++) {
            sheet.autoSizeColumn(i);
        }
    }

    return workbook;
}

From source file:io.vertigo.quarto.plugins.export.xls.XLSExporter.java

License:Apache License

private static HSSFCellStyle createHeaderCellStyle(final HSSFWorkbook workbook) {
    final HSSFCellStyle cellStyle = workbook.createCellStyle();
    final HSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName("Arial");
    font.setBold(true);/* ww w. ja  va 2  s .c  om*/
    cellStyle.setFont(font);
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderTop(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setVerticalAlignment(VerticalAlignment.JUSTIFY);
    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellStyle.setFillForegroundColor(HSSFColorPredefined.GREY_40_PERCENT.getIndex());
    cellStyle.setAlignment(HorizontalAlignment.CENTER);
    return cellStyle;
}

From source file:io.vertigo.quarto.plugins.export.xls.XLSExporter.java

License:Apache License

private static HSSFCellStyle createRowCellStyle(final HSSFWorkbook workbook, final boolean odd) {
    final HSSFCellStyle cellStyle = workbook.createCellStyle();
    final HSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName("Arial");
    cellStyle.setFont(font);/*from w  w w. j  a  v  a2 s .c  o  m*/
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderTop(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    cellStyle.setFillForegroundColor(
            odd ? HSSFColorPredefined.WHITE.getIndex() : HSSFColorPredefined.GREY_25_PERCENT.getIndex());

    return cellStyle;
}