Example usage for org.apache.poi.ss.usermodel Sheet isDisplayFormulas

List of usage examples for org.apache.poi.ss.usermodel Sheet isDisplayFormulas

Introduction

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

Prototype

boolean isDisplayFormulas();

Source Link

Document

Returns if formulas are displayed

Usage

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

License:Open Source License

/**
 * /*from   www. j av a  2s.  c o  m*/
 * 
 * @param expected 
 * @param actual 
 * @param isActCopyOfExp ??????true
 * @throws ReportsCheckException 
 */
public static void checkSheet(Sheet expected, Sheet actual, boolean isActCopyOfExp)
        throws ReportsCheckException {

    List<CheckMessage> errors = new ArrayList<CheckMessage>();

    Workbook expectedWorkbook = expected.getWorkbook();
    Workbook actualWorkbook = actual.getWorkbook();

    if (log.isDebugEnabled()) {
        log.debug("[" + actualWorkbook.getSheetName(actualWorkbook.getSheetIndex(actual))
                + "] check start!");
    }

    // ----------------------
    // ????
    // ----------------------
    // ??
    String eSheetName = expectedWorkbook.getSheetName(expectedWorkbook.getSheetIndex(expected));
    String aSheetName = actualWorkbook.getSheetName(actualWorkbook.getSheetIndex(actual));

    if (!isActCopyOfExp) {
        if (!eSheetName.equals(aSheetName)) {
            errors.add(new CheckMessage("??", eSheetName, aSheetName));
        }
    }

    // ?
    String ePrintSetupString = getPrintSetupString(expected.getPrintSetup());
    String aPrintSetupString = getPrintSetupString(actual.getPrintSetup());

    if (!ePrintSetupString.equals(aPrintSetupString)) {
        errors.add(new CheckMessage("?", ePrintSetupString, aPrintSetupString));
    }

    // ?
    String eHeaderString = getHeaderString(expected.getHeader());
    String aHeaderString = getHeaderString(actual.getHeader());
    if (!eHeaderString.equals(aHeaderString)) {
        errors.add(new CheckMessage("", eHeaderString, aHeaderString));
    }
    String eFooterString = getFooterString(expected.getFooter());
    String aFooterString = getFooterString(actual.getFooter());
    if (!eFooterString.equals(aFooterString)) {
        errors.add(new CheckMessage("", eFooterString, aFooterString));
    }

    // 
    String eBreaksString = getBreaksString(expected);
    String aBreaksString = getBreaksString(actual);
    log.debug(eBreaksString + "/" + aBreaksString);
    if (!eBreaksString.equals(aBreaksString)) {
        errors.add(new CheckMessage("", eBreaksString, aBreaksString));
    }

    // ?
    String expectedPrintArea = expectedWorkbook.getPrintArea(expectedWorkbook.getSheetIndex(expected));
    String actualPrintArea = actualWorkbook.getPrintArea(actualWorkbook.getSheetIndex(actual));
    if (expectedPrintArea != null || actualPrintArea != null) {
        // ????????Null?????????????
        // if ( expectedPrintArea == null || actualPrintArea == null || !equalPrintArea( expectedPrintArea, actualPrintArea, isActCopyOfExp)) {
        // errors.add( new CheckMessage( "?", expectedPrintArea, actualPrintArea));
        // }
        if (!isActCopyOfExp) {
            if (expectedPrintArea == null || actualPrintArea == null
                    || !expectedPrintArea.equals(actualPrintArea)) {
                errors.add(new CheckMessage("?", expectedPrintArea, actualPrintArea));
            }
        }
    }

    // (?)
    String ePaneInformationString = getPaneInformationString(expected.getPaneInformation());
    String aPaneInformationString = getPaneInformationString(actual.getPaneInformation());

    if (!ePaneInformationString.equals(aPaneInformationString)) {
        errors.add(new CheckMessage("(?)", expectedPrintArea, actualPrintArea));
    }

    // ??????

    // ?????

    // ?????

    // 

    // 
    if (expected.isDisplayGridlines() ^ actual.isDisplayGridlines()) {
        errors.add(new CheckMessage("",
                String.valueOf(expected.isDisplayGridlines()), String.valueOf(actual.isDisplayGridlines())));
    }

    // ?
    if (expected.isDisplayRowColHeadings() ^ actual.isDisplayRowColHeadings()) {
        errors.add(new CheckMessage("?", String.valueOf(expected.isDisplayRowColHeadings()),
                String.valueOf(actual.isDisplayRowColHeadings())));
    }

    // ?
    if (expected.isDisplayFormulas() ^ actual.isDisplayFormulas()) {
        errors.add(new CheckMessage("?", String.valueOf(expected.isDisplayFormulas()),
                String.valueOf(actual.isDisplayFormulas())));
    }
    // ??
    if (expected.getNumMergedRegions() != actual.getNumMergedRegions()) {
        errors.add(new CheckMessage("??", String.valueOf(expected.getNumMergedRegions()),
                String.valueOf(actual.getNumMergedRegions())));
    }

    for (int i = 0; i < actual.getNumMergedRegions(); i++) {

        CellRangeAddress actualAddress = null;
        if (expected instanceof HSSFSheet) {
            actualAddress = ((HSSFSheet) actual).getMergedRegion(i);
        } else if (expected instanceof XSSFSheet) {
            actualAddress = ((XSSFSheet) actual).getMergedRegion(i);
        }

        StringBuffer expectedAdressBuffer = new StringBuffer();
        boolean equalAddress = false;
        for (int j = 0; j < expected.getNumMergedRegions(); j++) {
            CellRangeAddress expectedAddress = null;
            if (expected instanceof HSSFSheet) {
                expectedAddress = ((HSSFSheet) expected).getMergedRegion(j);
            } else if (expected instanceof XSSFSheet) {
                expectedAddress = ((XSSFSheet) expected).getMergedRegion(j);
            }
            if (expectedAddress.toString().equals(actualAddress.toString())) {
                equalAddress = true;
                break;
            }
            CellReference crA = new CellReference(expectedAddress.getFirstRow(),
                    expectedAddress.getFirstColumn());
            CellReference crB = new CellReference(expectedAddress.getLastRow(),
                    expectedAddress.getLastColumn());
            expectedAdressBuffer.append(" [" + crA.formatAsString() + ":" + crB.formatAsString() + "]");
        }

        if (!equalAddress) {
            errors.add(new CheckMessage("??", expectedAdressBuffer.toString(),
                    actualAddress.toString()));
        }

    }

    int maxColumnNum = -1;
    if (expected instanceof HSSFSheet) {
        maxColumnNum = HSSF_MAX_COLUMN_NUMBER;
    } else if (expected instanceof XSSFSheet) {
        maxColumnNum = XSSF_MAX_COLUMN_NUMBER;
    }
    for (int i = 0; i < maxColumnNum; i++) {
        try {
            // 
            checkCellStyle(expected.getWorkbook(), expected.getColumnStyle(i), actual.getWorkbook(),
                    actual.getColumnStyle(i));
        } catch (ReportsCheckException e) {
            CheckMessage checkMessage = e.getCheckMessages().iterator().next();
            checkMessage.setMessage("[" + i + "]" + checkMessage.getMessage());
            errors.add(checkMessage);
        }

        // 
        if (expected.getColumnWidth(i) != actual.getColumnWidth(i)) {
            errors.add(new CheckMessage("[" + i + "]", String.valueOf(expected.getColumnWidth(i)),
                    String.valueOf(actual.getColumnWidth(i))));
        }
    }

    // ???
    if (expected.getLastRowNum() != actual.getLastRowNum()) {
        // ??????
        if (expected.getLastRowNum() < actual.getLastRowNum()) {
            int lastRowIndex = -1;
            if (expected instanceof HSSFSheet) {
                lastRowIndex = 0;
            }
            Iterator<Row> rowIterator = actual.rowIterator();
            while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                // ?????
                Iterator<Cell> cellIterator = row.cellIterator();
                while (cellIterator.hasNext()) {
                    Cell cell = cellIterator.next();
                    if (cell.getCellTypeEnum() != CellType.BLANK) {
                        lastRowIndex = row.getRowNum();
                        break;
                    }
                }
            }
            if (expected.getLastRowNum() != lastRowIndex) {
                errors.add(new CheckMessage("", String.valueOf(expected.getLastRowNum()),
                        String.valueOf(lastRowIndex)));
            }
        } else {
            errors.add(new CheckMessage("", String.valueOf(expected.getLastRowNum()),
                    String.valueOf(actual.getLastRowNum())));
        }

    }

    if (errors.isEmpty()) {
        for (int i = 0; i <= expected.getLastRowNum(); i++) {
            try {
                checkRow(expected.getRow(i), actual.getRow(i));
            } catch (ReportsCheckException e) {
                errors.addAll(e.getCheckMessages());
            }
        }
    }

    if (!errors.isEmpty()) {
        if (log.isErrorEnabled()) {
            for (CheckMessage message : errors) {
                log.error("?[" + message.getMessage() + "]");
                log.error(":" + message.getExpected());
                log.error(":" + message.getActual());
            }
        }
        throw new ReportsCheckException(errors);
    }

    if (log.isDebugEnabled()) {
        log.debug("[" + actualWorkbook.getSheetName(actualWorkbook.getSheetIndex(actual))
                + "] check end.");
    }

}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.BasicReportTest.java

License:Open Source License

@Test
public void testRunReportWithJpegXls() throws BirtException, IOException {

    InputStream inputStream = runAndRenderReport("SimpleWithJpeg.rptdesign", "xls");
    assertNotNull(inputStream);//w  w w. ja v a 2  s  .co  m
    try {

        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Simple Test Report", workbook.getSheetAt(0).getSheetName());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(false, sheet.isDisplayFormulas());
        assertEquals(true, sheet.isDisplayGridlines());
        assertEquals(true, sheet.isDisplayRowColHeadings());
        assertEquals(true, sheet.isDisplayZeros());
        performSimpleWithJpegTests(sheet);

        // Unfortunately it's not currently possible/easy to check the dimensions of images using POI
        // So the XL file has to be opened manually for verification
    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.BasicReportTest.java

License:Open Source License

@Test
public void testRunReportWithJpegXlsFormulasRenderOption() throws BirtException, IOException {

    displayFormulas = true;/*from w  w  w .java 2 s .c  om*/
    InputStream inputStream = runAndRenderReport("SimpleWithJpeg.rptdesign", "xls");
    assertNotNull(inputStream);
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Simple Test Report", workbook.getSheetAt(0).getSheetName());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(true, sheet.isDisplayFormulas());
        assertEquals(true, sheet.isDisplayGridlines());
        assertEquals(true, sheet.isDisplayRowColHeadings());
        assertEquals(true, sheet.isDisplayZeros());
        performSimpleWithJpegTests(sheet);
    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.BasicReportTest.java

License:Open Source License

@Test
public void testRunReportWithJpegXlsFormulasReport() throws BirtException, IOException {

    InputStream inputStream = runAndRenderReport("SimpleWithJpegDisplayFormulas.rptdesign", "xls");
    assertNotNull(inputStream);/*from  w  w  w  . j a  v a 2  s  .c  o m*/
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Simple Test Report", workbook.getSheetAt(0).getSheetName());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(true, sheet.isDisplayFormulas());
        assertEquals(true, sheet.isDisplayGridlines());
        assertEquals(true, sheet.isDisplayRowColHeadings());
        assertEquals(true, sheet.isDisplayZeros());
        performSimpleWithJpegTests(sheet);
    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.BasicReportTest.java

License:Open Source License

@Test
public void testRunReportWithJpegXlsGridlinesRenderOption() throws BirtException, IOException {

    displayGridlines = false;//from   w w  w. j a  v a 2 s .  c  o  m
    InputStream inputStream = runAndRenderReport("SimpleWithJpeg.rptdesign", "xls");
    assertNotNull(inputStream);
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Simple Test Report", workbook.getSheetAt(0).getSheetName());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(false, sheet.isDisplayFormulas());
        assertEquals(false, sheet.isDisplayGridlines());
        assertEquals(true, sheet.isDisplayRowColHeadings());
        assertEquals(true, sheet.isDisplayZeros());
        performSimpleWithJpegTests(sheet);
    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.BasicReportTest.java

License:Open Source License

@Test
public void testRunReportWithJpegXlsGridlinesReport() throws BirtException, IOException {

    InputStream inputStream = runAndRenderReport("SimpleWithJpegHideGridlines.rptdesign", "xls");
    assertNotNull(inputStream);//from  ww w  .  j  a  v a 2s . c  om
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Simple Test Report", workbook.getSheetAt(0).getSheetName());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(false, sheet.isDisplayFormulas());
        assertEquals(false, sheet.isDisplayGridlines());
        assertEquals(true, sheet.isDisplayRowColHeadings());
        assertEquals(true, sheet.isDisplayZeros());
        performSimpleWithJpegTests(sheet);
    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.BasicReportTest.java

License:Open Source License

@Test
public void testRunReportWithJpegXlsRowColHeadingsRenderOption() throws BirtException, IOException {

    displayRowColHeadings = false;//  w w w  .  j  a  va2 s  .  c  om
    InputStream inputStream = runAndRenderReport("SimpleWithJpeg.rptdesign", "xls");
    assertNotNull(inputStream);
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Simple Test Report", workbook.getSheetAt(0).getSheetName());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(false, sheet.isDisplayFormulas());
        assertEquals(true, sheet.isDisplayGridlines());
        assertEquals(false, sheet.isDisplayRowColHeadings());
        assertEquals(true, sheet.isDisplayZeros());
        performSimpleWithJpegTests(sheet);
    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.BasicReportTest.java

License:Open Source License

@Test
public void testRunReportWithJpegXlsRowColHeadingsReport() throws BirtException, IOException {

    InputStream inputStream = runAndRenderReport("SimpleWithJpegHideRowColHeadings.rptdesign", "xls");
    assertNotNull(inputStream);//from   w  w w .  j a va 2  s . co m
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Simple Test Report", workbook.getSheetAt(0).getSheetName());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(false, sheet.isDisplayFormulas());
        assertEquals(true, sheet.isDisplayGridlines());
        assertEquals(false, sheet.isDisplayRowColHeadings());
        assertEquals(true, sheet.isDisplayZeros());
        performSimpleWithJpegTests(sheet);
    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.BasicReportTest.java

License:Open Source License

@Test
public void testRunReportWithJpegXlsZerosRenderOption() throws BirtException, IOException {

    displayZeros = false;/* w  w w . j  a v  a2  s . c om*/
    InputStream inputStream = runAndRenderReport("SimpleWithJpeg.rptdesign", "xls");
    assertNotNull(inputStream);
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Simple Test Report", workbook.getSheetAt(0).getSheetName());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(false, sheet.isDisplayFormulas());
        assertEquals(true, sheet.isDisplayGridlines());
        assertEquals(true, sheet.isDisplayRowColHeadings());
        assertEquals(false, sheet.isDisplayZeros());
        performSimpleWithJpegTests(sheet);
    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.BasicReportTest.java

License:Open Source License

@Test
public void testRunReportWithJpegXlsZerosReport() throws BirtException, IOException {

    InputStream inputStream = runAndRenderReport("SimpleWithJpegHideZeros.rptdesign", "xls");
    assertNotNull(inputStream);/*ww  w  .  j a  va2s.com*/
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Simple Test Report", workbook.getSheetAt(0).getSheetName());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(false, sheet.isDisplayFormulas());
        assertEquals(true, sheet.isDisplayGridlines());
        assertEquals(true, sheet.isDisplayRowColHeadings());
        assertEquals(false, sheet.isDisplayZeros());
        performSimpleWithJpegTests(sheet);
    } finally {
        inputStream.close();
    }
}