Example usage for org.apache.poi.ss.usermodel Row getSheet

List of usage examples for org.apache.poi.ss.usermodel Row getSheet

Introduction

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

Prototype

Sheet getSheet();

Source Link

Document

Returns the Sheet this row belongs to

Usage

From source file:org.squashtest.tm.service.internal.batchexport.ExcelExporter.java

License:Open Source License

private void appendCustomFields(Row r, String codePrefix, List<CustomField> cufs) {

    for (CustomField cuf : cufs) {

        String code = codePrefix + cuf.getCode();
        Integer idx = cufColumnsByCode.get(code);

        // if unknown : register it
        if (idx == null) {
            idx = registerCuf(r.getSheet(), code);
        }/* w w  w  .  j  a v  a 2 s  . c  o m*/

        Cell c = r.createCell(idx);
        String value = nullSafeValue(cuf);
        c.setCellValue(value);
    }
}

From source file:org.teiid.translator.excel.ExcelUpdateExecution.java

License:Apache License

private void handleInsert() throws TranslatorException {
    Insert insert = (Insert) command;/*w ww  .j  av a  2 s .com*/
    ExpressionValueSource evs = (ExpressionValueSource) insert.getValueSource();
    Row row = nextRow();
    Sheet sheet = null;
    if (row == null) {
        sheet = workbook.getSheet(this.visitor.getSheetName());
    } else {
        sheet = row.getSheet();
    }
    int last = sheet.getLastRowNum();
    Row newRow = sheet.createRow(last + 1);
    List<Integer> cols = this.visitor.getProjectedColumns();
    for (int i = 0; i < cols.size(); i++) {
        int index = cols.get(i);
        setValue(newRow, index - 1, ((Literal) evs.getValues().get(i)).getValue());
    }
    GeneratedKeys keys = executionContext.getCommandContext().returnGeneratedKeys(
            new String[] { ExcelMetadataProcessor.ROW_ID },
            new Class<?>[] { TypeFacility.RUNTIME_TYPES.INTEGER });
    keys.addKey(Arrays.asList(last + 1));
    result++;
    writeXLSFile();
}

From source file:org.teiid.translator.excel.ExcelUpdateExecution.java

License:Apache License

private void handleDelete() throws TranslatorException {
    while (true) {
        Row row = nextRow();
        if (row == null) {
            break;
        }//  ww  w .j  a  v a 2  s  .c o m
        this.rowIterator = null;
        int start = row.getRowNum();
        Sheet sheet = row.getSheet();
        int end = sheet.getLastRowNum();
        //a different iteration style is needed, which will not perform as well for sparse documents
        for (int i = start; i <= end; i++) {
            row = sheet.getRow(i);
            if (row == null) {
                continue;
            }
            if (row.getFirstCellNum() == -1) {
                continue;
            }

            if (!this.visitor.allows(row.getRowNum())) {
                continue;
            }
            sheet.removeRow(row);
            result++;
            modified = true;
        }
    }
}

From source file:testpoi.GenerateDailyExcel.java

License:Open Source License

private static void makeEntry(Department deptt) {
    //create new row in xlsx to be generated
    Row newRow = sheetNew.createRow(rowCnt++);
    //Create a new cell in current row
    Cell newCell = newRow.createCell(0);
    //Set value to the department's name
    newCell.setCellValue(deptt.name);//w w w.j av  a  2  s.c om

    double random = Math.random();
    Row row = null;
    if (deptt.name.equals("Gynaecology")) {
        //Pick a row from female sheet randomly (Female sheet should have all reproducible ages)
        int rowNum = (int) (random * sheetFemale.getPhysicalNumberOfRows());

        row = sheetFemale.getRow(rowNum);
    } else if (deptt.name.equals("Paediatrics")) {
        //Pick a row from children sheet randomly (Children sheet should have all ages under 13)
        int rowNum = (int) (random * sheetChildren.getPhysicalNumberOfRows());

        row = sheetChildren.getRow(rowNum);
    } else {
        //Pick a row from all sheet randomly
        int rowNum = (int) (random * sheetAll.getPhysicalNumberOfRows());

        row = sheetAll.getRow(rowNum);
    }
    assert (row != null);

    //read and write fetched row
    Iterator<Cell> cellIterator = row.cellIterator();
    int newCellCnt = 1;
    while (cellIterator.hasNext()) {
        //May we write all cells as strings?
        Cell cell = cellIterator.next();
        String cellValue = null;
        try {
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
                cellValue = cell.getNumericCellValue() + "";
            else
                cellValue = cell.getStringCellValue();

            newCell = newRow.createCell(newCellCnt++);
            newCell.setCellValue(cellValue);
            //                System.out.print (cellValue+"("+cell.getColumnIndex()+")\t");
        } catch (Exception e) {
            System.out.println("Could not write from cell (value:" + cellValue +
            //                        ", column:"+cell.getSheet().getWorkbook().+
                    ", sheet:" + cell.getSheet().getSheetName() + ", row:" + cell.getRowIndex() + ", column:"
                    + cell.getColumnIndex() + ")");
            e.printStackTrace();
        }
    }
    System.out.println();

    //delete row read
    if (row.getSheet() == sheetFemale)
        sheetFemale.removeRow(row);
    else if (row.getSheet() == sheetChildren)
        sheetChildren.removeRow(row);
    else
        sheetAll.removeRow(row);
}