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

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

Introduction

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

Prototype

Row getRow(int rownum);

Source Link

Document

Returns the logical row (not physical) 0-based.

Usage

From source file:com.netxforge.netxstudio.models.export.MasterDataExporterRevenge_sxssf.java

License:Open Source License

private void _generateMultiRefCell(EReference eReference, Sheet sheet) {

    // Generate name.
    {/*w w w  .  j av a  2s  .c o m*/
        // Style, cell color.
        CellStyle referenceStyle = workBook.createCellStyle();
        referenceStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        referenceStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

        // Style, font
        Font referenceFont = workBook.createFont();
        referenceFont.setFontName("Verdana");
        referenceFont.setColor(IndexedColors.DARK_RED.getIndex());
        referenceStyle.setFont(referenceFont);

        // Style, border.
        referenceStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);

        Row row = sheet.getRow(0);
        if (row == null) {
            row = sheet.createRow(0);
        }
        short lastCellNum = row.getLastCellNum();
        if (lastCellNum == -1) {
            lastCellNum = 0;
        }
        Cell cell = row.createCell(lastCellNum);
        cell.setCellValue(StringUtils.capitalize(eReference.getName()));
        cell.setCellStyle(referenceStyle);
    }
    // Generate type
    {

        CellStyle typeStyle = workBook.createCellStyle();
        typeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);

        Row row = sheet.getRow(1);
        if (row == null) {
            row = sheet.createRow(1);
        }
        short lastCellNum = row.getLastCellNum();
        if (lastCellNum == -1) {
            lastCellNum = 0;
        }
        Cell cell = row.createCell(lastCellNum);
        cell.setCellValue(eReference.getEType().getName());
        cell.setCellStyle(typeStyle);
    }
}

From source file:com.netxforge.netxstudio.server.logic.reporting.NodeResourceReportingLogic.java

License:Open Source License

@Override
public void writeFinal(Sheet sheet) {

    Row row = sheet.getRow(INFO_ROW);
    if (row == null) {
        row = sheet.createRow(INFO_ROW);
    }/*  w  ww  .jav a  2  s  . c o  m*/
    Cell componentsSkippedInfoCell = row.createCell(INFO_COLUMN);
    componentsSkippedInfoCell
            .setCellValue("Number of not-reported Components (RAG Appropriate):" + this.componentsNotReported);

}

From source file:com.netxforge.netxstudio.server.logic.reporting.ResourceReportingEngine.java

License:Open Source License

public Row rowForIndex(Sheet sheet, int rowIndex) {
    Row tsRow = sheet.getRow(rowIndex);
    if (tsRow == null) {
        tsRow = sheet.createRow(rowIndex);
    }/*from ww w  .java  2  s. co  m*/
    return tsRow;
}

From source file:com.netxforge.netxstudio.server.logic.reporting.RFSServiceDashboardReportingLogic.java

License:Open Source License

/**
 * Write each NodeType into a separate column, starting from the
 * <code>NODETYPE_ROW</code>
 *//*from w  ww . ja v  a 2  s  .c o m*/
@Override
protected void writeContent(Sheet sheet, NodeType nodeType) {

    Row ntRow = sheet.getRow(NODETYPE_ROW);
    if (ntRow == null) {
        ntRow = sheet.createRow(NODETYPE_ROW);
    }

    Cell ntCell = null;

    if (ntRow.getLastCellNum() == -1) {
        // This is our first node type.
        ntCell = ntRow.createCell(NODE_COLUMN);
    } else {
        ntCell = ntRow.createCell(ntRow.getLastCellNum() + 3);
    }
    if (ntCell != null) {
        ntCell.setCellValue(nodeType.getName());
    }
}

From source file:com.netxforge.netxstudio.server.logic.reporting.RFSServiceDashboardReportingLogic.java

License:Open Source License

/**
 * Write each Node per NodeType column, starting
 *///from w ww  .j  ava2s.co  m
@Override
protected void writeContent(Sheet sheet, Service service, Node node, int row, int column) {

    // Write the NODE.ID box.
    int newRow = NODE_ROW + (row * NODE_HEIGHT);
    int nodeColumn = NODE_COLUMN + (column * NODE_WIDTH);

    sheet.setColumnWidth(nodeColumn, 10 * 256);

    CellStyle nodeStyle = this.getWorkBook().createCellStyle();
    nodeStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    nodeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    nodeStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    nodeStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    nodeStyle.setAlignment(CellStyle.ALIGN_CENTER);
    nodeStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    {
        Row cellRow = sheet.getRow(newRow);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow);
        }
        Cell c1 = cellRow.createCell(nodeColumn);
        c1.setCellValue(node.getNodeID());
        c1.setCellStyle(nodeStyle);
    }
    {
        Row cellRow = sheet.getRow(newRow + 1);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 1);
        }
        Cell c1 = cellRow.createCell(nodeColumn);
        c1.setCellStyle(nodeStyle);
    }
    {
        Row cellRow = sheet.getRow(newRow + 2);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 2);
        }
        Cell c1 = cellRow.createCell(nodeColumn);
        c1.setCellStyle(nodeStyle);
    }

    sheet.addMergedRegion(new CellRangeAddress(newRow, newRow + NODE_HEIGHT - 2, nodeColumn, nodeColumn));

    // In between column.
    sheet.setColumnWidth(nodeColumn + 1, 2 * 256);

    // Write the RAG

    CellStyle ragStyle = this.getWorkBook().createCellStyle();

    ragStyle.setBorderTop(CellStyle.BORDER_THIN);
    ragStyle.setBorderBottom(CellStyle.BORDER_THIN);
    ragStyle.setBorderLeft(CellStyle.BORDER_THIN);
    ragStyle.setBorderRight(CellStyle.BORDER_THIN);
    ragStyle.setAlignment(CellStyle.ALIGN_CENTER);
    ragStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    ragStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    int ragColumn = nodeColumn + 2;
    sheet.setColumnWidth(ragColumn, 2 * 256);

    IMonitoringSummary summary = monStateModel.summary(new NullProgressMonitor(), node,
            new IComputationContext[] { new ObjectContext<Service>(service),
                    new ObjectContext<DateTimeRange>(getPeriod()) });
    if (summary == null) {
        return;
    }
    int[] rag = summary.rag();
    {
        Row cellRow = sheet.getRow(newRow);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow);
        }
        Cell c1 = cellRow.createCell(ragColumn);

        c1.setCellValue("R");

        CellStyle rStyle = this.getWorkBook().createCellStyle();
        rStyle.cloneStyleFrom(ragStyle);
        rStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
        c1.setCellStyle(rStyle);

        if (rag != null) {
            c1.setCellValue(rag[0]);
        }
    }
    {
        Row cellRow = sheet.getRow(newRow + 1);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 1);
        }
        Cell c1 = cellRow.createCell(ragColumn);

        c1.setCellValue("A");

        CellStyle aStyle = this.getWorkBook().createCellStyle();
        aStyle.cloneStyleFrom(ragStyle);
        aStyle.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
        c1.setCellStyle(aStyle);

        if (rag != null) {
            c1.setCellValue(rag[1]);
        }
    }
    {
        Row cellRow = sheet.getRow(newRow + 2);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 2);
        }
        Cell c1 = cellRow.createCell(ragColumn);
        c1.setCellValue("G");
        CellStyle gStyle = this.getWorkBook().createCellStyle();
        gStyle.cloneStyleFrom(ragStyle);
        gStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
        c1.setCellStyle(gStyle);

        if (rag != null) {
            c1.setCellValue(rag[2]);
        }

    }
    // Clean our adapted summary.
    node.eAdapters().remove(summary);

}

From source file:com.netxforge.netxstudio.server.reporting.RFSServiceResourceEmitter.java

License:Open Source License

@Override
public void writeFinal() {

    Sheet sheet = getSheet();

    Row row = sheet.getRow(INFO_ROW);
    if (row == null) {
        row = sheet.createRow(INFO_ROW);
    }//  ww  w  .  j av a  2 s. co  m
    Cell nodeSkippedInfoCell = row.createCell(INFO_COLUMN);
    nodeSkippedInfoCell.setCellValue("Number of not-reported nodes (RAG Appropriate):" + this.nodesNotReported);

    Row componentsRow = sheet.getRow(INFO_ROW + 1);
    if (componentsRow == null) {
        componentsRow = sheet.createRow(INFO_ROW + 1);
    }
    Cell componentsSkippedInfoCell = componentsRow.createCell(INFO_COLUMN);
    componentsSkippedInfoCell
            .setCellValue("Number of not-reported Components (RAG Appropriate):" + this.componentsNotReported);

}

From source file:com.ocs.dynamo.importer.impl.BaseXlsImporterTest.java

License:Apache License

/**
 * Test that creating a simple (non-streaming) workbook works
 * //from  www.  j  av a 2s . c o m
 * @throws IOException
 */
@Test
public void testCreateWorkbook() throws IOException {
    byte[] bytes = readFile("importertest.xlsx");
    Workbook wb = importer.createWorkbook(bytes);

    Sheet sheet = wb.getSheetAt(0);

    PersonDTO dto = importer.processRow(0, sheet.getRow(0), PersonDTO.class);
    Assert.assertNotNull(dto);
    Assert.assertEquals(0, dto.getRowNum());
    Assert.assertEquals("Bas", dto.getName());
    Assert.assertEquals(1, dto.getNumber().intValue());
    Assert.assertEquals(2.4, dto.getFactor().doubleValue(), 0.001);
    Assert.assertEquals("abc", dto.getRandom());
    Assert.assertEquals(Gender.M, dto.getGender());
    Assert.assertEquals(1.50, dto.getPercentage().doubleValue(), 0.001);
    Assert.assertTrue(dto.getAbool());

    // check that default values are set
    dto = importer.processRow(1, sheet.getRow(1), PersonDTO.class);
    Assert.assertNotNull(dto);
    Assert.assertEquals(1, dto.getRowNum());
    Assert.assertEquals("Unknown", dto.getName());
    Assert.assertEquals(2, dto.getNumber().intValue());
    Assert.assertEquals(1.0, dto.getFactor().doubleValue(), 0.001);
    Assert.assertFalse(dto.getAbool());

    // check negative values
    dto = importer.processRow(2, sheet.getRow(2), PersonDTO.class);
    Assert.assertNotNull(dto);
    Assert.assertEquals(2, dto.getRowNum());
    Assert.assertEquals("Endy", dto.getName());
    Assert.assertEquals(-3, dto.getNumber().intValue());

}

From source file:com.ocs.dynamo.importer.impl.BaseXlsImporterTest.java

License:Apache License

/**
 * @throws IOException/*from  w  w  w  . j a  v a 2  s.  c  om*/
 */
@Test
public void testCreateWorkbook_WrongNumericValue() throws IOException {
    byte[] bytes = readFile("importertest_wrongnumeric.xlsx");
    Workbook wb = importer.createWorkbook(bytes);

    Sheet sheet = wb.getSheetAt(0);

    try {
        importer.processRow(0, sheet.getRow(0), PersonDTO.class);
    } catch (OCSImportException ex) {
        Assert.assertEquals("Found an invalid numeric value: xyz", ex.getMessage());
    }

}

From source file:com.ocs.dynamo.importer.impl.BaseXlsImporterTest.java

License:Apache License

/**
 * Test that an exception is raised if a row doesn't have enough columns
 * // w  w w . ja va  2 s  .  c  o  m
 * @throws IOException
 */
@Test
public void testCreateWorkbook_NotEnoughRows() throws IOException {
    byte[] bytes = readFile("importertest _notenoughrows.xlsx");
    Workbook wb = importer.createWorkbook(bytes);

    Sheet sheet = wb.getSheetAt(0);

    try {
        importer.processRow(0, sheet.getRow(0), PersonDTO.class);
    } catch (OCSImportException ex) {
        Assert.assertEquals("Row doesn't have enough columns", ex.getMessage());
    }

}

From source file:com.ocs.dynamo.importer.impl.BaseXlsImporterTest.java

License:Apache License

/**
 * Test that an exception occurs if a value for a required field is missing
 * /* www. j  av a2 s.  com*/
 * @throws IOException
 */
@Test
public void testCreateWorkbook_RequiredValueMissing() throws IOException {
    byte[] bytes = readFile("importertest_required_missing.xlsx");
    Workbook wb = importer.createWorkbook(bytes);

    Sheet sheet = wb.getSheetAt(0);

    try {
        importer.processRow(0, sheet.getRow(1), PersonDTO.class);
    } catch (OCSImportException ex) {
        Assert.assertEquals("Required value for field 'number' is missing", ex.getMessage());
    }
}