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:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

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

From source file:jgnash.convert.exportantur.ssf.AccountExport.java

License:Open Source License

public static void exportAccount(final Account account, final String[] columnNames, final LocalDate startDate,
        final LocalDate endDate, final File file) {
    Objects.requireNonNull(account);
    Objects.requireNonNull(startDate);
    Objects.requireNonNull(endDate);
    Objects.requireNonNull(file);
    Objects.requireNonNull(columnNames);

    final String extension = FileUtils.getFileExtension(file.getAbsolutePath());

    try (final Workbook wb = extension.equals("xlsx") ? new XSSFWorkbook() : new HSSFWorkbook()) {
        final CreationHelper createHelper = wb.getCreationHelper();

        // create a new sheet
        final Sheet s = wb.createSheet(account.getName());

        // create 2 fonts objects
        final Font defaultFont = wb.createFont();
        final Font headerFont = wb.createFont();

        defaultFont.setFontHeightInPoints((short) 10);
        defaultFont.setColor(IndexedColors.BLACK.getIndex());

        headerFont.setFontHeightInPoints((short) 11);
        headerFont.setColor(IndexedColors.BLACK.getIndex());
        headerFont.setBold(true);//  w w  w.j  a  v  a 2 s  .c om

        // create header cell styles
        final CellStyle headerStyle = wb.createCellStyle();

        // Set the other cell style and formatting
        headerStyle.setBorderBottom(BorderStyle.THIN);
        headerStyle.setBorderTop(BorderStyle.THIN);
        headerStyle.setBorderLeft(BorderStyle.THIN);
        headerStyle.setBorderRight(BorderStyle.THIN);
        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        DataFormat df_header = wb.createDataFormat();

        headerStyle.setDataFormat(df_header.getFormat("text"));
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(HorizontalAlignment.CENTER);

        final CellStyle dateStyle = wb.createCellStyle();
        dateStyle.setDataFormat(createHelper.createDataFormat().getFormat("mm/dd/yy"));
        dateStyle.setFont(defaultFont);

        final CellStyle timestampStyle = wb.createCellStyle();
        timestampStyle.setDataFormat(createHelper.createDataFormat().getFormat("YYYY-MM-DD HH:MM:SS"));
        timestampStyle.setFont(defaultFont);

        final CellStyle textStyle = wb.createCellStyle();
        textStyle.setFont(defaultFont);

        final CellStyle amountStyle = wb.createCellStyle();
        amountStyle.setFont(defaultFont);
        amountStyle.setAlignment(HorizontalAlignment.RIGHT);

        final DecimalFormat format = (DecimalFormat) NumericFormats
                .getFullCommodityFormat(account.getCurrencyNode());
        final String pattern = format.toLocalizedPattern().replace("", account.getCurrencyNode().getPrefix());
        final DataFormat df = wb.createDataFormat();
        amountStyle.setDataFormat(df.getFormat(pattern));

        // Create headers
        int row = 0;
        Row r = s.createRow(row);
        for (int i = 0; i < columnNames.length; i++) {
            Cell c = r.createCell(i);
            c.setCellValue(createHelper.createRichTextString(columnNames[i]));
            c.setCellStyle(headerStyle);
        }

        // Dump the transactions
        for (final Transaction transaction : account.getTransactions(startDate, endDate)) {
            r = s.createRow(++row);

            int col = 0;

            // date
            Cell c = r.createCell(col, CellType.STRING);
            c.setCellValue(DateUtils.asDate(transaction.getLocalDate()));
            c.setCellStyle(dateStyle);

            // timestamp
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(DateUtils.asDate(transaction.getTimestamp()));
            c.setCellStyle(timestampStyle);

            // number
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(transaction.getNumber());
            c.setCellStyle(textStyle);

            // payee
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(transaction.getPayee());
            c.setCellStyle(textStyle);

            // memo
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(transaction.getMemo());
            c.setCellStyle(textStyle);

            // account
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(getAccountColumnValue(transaction, account));
            c.setCellStyle(textStyle);

            // clr, strip any zero width spaces
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(transaction.getReconciled(account).toString().replaceAll(ZERO_WIDTH_SPACE, ""));
            c.setCellStyle(textStyle);

            final BigDecimal amount = transaction.getAmount(account);

            // increase
            c = r.createCell(++col, CellType.NUMERIC);
            if (amount.signum() >= 0) {
                c.setCellValue(amount.doubleValue());
            }
            c.setCellStyle(amountStyle);

            // decrease
            c = r.createCell(++col, CellType.NUMERIC);
            if (amount.signum() < 0) {
                c.setCellValue(amount.abs().doubleValue());
            }
            c.setCellStyle(amountStyle);

            // balance
            c = r.createCell(++col, CellType.NUMERIC);
            c.setCellValue(account.getBalanceAt(transaction).doubleValue());
            c.setCellStyle(amountStyle);
        }

        // autosize the column widths
        final short columnCount = s.getRow(1).getLastCellNum();

        // autosize all of the columns + 10 pixels
        for (int i = 0; i <= columnCount; i++) {
            s.autoSizeColumn(i);
            s.setColumnWidth(i, s.getColumnWidth(i) + 10);
        }

        Logger.getLogger(AccountExport.class.getName()).log(Level.INFO, "{0} cell styles were used",
                wb.getNumCellStyles());

        // Save
        final String filename;

        if (wb instanceof XSSFWorkbook) {
            filename = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".xlsx";
        } else {
            filename = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".xls";
        }

        try (final OutputStream out = Files.newOutputStream(Paths.get(filename))) {
            wb.write(out);
        } catch (final Exception e) {
            Logger.getLogger(AccountExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
        }

    } catch (final IOException e) {
        Logger.getLogger(AccountExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}

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

License:Open Source License

private void construitEnteteSoldeCommande(Workbook wb, Sheet sheet) {
    Row row = createRowGeneric(sheet, 4, 500);
    Cell cell = row.createCell(6);//from   ww  w  .j a  va 2s.  co  m
    cell.setCellValue("Montant de la commande");
    cell.setCellStyle(createCellWithBorderAndColor(wb, BorderStyle.THIN, IndexedColors.LIGHT_TURQUOISE, false));
}

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

License:Open Source License

private void construitEnteteNumeroMarcheEtSoldeCommande(Workbook wb, Map<Service, List<ArticleDemande>> map,
        AbstractEntity abstractEntity, Service service, Sheet sheet) {
    Row row = createRowGeneric(sheet, LIGNE_NUMERO_MARCHE_ET_SOLDE_COMMANDE, 500);
    Cell cell = row.createCell(0);//  w  w w  . j av a2  s .co  m
    if (abstractEntity instanceof SousMarche) {
        cell.setCellValue("March Nouma n: " + ((SousMarche) abstractEntity).getNumero());
        cell.setCellStyle(createCellWithBorderAndColor(wb, BorderStyle.THIN, IndexedColors.TAN, false));
    }

    // Cell Montant de la commande
    cell = row.createCell(6);

    int prixTotalService = 0;
    for (ArticleDemande articleDemande : map.get(service)) {
        prixTotalService += articleDemande.getTotalPrixCommande();
    }
    cell.setCellValue(prixTotalService);
    CellStyle style = createCellWithBorderAndColor(wb, BorderStyle.THIN, null, false);
    style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
    cell.setCellStyle(style);
}

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

License:Open Source License

private void construitEnteteMarche(Workbook wb, AbstractEntity abstractEntity, Sheet sheet) {
    Row row = createRowGeneric(sheet, 6, 500);
    Cell cell = row.createCell(0);/*from ww w  .j  av  a2s. c om*/
    cell.setCellStyle(createCellWithBorderAndColor(wb, BorderStyle.THIN, IndexedColors.YELLOW, false));

    if (abstractEntity instanceof SousMarche) {
        cell.setCellValue(((SousMarche) abstractEntity).getLibelle());
    }

    cell = row.createCell(1);
    cell.setCellStyle(createCellWithBorderAndColor(wb, BorderStyle.THIN, IndexedColors.YELLOW, false));

    if (abstractEntity instanceof SousMarche) {
        cell.setCellValue(((SousMarche) abstractEntity).getFournisseur().getNom());
    } else if (abstractEntity instanceof Fournisseur) {
        cell.setCellValue(((Fournisseur) abstractEntity).getNom());
    } else {
        cell.setCellValue("SANS MARCHE NI FOURNISSEUR");
    }
}

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

License:Open Source License

private void construitEnteteArticle(Workbook wb, Sheet sheet) {
    Row row = createRowGeneric(sheet, 8, 500);
    row.createCell(0).setCellValue("Rfrence");
    row.createCell(1).setCellValue("Dsignation");
    row.createCell(2).setCellValue("Prix");
    row.createCell(3).setCellValue("Colisage");
    row.createCell(4).setCellValue("Commande");
    row.createCell(5).setCellValue("Total");

    CellStyle style = createCellWithBorderAndColor(wb, BorderStyle.THIN, IndexedColors.TAN, false);

    row.getCell(0).setCellStyle(style);//from  ww w .  ja  v  a 2 s  . c  o  m
    row.getCell(1).setCellStyle(style);
    row.getCell(2).setCellStyle(style);
    row.getCell(3).setCellStyle(style);
    row.getCell(4).setCellStyle(style);
    row.getCell(5).setCellStyle(style);
}

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

License:Open Source License

private void remplitLigneArticle(Workbook wb, List<ArticleDemande> listeArticleDemande, Sheet sheet) {
    int numRow = 10;
    Map<ArticleCatalogue, Integer> mapArticleQuantite = new HashMap<>();

    for (ArticleDemande articleDemande : listeArticleDemande) {
        ArticleCatalogue articleCatalogue = articleDemande.getArticleCatalogue();
        Integer quantite = mapArticleQuantite.get(articleCatalogue);
        if (quantite != null) {
            mapArticleQuantite.replace(articleCatalogue, quantite + articleDemande.getQuantiteCommande());
        } else {//from  w  ww  .j a  v a2  s .com
            mapArticleQuantite.put(articleCatalogue, articleDemande.getQuantiteCommande());
        }
    }

    List<ArticleCatalogue> listeArticleCatalogue = new ArrayList(mapArticleQuantite.keySet());
    Collections.sort(listeArticleCatalogue, new ArticleCatalogueComparator());

    for (ArticleCatalogue articleCatalogue : listeArticleCatalogue) {
        Row row = createRowGeneric(sheet, numRow, 500);
        row.createCell(0).setCellValue(articleCatalogue.getReference());
        row.createCell(1).setCellValue(articleCatalogue.getLibelle());
        row.createCell(2).setCellValue(articleCatalogue.getPrix());
        row.createCell(3).setCellValue(articleCatalogue.getLibelleColisage());
        row.createCell(4).setCellValue(mapArticleQuantite.get(articleCatalogue));

        String strFormula = "C" + (numRow + 1) + "*E" + (numRow + 1) + "";
        Cell cell = row.createCell(5);
        cell.setCellType(CellType.FORMULA);
        cell.setCellFormula(strFormula);

        CellStyle style = createCellWithBorderAndColor(wb, BorderStyle.THIN, IndexedColors.LIGHT_YELLOW, false);
        CellStyle stylePrix = createCellWithBorderAndColor(wb, BorderStyle.THIN, IndexedColors.LIGHT_YELLOW,
                false);
        stylePrix.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));

        row.getCell(0).setCellStyle(style);
        row.getCell(1).setCellStyle(style);
        row.getCell(2).setCellStyle(stylePrix);
        row.getCell(3).setCellStyle(style);
        row.getCell(4).setCellStyle(style);
        row.getCell(5).setCellStyle(stylePrix);
        numRow++;
    }
}

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

License:Open Source License

private static void createRow(XSSFSheet worksheet, XSSFWorkbook workbook, ArticleStock article,
        CatalogueService catalogueService, int rowNumber) throws IOException {

    int col = 0;//from ww  w.j ava 2  s . c  o m
    XSSFCellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    XSSFCellStyle cellImageStyle = workbook.createCellStyle();
    cellImageStyle.setBorderBottom(BorderStyle.THIN);
    cellImageStyle.setBorderLeft(BorderStyle.THIN);
    cellImageStyle.setBorderRight(BorderStyle.THIN);
    cellImageStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellImageStyle.setAlignment(HorizontalAlignment.CENTER);

    if (rowNumber != 1) {
        cellStyle.setBorderTop(BorderStyle.THIN);
    }

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

    XSSFRow row = worksheet.createRow(rowNumber);
    row.setHeight((short) ROW_HEIGHT_TWIPS);//80px 1600
    // Photo
    File image = null;

    try {
        image = catalogueService.getFilePieceJointe(article.getArticleCatalogue().getPhotoArticleCatalogue());
    } catch (IllegalArgumentException e) {
        log.warn("No image to display for article " + article.getArticleCatalogue().getLibelle());
    }
    XSSFCell cell = row.createCell(col);
    cell.setCellStyle(cellImageStyle);

    if (image != null)
        addImage(workbook, worksheet, image, rowNumber);
    col = col + 1;

    // Rfrence
    cell = row.createCell(col);
    cell.setCellStyle(cellStyle);
    col = col + 1;
    cell.setCellValue(article.getReferenceArticleStock());

    // Libell
    cell = row.createCell(col);
    cell.setCellStyle(cellStyle);
    col = col + 1;
    cell.setCellValue(article.getArticleCatalogue().getLibelle());

    // Appock Stock
    cell = row.createCell(col);
    cell.setCellStyle(cellStyle);
    col = col + 1;
    cell.setCellValue(article.getQuantiteStock());
    cell.setCellType(CellType.NUMERIC);

    // Stock reel
    cell = row.createCell(col);
    cell.setCellStyle(cellStyle);
    cell.setCellType(CellType.NUMERIC);

}

From source file:nl.detoren.ijc.io.OutputExcel.java

License:Open Source License

private void borderFull(Cell cell) {
    if (cell != null) {
        Workbook wb = cell.getRow().getSheet().getWorkbook();
        CellStyle style = wb.createCellStyle();
        style.setBorderBottom(BorderStyle.THIN);
        style.setBorderTop(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);
        style.setBorderLeft(BorderStyle.THIN);
        cell.setCellStyle(style);//from   w ww .  j  av a 2  s  . c  o m
    }
}

From source file:nl.detoren.ijc.io.OutputExcel.java

License:Open Source License

private void borderLeft(Cell cell) {
    if (cell != null) {
        Workbook wb = cell.getRow().getSheet().getWorkbook();
        CellStyle style = wb.createCellStyle();
        style.setBorderLeft(BorderStyle.THIN);
        cell.setCellStyle(style);/*from  w ww .  ja v a2s  . c  o m*/
    }
}