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

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

Introduction

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

Prototype

boolean isDisplayGridlines();

Source Link

Document

Returns if gridlines are displayed

Usage

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

License:Open Source License

/**
 * /* w w  w. j  a  va2s. c  om*/
 * 
 * @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:org.joeffice.spreadsheet.SheetComponent.java

License:Apache License

public JTable createTable(Sheet sheet) {
    SheetTableModel sheetTableModel = new SheetTableModel(sheet);
    JTable table = new SheetTable(sheetTableModel);

    table.setDefaultRenderer(Cell.class, new CellRenderer());
    TableCellEditor editor = new org.joeffice.spreadsheet.cell.CellEditor();
    table.setDefaultEditor(Cell.class, editor);
    int columnsCount = sheetTableModel.getColumnCount();
    for (int i = 0; i < columnsCount; i++) {
        TableColumn tableColumn = table.getColumnModel().getColumn(i);
        tableColumn.setCellRenderer(new CellRenderer());
        tableColumn.setCellEditor(editor);
        int widthUnits = sheet.getColumnWidth(i);
        tableColumn.setPreferredWidth(widthUnitsToPixel(widthUnits));
    }/*from  ww w  .j a  va  2  s.  c  om*/

    int rowCount = sheetTableModel.getRowCount();
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        Row row = sheet.getRow(rowIndex);
        if (row != null) {
            int cellHeight = (int) Math.ceil(sheet.getRow(rowIndex).getHeightInPoints());
            cellHeight += CELL_HEIGHT_MARGINS;
            table.setRowHeight(rowIndex, cellHeight);
        }
    }

    table.setAutoscrolls(true);
    table.setFillsViewportHeight(true);
    JLabel tableHeader = (JLabel) table.getTableHeader().getDefaultRenderer();
    tableHeader.setHorizontalAlignment(SwingConstants.CENTER);

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setCellSelectionEnabled(true);

    TableColumnAdjuster tca = new TableColumnAdjuster(table, 20);
    if (sheet.getDefaultColumnWidth() == -1) {
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        tca.setOnlyAdjustLarger(true);
        tca.setLeaveEmptyAsIs(true);
        tca.adjustColumns();
    }

    table.setTransferHandler(new TableTransferHandler());
    table.setDragEnabled(true);
    table.setDropMode(DropMode.ON_OR_INSERT);

    Action cutAction = new ClipboardAction(DefaultEditorKit.cutAction);
    Action copyAction = new ClipboardAction(DefaultEditorKit.copyAction);
    Action pasteAction = new ClipboardAction(DefaultEditorKit.pasteAction);
    table.getActionMap().put(DefaultEditorKit.cutAction, cutAction);
    table.getActionMap().put(DefaultEditorKit.copyAction, copyAction);
    table.getActionMap().put(DefaultEditorKit.pasteAction, pasteAction);

    //table.setIntercellSpacing(new Dimension(0, 0));
    table.putClientProperty("print.printable", Boolean.TRUE);
    Rectangle lastDataCellBounds = table.getCellRect(sheet.getLastRowNum(), sheetTableModel.getLastColumnNum(),
            true);
    table.putClientProperty("print.size", new Dimension(lastDataCellBounds.x + lastDataCellBounds.width,
            lastDataCellBounds.y + lastDataCellBounds.height));
    new SheetListener(table);

    if (!sheet.isDisplayGridlines()) {
        table.setShowGrid(false);
    }
    return table;
}

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);/*from   ww w  . j  a  va2s.  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(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  ww  w  . j  ava 2s  .  co 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(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 ww. j av  a2 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;/*w ww. j a  v a2s.com*/
    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  w ww .  j av a2s  .  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;//from  w  ww .  ja v  a  2  s . co  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(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  ww  .  j a  v a 2s .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(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;//from   w w w. j  av  a2 s .com
    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();
    }
}