Example usage for org.apache.poi.xssf.usermodel XSSFCellStyle getWrapText

List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle getWrapText

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFCellStyle getWrapText.

Prototype

@Override
public boolean getWrapText() 

Source Link

Document

Whether the text should be wrapped

Usage

From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-6]  ?  :  ? ?(?, ? )? //from  ww  w  .  j a v a2 s . com
 */
@Test
public void testModifyCellAttribute() throws Exception {

    try {
        LOGGER.debug("testModifyCellAttribute start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testModifyCellAttribute.xlsx");

        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            LOGGER.debug("Delete file....{}", sb.toString());
        }

        Workbook wbTmp = new XSSFWorkbook();
        wbTmp.createSheet();

        //  ? ?
        excelService.createWorkbook(wbTmp, sb.toString());

        //  ? 
        XSSFWorkbook wb = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        LOGGER.debug("testModifyCellAttribute after loadWorkbook....");

        Sheet sheet = wb.createSheet("cell test sheet2");
        sheet.setColumnWidth((short) 3, (short) 200); // column Width

        CellStyle cs = wb.createCellStyle();
        XSSFFont font = wb.createFont();
        font.setFontHeight(16);
        font.setBoldweight((short) 3);
        font.setFontName("fixedsys");

        cs.setFont(font);
        cs.setAlignment(XSSFCellStyle.ALIGN_RIGHT); // cell 
        cs.setWrapText(true);

        for (int i = 0; i < 100; i++) {
            Row row = sheet.createRow(i);
            row.setHeight((short) 300); // row? height 

            for (int j = 0; j < 5; j++) {
                Cell cell = row.createCell(j);
                cell.setCellValue(new XSSFRichTextString("row " + i + ", cell " + j));
                cell.setCellStyle(cs);
            }
        }

        //  ? 
        FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();

        //////////////////////////////////////////////////////////////////////////
        // ?
        XSSFWorkbook wbT = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        Sheet sheetT = wbT.getSheet("cell test sheet2");
        LOGGER.debug("getNumCellStyles : {}", wbT.getNumCellStyles());

        XSSFCellStyle cs1 = (XSSFCellStyle) wbT.getCellStyleAt((short) (wbT.getNumCellStyles() - 1));

        XSSFFont fontT = cs1.getFont();
        LOGGER.debug("font getFontHeight : {}", fontT.getFontHeight());
        LOGGER.debug("font getBoldweight : {}", fontT.getBoldweight());
        LOGGER.debug("font getFontName : {}", fontT.getFontName());
        LOGGER.debug("getAlignment : {}", cs1.getAlignment());
        LOGGER.debug("getWrapText : {}", cs1.getWrapText());

        for (int i = 0; i < 100; i++) {
            Row row1 = sheetT.getRow(i);
            for (int j = 0; j < 5; j++) {
                Cell cell1 = row1.getCell(j);
                LOGGER.debug("row {}, cell {} : {}", i, j, cell1.getRichStringCellValue());
                assertEquals(320, fontT.getFontHeight());
                assertEquals(400, fontT.getBoldweight());
                LOGGER.debug("fontT.getBoldweight()? ? 400? ?");

                assertEquals(XSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment());
                assertTrue(cs1.getWrapText());
            }
        }

    } catch (Exception e) {
        LOGGER.error(e.toString());
        throw new Exception(e);
    } finally {
        LOGGER.debug("testModifyCellAttribute end....");
    }
}

From source file:net.mcnewfamily.rmcnew.shared.Util.java

License:Open Source License

public static void copyXSSFCellStyle(XSSFCell srcCell, XSSFCell destCell) {
    XSSFCellStyle srcCellStyle = srcCell.getCellStyle();
    XSSFCellStyle destCellStyle = destCell.getCellStyle();
    //        destCellStyle.cloneStyleFrom(srcCellStyle);
    destCellStyle.setAlignment(srcCellStyle.getAlignment());
    destCellStyle.setVerticalAlignment(srcCellStyle.getVerticalAlignment());
    destCellStyle.setFont(srcCellStyle.getFont());
    destCellStyle.setBorderBottom(srcCellStyle.getBorderBottom());
    destCellStyle.setBorderLeft(srcCellStyle.getBorderLeft());
    destCellStyle.setBorderRight(srcCellStyle.getBorderRight());
    destCellStyle.setBorderTop(srcCellStyle.getBorderTop());
    destCellStyle.setFillPattern(srcCellStyle.getFillPattern());
    // foreground color must be set before background color is set
    destCellStyle.setFillForegroundColor(srcCellStyle.getFillForegroundColor());
    destCellStyle.setFillBackgroundColor(srcCellStyle.getFillBackgroundColor());
    destCellStyle.setIndention(srcCellStyle.getIndention());
    destCellStyle.setWrapText(srcCellStyle.getWrapText());
    destCell.setCellStyle(destCellStyle);
}

From source file:org.bbreak.excella.core.test.util.TestUtil.java

License:Open Source License

private static String getCellStyleString(XSSFCellStyle cellStyle) {
    StringBuffer sb = new StringBuffer();
    if (cellStyle != null) {
        XSSFFont font = cellStyle.getFont();
        sb.append("Font=").append(font.getCTFont()).append(",");
        sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(",");
        sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(",");
        sb.append("Hidden=").append(cellStyle.getHidden()).append(",");
        sb.append("Locked=").append(cellStyle.getLocked()).append(",");
        sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(",");
        sb.append("WrapText=").append(cellStyle.getWrapText()).append(",");
        sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(",");
        sb.append("Rotation=").append(cellStyle.getRotation()).append(",");
        sb.append("Indention=").append(cellStyle.getIndention()).append(",");
        sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(",");
        sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(",");
        sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(",");
        sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(",");

        sb.append("LeftBorderColor=").append(getXSSFColorString(cellStyle.getLeftBorderXSSFColor()))
                .append(",");
        sb.append("RightBorderColor=").append(getXSSFColorString(cellStyle.getRightBorderXSSFColor()))
                .append(",");
        sb.append("TopBorderColor=").append(getXSSFColorString(cellStyle.getTopBorderXSSFColor())).append(",");
        sb.append("BottomBorderColor=").append(getXSSFColorString(cellStyle.getBottomBorderXSSFColor()))
                .append(",");

        sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(",");
        sb.append("FillForegroundColor=").append(getXSSFColorString(cellStyle.getFillForegroundXSSFColor()))
                .append(",");
        sb.append("FillBackgroundColor=").append(getXSSFColorString(cellStyle.getFillBackgroundXSSFColor()));
    }//w ww  . ja  v a2s.  co  m
    return sb.toString();
}

From source file:org.bbreak.excella.reports.ReportsTestUtil.java

License:Open Source License

/**
 * XSSF????/*from   w w  w .j a v a  2 s .co  m*/
 * 
 * @param cellStyle 
 * @return ??
 */
private static String getCellStyleString(XSSFCellStyle cellStyle) {
    StringBuffer sb = new StringBuffer();
    if (cellStyle != null) {
        XSSFFont font = cellStyle.getFont();
        sb.append("Font=").append(font.getCTFont()).append(",");
        sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(",");
        sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(",");
        sb.append("Hidden=").append(cellStyle.getHidden()).append(",");
        sb.append("Locked=").append(cellStyle.getLocked()).append(",");
        sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(",");
        sb.append("WrapText=").append(cellStyle.getWrapText()).append(",");
        sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(",");
        sb.append("Rotation=").append(cellStyle.getRotation()).append(",");
        sb.append("Indention=").append(cellStyle.getIndention()).append(",");
        sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(",");
        sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(",");
        sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(",");
        sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(",");

        sb.append("LeftBorderColor=").append(getXSSFColorString(cellStyle.getLeftBorderXSSFColor()))
                .append(",");
        sb.append("RightBorderColor=").append(getXSSFColorString(cellStyle.getRightBorderXSSFColor()))
                .append(",");
        sb.append("TopBorderColor=").append(getXSSFColorString(cellStyle.getTopBorderXSSFColor())).append(",");
        sb.append("BottomBorderColor=").append(getXSSFColorString(cellStyle.getBottomBorderXSSFColor()))
                .append(",");

        sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(",");
        try {
            sb.append("FillForegroundColor=").append(getXSSFColorString(cellStyle.getFillForegroundXSSFColor()))
                    .append(",");
        } catch (NullPointerException e) {
            // POI-3.7???
            sb.append("FillForegroundColor=none,");
        }

        try {
            sb.append("FillBackgroundColor=")
                    .append(getXSSFColorString(cellStyle.getFillBackgroundXSSFColor()));
        } catch (NullPointerException e) {
            // POI-3.7???
            sb.append("FillBackgroundColor=none,");
        }
    }
    return sb.toString();
}