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

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

Introduction

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

Prototype

BorderStyle MEDIUM

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

Click Source Link

Document

Medium border

Usage

From source file:de.jlo.talendcomp.excel.SpreadsheetFile.java

License:Apache License

/**
 * adds a font to the workbook/*from w w w.j  ava  2 s  .  co  m*/
 * @param family like Arial
 * @param height like 8,9,10,12,14...
 * @param bui with "b"=bold, "u"=underlined, "i"=italic and all combinations as String
 * @param color color index
 */
public void addStyle(String styleName, String fontFamily, String fontHeight, String fontDecoration,
        String fontColor, String bgColor, String textAlign, boolean buttomBorder) {
    if (styleName != null && styleName.isEmpty() == false) {
        Font f = workbook.createFont();
        if (fontFamily != null && fontFamily.isEmpty() == false) {
            f.setFontName(fontFamily);
        }
        if (fontHeight != null && fontHeight.isEmpty() == false) {
            short height = Short.parseShort(fontHeight);
            if (height > 0) {
                f.setFontHeightInPoints(height);
            }
        }
        if (fontDecoration != null && fontDecoration.isEmpty() == false) {
            if (fontDecoration.contains("b")) {
                f.setBold(true);
            }
            if (fontDecoration.contains("i")) {
                f.setItalic(true);
            }
            if (fontDecoration.contains("u")) {
                f.setUnderline(Font.U_SINGLE);
            }
        }
        if (fontColor != null && fontColor.isEmpty() == false) {
            short color = Short.parseShort(fontColor);
            f.setColor(color);
        }
        CellStyle style = workbook.createCellStyle();
        style.setFont(f);
        if (bgColor != null && bgColor.isEmpty() == false) {
            short color = Short.parseShort(bgColor);
            style.setFillForegroundColor(color);
            //style.setFillBackgroundColor(color);
            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        }
        if (textAlign != null && textAlign.isEmpty() == false) {
            if ("center".equalsIgnoreCase(textAlign)) {
                style.setAlignment(HorizontalAlignment.CENTER);
            } else if ("left".equalsIgnoreCase(textAlign)) {
                style.setAlignment(HorizontalAlignment.LEFT);
            } else if ("right".equals(textAlign)) {
                style.setAlignment(HorizontalAlignment.RIGHT);
            }
        }
        if (buttomBorder) {
            style.setBorderBottom(BorderStyle.MEDIUM);
            style.setBottomBorderColor((short) 9);
        }
        namedStyles.put(styleName, style);
    }
}

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  va 2 s .  c  o  m*/
        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:guru.qas.martini.report.DefaultState.java

License:Apache License

public void updateLongestExecutions() {
    if (!longestExecutionCells.isEmpty()) {
        for (Cell cell : longestExecutionCells) {
            CellStyle original = cell.getCellStyle();
            Sheet sheet = cell.getSheet();
            Workbook workbook = sheet.getWorkbook();
            CellStyle newStyle = workbook.createCellStyle();
            newStyle.cloneStyleFrom(original);
            int originalFontIndex = original.getFontIndexAsInt();
            Font originalFont = workbook.getFontAt(originalFontIndex);

            Font font = workbook.createFont();
            font.setBold(true);/* w  w w . j a  va 2s  .c om*/
            font.setColor(IndexedColors.DARK_RED.getIndex());
            font.setFontHeight((short) Math.round(originalFont.getFontHeight() * 1.5));
            newStyle.setFont(font);
            cell.setCellStyle(newStyle);

            Row row = cell.getRow();
            short firstCellNum = row.getFirstCellNum();
            short lastCellNum = row.getLastCellNum();

            for (int i = firstCellNum; i < lastCellNum; i++) {
                Cell rowCell = row.getCell(i);
                original = rowCell.getCellStyle();
                CellStyle borderStyle = workbook.createCellStyle();
                borderStyle.cloneStyleFrom(original);
                borderStyle.setBorderTop(BorderStyle.MEDIUM);
                borderStyle.setBorderBottom(BorderStyle.MEDIUM);

                if (i == cell.getColumnIndex()) {
                    borderStyle.setBorderLeft(BorderStyle.MEDIUM);
                    borderStyle.setBorderRight(BorderStyle.MEDIUM);
                } else if (i == firstCellNum) {
                    borderStyle.setBorderLeft(BorderStyle.MEDIUM);
                } else if (i == lastCellNum - 1) {
                    borderStyle.setBorderRight(BorderStyle.MEDIUM);
                }
                rowCell.setCellStyle(borderStyle);
            }
        }
    }
}

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

License:Apache License

protected CellStyle getHeaderStyle(Workbook workbook) {
    CellStyle style = workbook.createCellStyle();
    style.setBorderBottom(BorderStyle.MEDIUM);
    Font headerFont = getHeaderFont(workbook);
    style.setFont(headerFont);/*  w w  w.  j a  va2s  .c o  m*/
    return style;
}

From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

protected BorderStyle getBorder(Border border) {
    if (border.getLineWidth() <= 1f) {
        return BorderStyle.THIN;
    }//from  w  w w. j av a  2s .  c om
    if (border.getLineWidth() <= 2f) {
        return BorderStyle.MEDIUM;
    } else {
        return BorderStyle.THICK;
    }
}

From source file:nc.noumea.mairie.appock.services.impl.ExportExcelServiceImpl.java

License:Open Source License

private void construitEnteteService(Workbook wb, Service service, Sheet sheet) {
    Row row = createRowGeneric(sheet, 1, 500);
    Cell cell = row.createCell(1);//ww  w  .j a v a  2 s  . c  o m
    cell.setCellValue(service.getLibelle());
    cell.setCellStyle(
            createCellWithBorderAndColor(wb, BorderStyle.MEDIUM, IndexedColors.LIGHT_TURQUOISE, true));
}

From source file:nc.noumea.mairie.appock.services.impl.ExportExcelServiceImpl.java

License:Open Source License

private void construitEnteteExportCatalogueGeneric(Workbook wb, Row row, String libelle, int colonne) {
    Cell cell = row.createCell(colonne);
    cell.setCellValue(libelle);//from w w w. j  ava 2  s  . c o m
    cell.setCellStyle(
            createCellWithBorderAndColor(wb, BorderStyle.MEDIUM, IndexedColors.LIGHT_TURQUOISE, true));
}

From source file:nc.noumea.mairie.appock.services.impl.ExportExcelServiceImpl.java

License:Open Source License

private void construitLigneExportCatalogueGeneric(Workbook wb, Row row, String libelle, int colonne,
        boolean mouvementStock) {
    Cell cell = row.createCell(colonne);
    cell.setCellValue(libelle);// ww  w .j  ava2 s.c o m
    cell.setCellStyle(createCellWithBorderAndColor(wb, BorderStyle.MEDIUM,
            mouvementStock ? IndexedColors.LIGHT_GREEN : null, false));
}

From source file:nc.noumea.mairie.appock.util.StockSpreadsheetExporter.java

License:Open Source License

private static int generateHeader(XSSFSheet worksheet, XSSFWorkbook workbook, int rowNum) {
    // Now add/*ww  w. ja va  2 s .  c o m*/
    XSSFRow row = worksheet.createRow(rowNum);
    XSSFCell cell;

    XSSFCellStyle headerStyle = workbook.createCellStyle();
    headerStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.index);
    headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    headerStyle.setBorderBottom(BorderStyle.MEDIUM);
    headerStyle.setBorderLeft(BorderStyle.MEDIUM);
    headerStyle.setBorderRight(BorderStyle.MEDIUM);
    headerStyle.setBorderTop(BorderStyle.MEDIUM);
    headerStyle.setAlignment(HorizontalAlignment.CENTER);
    headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    XSSFFont txtFont = workbook.createFont();
    txtFont.setFontName("calibri");
    txtFont.setFontHeightInPoints((short) 9);
    txtFont.setBold(true);
    headerStyle.setFont(txtFont);

    cell = row.createCell(0);
    cell.setCellValue("Photo");
    cell.setCellStyle(headerStyle);
    worksheet.setColumnWidth(0, ConvertImageUnits.pixel2WidthUnits(COLUMN_WIDTH_PX));//4387

    cell = row.createCell(1);
    cell.setCellValue("Rfrence");
    cell.setCellStyle(headerStyle);

    cell = row.createCell(2);
    cell.setCellValue("Libell");
    cell.setCellStyle(headerStyle);

    cell = row.createCell(3);
    cell.setCellValue("Stock\n Appock");
    cell.setCellStyle(headerStyle);
    cell.getCellStyle().setWrapText(true);

    cell = row.createCell(4);
    cell.setCellValue("Stock\n rel");
    cell.setCellStyle(headerStyle);
    cell.getCellStyle().setWrapText(true);

    row.setHeight((short) 600);

    return rowNum + 1;
}

From source file:org.haplo.jsinterface.generate.KGenerateXLS.java

License:Mozilla Public License

private void styleBorder(SheetStyleInstruction i) {
    CellRangeAddress region = styleInstructionCellRangeAddress(i);
    // Border//  ww w.  jav  a  2s.  c om
    RegionUtil.setBorderBottom(BorderStyle.MEDIUM, region, this.sheet);
    RegionUtil.setBorderTop(BorderStyle.MEDIUM, region, this.sheet);
    RegionUtil.setBorderLeft(BorderStyle.MEDIUM, region, this.sheet);
    RegionUtil.setBorderRight(BorderStyle.MEDIUM, region, this.sheet);
    // Colour
    short colindex = styleFindColour(IndexedColors.BLACK.getIndex(), i.colour);
    RegionUtil.setBottomBorderColor(colindex, region, this.sheet);
    RegionUtil.setTopBorderColor(colindex, region, this.sheet);
    RegionUtil.setLeftBorderColor(colindex, region, this.sheet);
    RegionUtil.setRightBorderColor(colindex, region, this.sheet);
}