Example usage for org.apache.poi.ss.usermodel CellStyle setAlignment

List of usage examples for org.apache.poi.ss.usermodel CellStyle setAlignment

Introduction

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

Prototype

void setAlignment(HorizontalAlignment align);

Source Link

Document

set the type of horizontal alignment for the cell

Usage

From source file:com.sec.ose.osi.report.standard.SummarySheetTemplate.java

License:Open Source License

/**
 * write summary info//w  w  w.j  a v a  2 s . c o  m
 * 
 * @param summaryRowList
 */
public void writeSummaryRow(ArrayList<SummaryRow> summaryRowList) {
    CellStyle rightStyle = getCellStyle(WHITE, getFont(FONT_BLACK, (short) 10, false));
    rightStyle.setAlignment(CellStyle.ALIGN_RIGHT);

    int curRow = ROW_START;
    for (SummaryRow summaryRow : summaryRowList) {
        Row row = sheet.createRow(curRow++);

        Cell cell = row.createCell(ISheetTemplate.COL_A);
        cell.setCellValue(summaryRow.getClassification());
        cell.setCellStyle(normalStyle);

        cell = row.createCell(ISheetTemplate.COL_B);
        cell.setCellValue(summaryRow.getProjectName());
        cell.setCellStyle(leftStyle);

        cell = row.createCell(ISheetTemplate.COL_C);
        cell.setCellValue(summaryRow.getScanDate());
        cell.setCellStyle(normalStyle);

        cell = row.createCell(ISheetTemplate.COL_D);
        cell.setCellValue(DateUtil.translateTimeFormatToColon(summaryRow.getScanTime()));
        cell.setCellStyle(normalStyle);

        cell = row.createCell(ISheetTemplate.COL_E);
        cell.setCellValue(summaryRow.getPendingFileCount());
        cell.setCellStyle(normalStyle);

        cell = row.createCell(ISheetTemplate.COL_F);
        cell.setCellValue(summaryRow.getPendingPercent());
        cell.setCellStyle(normalStyle);

        cell = row.createCell(ISheetTemplate.COL_G);
        cell.setCellValue(summaryRow.getTotalFileCount());
        cell.setCellStyle(normalStyle);

        cell = row.createCell(ISheetTemplate.COL_H);
        cell.setCellValue(summaryRow.getExceptionalFileCount());
        cell.setCellStyle(normalStyle);

        cell = row.createCell(ISheetTemplate.COL_I);
        cell.setCellValue(summaryRow.getBytes());
        cell.setCellStyle(rightStyle);

        cell = row.createCell(ISheetTemplate.COL_J);
        cell.setCellValue(summaryRow.getTotalIdentifiedFileCount());
        cell.setCellStyle(normalStyle);

        int percent = (summaryRow.getCurrentPendingFileCount() * 100 / summaryRow.getPendingFileCount());
        cell = row.createCell(ISheetTemplate.COL_K);
        cell.setCellValue(summaryRow.getCurrentPendingFileCount() + " (" + percent + "%)");
        cell.setCellStyle(normalStyle);
    }

}

From source file:com.shiyq.poi.HSSFTest.java

public static boolean createExcel(String excelName) {
    boolean created = false;
    Workbook wb = new HSSFWorkbook();
    Font font = wb.createFont();//w w w .  ja  v a  2  s. c  o  m
    font.setBold(true);
    CellStyle headStyle = wb.createCellStyle();
    headStyle.setFont(font);

    Sheet sheet = wb.createSheet("20165???");
    String[] head = { "??", "?", "??", "???", "????",
            "????", "?", "??", "", "",
            "??" };
    String[] code = { "card_no", "card_type", "spread_time", "spread_emp_no", "spread_emp_name", "owner_name",
            "plate", "blance", "start_time", "end_time", "month_money" };

    List<Map<String, Object>> list = setList();
    setSheet(sheet, list, head, headStyle, code);
    //
    int startRow = 4;
    int endRow = 8;
    int startColumn = head.length + 4;
    int endColumn = head.length + 8;

    String describe = "1?" + (new Date().toString()) + "\n";
    describe += "2.\n";
    describe += "3.?2016-4-42016-5-4";
    CellStyle descStyle = wb.createCellStyle();
    descStyle.setAlignment(CellStyle.ALIGN_LEFT);
    descStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    setSheet(sheet, startRow, endRow, startColumn, endColumn, describe, descStyle);

    Sheet sheet1 = wb.createSheet("20166???");
    setSheet(sheet1, list, head, headStyle, code);
    setSheet(sheet1, startRow, endRow, startColumn, endColumn, describe, descStyle);
    try {
        try (FileOutputStream fileOut = new FileOutputStream(excelName)) {
            wb.write(fileOut);
            created = true;
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(HSSFTest.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(HSSFTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    return created;
}

From source file:com.skt.adcas.lte.action.DownLinkByNMSAction.java

private static void createCell(Workbook wb, Row row, short column, String value, short halign) {
    Cell cell = row.createCell(column);/*from w  w w.  j a  v a 2s.  c o  m*/
    cell.setCellValue(value);
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cell.setCellStyle(cellStyle);

}

From source file:com.skt.adcas.lte.action.DownLinkByNMSAction.java

private static void createCell(Workbook wb, Row row, short column, double value, short halign) {
    Cell cell = row.createCell(column);//from ww w  .  j  a v  a  2 s . co  m
    cell.setCellValue(value);
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cell.setCellStyle(cellStyle);

}

From source file:com.skt.adcas.lte.action.DownLinkByNMSAction.java

private static void createCell(Workbook wb, Row row, short column, short halign, short valign, String text) {
    Cell cell = row.createCell(column);/* w  w w  . j av  a  2  s.c  o  m*/
    cell.setCellValue(text);
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(valign);
    cell.setCellStyle(cellStyle);
}

From source file:com.tecnosur.util.Excel.java

private static void createTituloCell(HSSFWorkbook wb, Row row, int column, short halign, short valign,
        String strContenido) {//from   w w  w  .  j ava  2 s .c  o m

    CreationHelper ch = wb.getCreationHelper();
    Cell cell = row.createCell(column);
    cell.setCellValue(ch.createRichTextString(strContenido));

    HSSFFont cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 11);
    cellFont.setFontName(HSSFFont.FONT_ARIAL);
    cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(valign);
    cellStyle.setFont(cellFont);
    cell.setCellStyle(cellStyle);

}

From source file:com.tecnosur.util.Excel.java

private static void createCell(HSSFWorkbook wb, Row row, int column, short halign, short valign,
        String strContenido, boolean booBorde, boolean booCabecera) {
    CreationHelper ch = wb.getCreationHelper();
    Cell cell = row.createCell(column);/*  www. jav  a  2  s  . c om*/
    HSSFFont cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 8);
    cellFont.setFontName(HSSFFont.FONT_ARIAL);
    cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    cell.setCellValue(ch.createRichTextString(strContenido));
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(valign);
    cellStyle.setFont(cellFont);
    if (booBorde) {
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBottomBorderColor((short) 8);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setLeftBorderColor((short) 8);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setRightBorderColor((short) 8);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setTopBorderColor((short) 8);
    }
    if (booCabecera) {
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBottomBorderColor((short) 8);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setLeftBorderColor((short) 8);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setRightBorderColor((short) 8);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setTopBorderColor((short) 8);

        cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
        cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    }
    cell.setCellStyle(cellStyle);
}

From source file:com.tm.hiber.service.util.DatabaseUtil.java

/**
 *
 * @param objFile//from   w ww  .j a v a 2  s  .c  om
 * @param objJTable
 * @return number of records exported
 */
public int exportData(File objFile, JTable objJTable) throws FileNotFoundException, IOException {
    int response = 0;

    if (objFile == null) {
        return response;
    }

    DefaultTableModel tm = (DefaultTableModel) objJTable.getModel();
    Object[] rows = tm.getDataVector().toArray();

    JTableHeader columnNames = objJTable.getTableHeader();
    TableColumnModel columnModel = columnNames.getColumnModel();
    int columnCount = columnModel.getColumnCount();
    Vector<String> vecColumnNames = new Vector<String>();
    for (int c = 0; c < columnCount; c++) {
        vecColumnNames.add(columnModel.getColumn(c).getHeaderValue().toString());
    }

    HSSFWorkbook exportReadyWorkbook = new HSSFWorkbook();
    HSSFSheet dataSheet = exportReadyWorkbook.createSheet(getExportSheetName());

    if (vecColumnNames.size() > 0) {
        int columnCounter = 0;
        Row objHSSFColumnName = dataSheet.createRow(0);

        for (String strColumnName : vecColumnNames) {
            /* Set Header CSS */

            Cell objHSSFCell = objHSSFColumnName.createCell(columnCounter);
            objHSSFCell.setCellValue(strColumnName);
            CellStyle csll = exportReadyWorkbook.createCellStyle();
            Font objFont = exportReadyWorkbook.createFont();
            objFont.setFontName("Calibri");
            objFont.setColor(IndexedColors.BLACK.index);
            objFont.setBold(true);
            csll.setFont(objFont);
            csll.setFillBackgroundColor(HSSFColor.YELLOW.index);
            csll.setFillForegroundColor(HSSFColor.YELLOW.index);
            csll.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            csll.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            //csll.setWrapText(true);
            objHSSFCell.setCellStyle(csll);
            columnCounter++;
        }
    }

    if (rows != null && rows.length > 0) {
        /* Set Data into Sheet */
        for (int i = 0; i < rows.length; i++) {
            Vector objCellsData = (Vector) rows[i];
            Row objHSSFRow = dataSheet.createRow(i + 1);
            if (objCellsData != null && objCellsData.size() > 0) {
                for (int j = 0; j < objCellsData.size(); j++) {

                    /* Set Cell Data CSS */

                    Cell objHSSFCell = objHSSFRow.createCell(j);
                    CellStyle csll = exportReadyWorkbook.createCellStyle();
                    Font objFont = exportReadyWorkbook.createFont();
                    objFont.setColor(IndexedColors.BLACK.index);
                    objFont.setBold(false);
                    objFont.setFontName("Calibri");
                    csll.setFont(objFont);
                    csll.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
                    csll.setFillBackgroundColor(IndexedColors.WHITE.index);
                    csll.setFillForegroundColor(IndexedColors.WHITE.index);

                    csll.setAlignment(HSSFCellStyle.ALIGN_CENTER);

                    //csll.setWrapText(true);
                    csll.setBorderBottom(CellStyle.BORDER_THIN);
                    csll.setBorderTop(CellStyle.BORDER_THIN);

                    csll.setBottomBorderColor(HSSFColor.GREY_25_PERCENT.index);
                    csll.setTopBorderColor(HSSFColor.GREY_50_PERCENT.index);

                    objHSSFCell.setCellStyle(csll);
                    Object cellData = objCellsData.get(j);
                    objHSSFCell.setCellValue((String) cellData);
                }
            }
        }

        for (int i = 0; i < columnCount; i++) {
            if (i == 2) {
                dataSheet.setColumnWidth(i, 30 * 256);
            } else {
                dataSheet.autoSizeColumn(i);
            }
        }

        /* Write File */
        FileOutputStream objFileOutputStream = new FileOutputStream(objFile);
        exportReadyWorkbook.write(objFileOutputStream);
        objFileOutputStream.flush();
        objFileOutputStream.close();
        response = rows.length;
    }

    return response;
}

From source file:com.vincestyling.apkinfoextractor.core.export.ExportToExcel.java

License:Apache License

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<>();
    String fontName = getAvaliableTitleFont();
    CellStyle style;

    Font font = wb.createFont();/*from   w w w. j  a va  2s. c o m*/
    font.setFontName(fontName);
    font.setFontHeightInPoints((short) 14);
    font.setColor(IndexedColors.BROWN.getIndex());

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(font);
    styles.put("title", style);

    font = wb.createFont();
    font.setFontName(fontName);
    font.setFontHeightInPoints((short) 14);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setColor(IndexedColors.WHITE.getIndex());

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFont(font);
    style.setWrapText(true);
    setBorder(style);
    styles.put("header", style);

    font = wb.createFont();
    font.setFontName(fontName);
    font.setFontHeightInPoints((short) 12);
    font.setColor(IndexedColors.BLACK.getIndex());

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setWrapText(true);
    style.setFont(font);
    setBorder(style);
    styles.put("cell", style);

    return styles;
}

From source file:com.wabacus.system.assistant.StandardExcelAssistant.java

License:Open Source License

public CellStyle getTitleCellStyleForStandardExcel(Workbook workbook) {
    CellStyle cs = workbook.createCellStyle();
    cs.setBorderTop(CellStyle.BORDER_THIN);
    cs.setBorderLeft(CellStyle.BORDER_THIN);
    cs.setBorderBottom(CellStyle.BORDER_THIN);
    cs.setBorderRight(CellStyle.BORDER_THIN);
    cs.setWrapText(true);/*from   www  . j ava 2  s.c om*/
    cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cs.setAlignment(CellStyle.ALIGN_CENTER);
    cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cs.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
    Font font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    font.setFontHeightInPoints((short) 10);
    cs.setFont(font);
    //cs.setUserStyleName("wabacus_title_rowstyle");//
    return cs;
}