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

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

Introduction

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

Prototype

Sheet getSheet(String name);

Source Link

Document

Get sheet with the given name

Usage

From source file:no.asgari.civilization.server.excel.ItemReader.java

License:Apache License

private LinkedList<? extends Item> getShuffledVillages(Workbook wb) {
    Sheet sheet = wb.getSheet(SheetName.VILLAGES.getName());

    List<Cell> unfilteredCivCells = new ArrayList<>();
    sheet.forEach(row -> row.forEach(unfilteredCivCells::add));

    List<Village> villages = unfilteredCivCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate)
            .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate)
            .map(village -> new Village(village.toString())).collect(Collectors.toList());

    Collections.shuffle(villages);
    return new LinkedList<>(villages);
}

From source file:no.asgari.civilization.server.excel.ItemReader.java

License:Apache License

/**
 * Tech cards do not need to be shuffled as the player is supposed to pick the card they want
 *
 * @param wb/*w  w w .j a v  a 2 s.  c  o m*/
 * @return
 */
private List<Tech> getTechsFromExcel(Workbook wb) {
    //Start with level 1 techs
    Sheet sheet = wb.getSheet(SheetName.LEVEL_1_TECH.getName());
    List<Cell> level1Cells = new ArrayList<>();
    sheet.forEach(row -> row.forEach(level1Cells::add));

    List<Tech> level1Techs = level1Cells.stream().filter(notEmptyPredicate).filter(notRandomPredicate)
            .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate)
            .map(tech -> new Tech(tech.toString(), Tech.LEVEL_1)).collect(Collectors.toList());

    sheet = wb.getSheet(SheetName.LEVEL_2_TECH.getName());
    List<Cell> level2Cells = new ArrayList<>();
    sheet.forEach(row -> row.forEach(level2Cells::add));

    List<Tech> level2Techs = level2Cells.stream().filter(notEmptyPredicate).filter(notRandomPredicate)
            .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate)
            .map(tech -> new Tech(tech.toString(), Tech.LEVEL_2)).collect(Collectors.toList());

    sheet = wb.getSheet(SheetName.LEVEL_3_TECH.getName());
    List<Cell> level3Cells = new ArrayList<>();
    sheet.forEach(row -> row.forEach(level3Cells::add));

    List<Tech> level3Techs = level3Cells.stream().filter(notEmptyPredicate).filter(notRandomPredicate)
            .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate)
            .map(tech -> new Tech(tech.toString(), Tech.LEVEL_3)).collect(Collectors.toList());

    sheet = wb.getSheet(SheetName.LEVEL_4_TECH.getName());
    List<Cell> level4Cells = new ArrayList<>();
    sheet.forEach(row -> row.forEach(level4Cells::add));

    List<Tech> level4Techs = level4Cells.stream().filter(notEmptyPredicate).filter(notRandomPredicate)
            .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate)
            .map(tech -> new Tech(tech.toString(), Tech.LEVEL_4)).collect(Collectors.toList());

    List<Tech> allTechs = new ArrayList<>(level1Techs);
    allTechs.addAll(level2Techs);
    allTechs.addAll(level3Techs);
    allTechs.addAll(level4Techs);
    allTechs.add(Tech.SPACE_FLIGHT);
    Collections.sort(allTechs, (o1, o2) -> Integer.valueOf(o1.getLevel()).compareTo(o2.getLevel()));

    return allTechs;
}

From source file:no.asgari.civilization.server.excel.ItemReader.java

License:Apache License

private void readInfantry(Workbook wb) throws IOException {
    Sheet infantrySheet = wb.getSheet(SheetName.INFANTRY.toString());

    List<Cell> unfilteredCells = new ArrayList<>();
    infantrySheet.forEach(row -> row.forEach(unfilteredCells::add));

    List<Infantry> infantryUnits = unfilteredCells.stream().filter(ItemReader.notEmptyPredicate)
            .filter(ItemReader.notRandomPredicate).filter(ItemReader.rowNotZeroPredicate)
            .filter(ItemReader.columnIndexZeroPredicate).map(cell -> createInfantry(cell.toString()))
            .collect(Collectors.toList());

    Collections.shuffle(infantryUnits);
    infantryList = new LinkedList<>(infantryUnits);
    log.debug(infantryList);//from  w ww.ja  v  a  2s.  co m
}

From source file:no.asgari.civilization.server.excel.ItemReader.java

License:Apache License

private void readMounted(Workbook wb) throws IOException {
    Sheet mountedsheet = wb.getSheet(SheetName.MOUNTED.toString());

    List<Cell> unfilteredCells = new ArrayList<>();
    mountedsheet.forEach(row -> row.forEach(unfilteredCells::add));

    List<Mounted> mountedUnits = unfilteredCells.stream().filter(ItemReader.notEmptyPredicate)
            .filter(ItemReader.notRandomPredicate).filter(ItemReader.rowNotZeroPredicate)
            .filter(ItemReader.columnIndexZeroPredicate).map(cell -> createMounted(cell.toString()))
            .collect(Collectors.toList());

    Collections.shuffle(mountedUnits);
    mountedList = new LinkedList<>(mountedUnits);
    log.debug("Mounted units from excel are " + mountedList);
}

From source file:no.asgari.civilization.server.excel.ItemReader.java

License:Apache License

private void readArtillery(Workbook wb) throws IOException {
    Sheet artillerySheet = wb.getSheet(SheetName.ARTILLERY.toString());

    List<Cell> unfilteredCells = new ArrayList<>();
    artillerySheet.forEach(row -> row.forEach(unfilteredCells::add));

    List<Artillery> artilleryUnits = unfilteredCells.stream().filter(ItemReader.notEmptyPredicate)
            .filter(ItemReader.notRandomPredicate).filter(ItemReader.rowNotZeroPredicate)
            .filter(ItemReader.columnIndexZeroPredicate).map(cell -> createArtillery(cell.toString()))
            .collect(Collectors.toList());

    Collections.shuffle(artilleryUnits);
    artilleryList = new LinkedList<>(artilleryUnits);
    log.debug("Artillery units from excel are " + artilleryList);
}

From source file:no.asgari.civilization.server.excel.ItemReader.java

License:Apache License

private void readAircraft(Workbook wb) throws IOException {
    Sheet aircraftSheet = wb.getSheet(SheetName.AIRCRAFT.toString());

    List<Cell> unfilteredCells = new ArrayList<>();
    aircraftSheet.forEach(row -> row.forEach(unfilteredCells::add));

    List<Aircraft> aircraftUnits = unfilteredCells.stream().filter(ItemReader.notEmptyPredicate)
            .filter(ItemReader.notRandomPredicate).filter(ItemReader.rowNotZeroPredicate)
            .filter(ItemReader.columnIndexZeroPredicate).map(cell -> createAircraft(cell.toString()))
            .collect(Collectors.toList());

    Collections.shuffle(aircraftUnits);
    aircraftList = new LinkedList<>(aircraftUnits);
    log.debug("Aircraft units from excel are " + aircraftList);
}

From source file:no.asgari.civilization.server.excel.ItemReader.java

License:Apache License

private LinkedList<? extends Item> getSocialPolicies(Workbook wb) {
    Sheet spSheet = wb.getSheet(SheetName.SOCIAL_POLICY.getName().toString());

    List<Cell> unfilteredSPCells = new ArrayList<>();
    spSheet.forEach(row -> row.forEach(unfilteredSPCells::add));

    List<SocialPolicy> sps = unfilteredSPCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate)
            .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate)
            .map(sp -> new SocialPolicy(sp.toString())).collect(Collectors.toList());

    List<String> descriptionCells = unfilteredSPCells.stream().filter(notEmptyPredicate)
            .filter(notRandomPredicate).filter(rowNotZeroPredicate).filter(cell -> cell.getColumnIndex() == 1)
            .map(Object::toString).collect(Collectors.toList());

    List<String> flipsideCells = unfilteredSPCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate)
            .filter(rowNotZeroPredicate).filter(cell -> cell.getColumnIndex() == 2).map(Object::toString)
            .collect(Collectors.toList());

    //Description should be in the same order as flipside
    for (int i = 0; i < sps.size(); i++) {
        SocialPolicy item = sps.get(i);//from   w w  w.  java 2s. co  m
        item.setDescription(descriptionCells.get(i));
        item.setFlipside(flipsideCells.get(i));
    }

    Collections.shuffle(sps);
    return new LinkedList<>(sps);
}

From source file:nu.mine.kino.projects.utils.POI2Test.java

License:Open Source License

private void expandRange(Workbook workbook, String sheetName, String dataName, int dataCount) {

    // OwZ//  ww  w  .j a v  a  2  s .c om
    Sheet sheet = workbook.getSheet(sheetName);
    final Name DATA_AREA = workbook.getName(dataName);
    final AreaReference areaReference = new AreaReference(DATA_AREA.getRefersToFormula());
    // final CellReference firstCell = areaReference.getFirstCell();
    final CellReference lastCell = areaReference.getLastCell();

    // System.out.printf("??sIndex %s\n", firstCell.getRow());
    System.out.printf("??I?sIndex %s\n", lastCell.getRow());

    sheet.shiftRows(lastCell.getRow(), lastCell.getRow(), dataCount);
}

From source file:nu.mine.kino.projects.utils.ProjectUtils.java

License:Open Source License

public static Holiday[] createHolidays(Workbook workbook) {
    Sheet sheet = workbook.getSheet("xe?[u");

    List<Holiday> arrayList = new ArrayList<Holiday>();
    Iterator<Row> e = sheet.rowIterator();
    while (e.hasNext()) {
        Row row = e.next();//from   w  ww.  j  a v  a2 s.c o m
        Holiday holiday = new Holiday();

        Cell dateCell = row.getCell(0);
        if (dateCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            if (PoiUtil.isCellDateFormatted(dateCell)) {
                Date dateCellValue = dateCell.getDateCellValue();
                holiday.setDate(dateCellValue);
            }
            arrayList.add(holiday);
        }

        // Cell cell1 = row.getCell(1);
        // if (cell1 != null && cell1.getCellType() ==
        // Cell.CELL_TYPE_FORMULA) {
        // holiday.setDayOfWeek((String) PoiUtils.getCellValue(cell1,
        // String.class));
        // }

        Cell cell2 = row.getCell(2);
        if (cell2 != null && cell2.getCellType() == Cell.CELL_TYPE_STRING) {
            holiday.setName(cell2.getStringCellValue());
        }
        Cell cell3 = row.getCell(3);
        if (cell3 != null && cell3.getCellType() == Cell.CELL_TYPE_STRING) {
            holiday.setRule(cell3.getStringCellValue());
        }
        Cell cell4 = row.getCell(4);
        if (cell4 != null && cell4.getCellType() == Cell.CELL_TYPE_STRING) {
            holiday.setHurikae(cell4.getStringCellValue());
        }

    }
    return arrayList.toArray(new Holiday[arrayList.size()]);
}

From source file:org.alanwilliamson.openbd.plugin.spreadsheet.tags.cfSpreadSheetWrite.java

License:Open Source License

protected void writeQueryToSheet(cfQueryResultData queryData, cfSpreadSheetData spreadsheet, String sheetName)
        throws dataNotSupportedException {
    Workbook workbook = spreadsheet.getWorkBook();

    if (workbook.getSheet(sheetName) != null)
        workbook.removeSheetAt(workbook.getSheetIndex(sheetName));

    Sheet sheet = workbook.createSheet(sheetName);

    //WRITE THE SHEET: 1st row to be the columns
    String[] columnList = queryData.getColumnList();
    Row row = sheet.createRow(0);//ww  w.  jav a  2s. c  o m
    Cell cell;
    for (int c = 0; c < columnList.length; c++) {
        cell = row.createCell(c, Cell.CELL_TYPE_STRING);
        cell.setCellValue(columnList[c]);
    }

    //WRITE THE SHEET: Write out all the rows
    int rowsToInsert = queryData.getSize();
    for (int x = 0; x < rowsToInsert; x++) {
        row = sheet.createRow(x + 1);

        for (int c = 0; c < columnList.length; c++) {
            cell = row.createCell(c);

            cfData value = queryData.getCell(x + 1, c + 1);

            if (value.getDataType() == cfData.CFNUMBERDATA) {
                cell.setCellValue(value.getDouble());
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);
            } else if (value.getDataType() == cfData.CFDATEDATA) {
                cell.setCellValue(new Date(value.getDateLong()));
            } else if (value.getDataType() == cfData.CFBOOLEANDATA) {
                cell.setCellValue(value.getBoolean());
                cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
            } else {
                cell.setCellValue(value.getString());
                cell.setCellType(Cell.CELL_TYPE_STRING);
            }
        }

    }
}