List of usage examples for org.apache.poi.ss.usermodel Workbook getSheet
Sheet getSheet(String name);
From source file:nl.meine.scouting.solparser.writer.ExcelWriterTest.java
License:Open Source License
@Test public void testRemovedPerson() throws Throwable { instance.write();//from w w w . j av a 2s . c o m instance.postprocess(sorter.getOrder()); instance.closeWriter(); // lidnummer 16: weg // lidnummer 1616 alles gelijk File twopersons = ParserTest.getResource("twopersons_removed.csv"); Parser p = new Parser(twopersons, SorterFactory.createSorter(SorterFactory.SORTER_ONLYALL)); p.read(true); persons = p.getAllPersons(); sortedPersons = p.getSortedPersons(); instance = new ExcelWriter("dummy.xls"); instance.setAllPersons(allPersons); instance.setSortedPersons(sortedPersons); instance.init(); instance.write(); instance.postprocess(sorter.getOrder()); instance.closeWriter(); Workbook wb = instance.workbook; Sheet s = wb.getSheetAt(0); assertEquals(2, s.getPhysicalNumberOfRows()); Sheet removedSheet = wb.getSheet(ExcelWriter.SHEET_REMOVED_PERSONS); assertNotNull(removedSheet); assertEquals(2, removedSheet.getPhysicalNumberOfRows()); Row r = removedSheet.getRow(1); Cell lidnummer = r.getCell(0); assertEquals("16", lidnummer.getStringCellValue()); }
From source file:no.asgari.civilization.server.excel.ItemReader.java
License:Apache License
private LinkedList<? extends Item> getShuffledCityStates(Workbook wb) { Sheet civSheet = wb.getSheet(SheetName.CITY_STATES.getName()); List<Cell> unfilteredCSCells = new ArrayList<>(); civSheet.forEach(row -> row.forEach(unfilteredCSCells::add)); List<Citystate> cityStates = unfilteredCSCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate) .map(cs -> new Citystate(cs.toString())).collect(Collectors.toList()); List<String> description = unfilteredCSCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(cell -> cell.getColumnIndex() == 1).map(Object::toString) .collect(Collectors.toList()); //Description should be in the same order as city states for (int i = 0; i < cityStates.size(); i++) { Citystate item = cityStates.get(i); item.setDescription(description.get(i)); }//from w ww.j ava2 s . c o m Collections.shuffle(cityStates); return new LinkedList<>(cityStates); }
From source file:no.asgari.civilization.server.excel.ItemReader.java
License:Apache License
private LinkedList<? extends Item> getShuffledCivsFromExcel(Workbook wb) { Sheet civSheet = wb.getSheet(SheetName.CIV.toString()); List<Cell> unfilteredCivCells = new ArrayList<>(); civSheet.forEach(row -> row.forEach(unfilteredCivCells::add)); List<Civ> civs = unfilteredCivCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate) .map(civname -> new Civ(civname.toString())).collect(Collectors.toList()); List<String> startingTech = unfilteredCivCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(cell -> cell.getColumnIndex() == 1).map(Object::toString) .collect(Collectors.toList()); List<String> descriptionCells = unfilteredCivCells.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 cultures for (int i = 0; i < civs.size(); i++) { Civ item = civs.get(i);/* w ww.jav a 2 s.c om*/ item.setDescription(descriptionCells.get(i)); item.setStartingTech(new Tech(startingTech.get(i), Tech.LEVEL_1, itemCounter.incrementAndGet())); } Collections.shuffle(civs); return new LinkedList<>(civs); }
From source file:no.asgari.civilization.server.excel.ItemReader.java
License:Apache License
private LinkedList<? extends Item> getShuffledCultureIFromExcel(Workbook wb) { Sheet culture1Sheet = wb.getSheet(SheetName.CULTURE_1.getName()); List<Cell> unfilteredCells = new ArrayList<>(); culture1Sheet.forEach(row -> row.forEach(unfilteredCells::add)); List<CultureI> cultures = unfilteredCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate) .map(cell -> new CultureI(cell.toString())).collect(Collectors.toList()); List<String> description = unfilteredCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(cell -> cell.getColumnIndex() == 1).map(Object::toString) .collect(Collectors.toList()); //Description should be in the same order as cultures for (int i = 0; i < cultures.size(); i++) { CultureI item = cultures.get(i); item.setDescription(description.get(i)); }/*from w w w . j a va 2 s. c o m*/ Collections.shuffle(cultures); return new LinkedList<>(cultures); }
From source file:no.asgari.civilization.server.excel.ItemReader.java
License:Apache License
private LinkedList<? extends Item> getShuffledCultureIIFromExcel(Workbook wb) { Sheet culture2Sheet = wb.getSheet(SheetName.CULTURE_2.getName()); List<Cell> unfilteredCells = new ArrayList<>(); culture2Sheet.forEach(row -> row.forEach(unfilteredCells::add)); List<CultureII> culture2s = unfilteredCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate) .map(cell -> new CultureII(cell.toString())).collect(Collectors.toList()); List<String> description = unfilteredCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(cell -> cell.getColumnIndex() == 1).map(Object::toString) .collect(Collectors.toList()); //Description should be in the same order as culture2s for (int i = 0; i < culture2s.size(); i++) { CultureII item = culture2s.get(i); item.setDescription(description.get(i)); }/* w w w .ja va 2 s. c o m*/ Collections.shuffle(culture2s); return new LinkedList<>(culture2s); }
From source file:no.asgari.civilization.server.excel.ItemReader.java
License:Apache License
private LinkedList<? extends Item> getShuffledCultureIIIFromExcel(Workbook wb) { Sheet culture3Sheet = wb.getSheet(SheetName.CULTURE_3.getName()); List<Cell> unfilteredCells = new ArrayList<>(); culture3Sheet.forEach(row -> row.forEach(unfilteredCells::add)); List<CultureIII> culture3s = unfilteredCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate) .map(cell -> new CultureIII(cell.toString())).collect(Collectors.toList()); List<String> description = unfilteredCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(cell -> cell.getColumnIndex() == 1).map(Object::toString) .collect(Collectors.toList()); //Description should be in the same order as culture3s for (int i = 0; i < culture3s.size(); i++) { CultureIII item = culture3s.get(i); item.setDescription(description.get(i)); }/*from w w w . j a v a 2 s . c om*/ Collections.shuffle(culture3s); return new LinkedList<>(culture3s); }
From source file:no.asgari.civilization.server.excel.ItemReader.java
License:Apache License
private LinkedList<? extends Item> getShuffledGreatPersonFromExcel(Workbook wb) { Sheet gpSheet = wb.getSheet(SheetName.GREAT_PERSON.getName()); List<Cell> unfilteredCells = new ArrayList<>(); gpSheet.forEach(row -> row.forEach(unfilteredCells::add)); List<GreatPerson> gps = unfilteredCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate) .map(cell -> new GreatPerson(cell.toString())).collect(Collectors.toList()); List<String> tile = unfilteredCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(cell -> cell.getColumnIndex() == 1).map(Object::toString) .collect(Collectors.toList()); List<String> description = unfilteredCells.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 cultures for (int i = 0; i < gps.size(); i++) { GreatPerson item = gps.get(i);//from w ww .j ava 2 s . co m item.setDescription(description.get(i)); item.setType(tile.get(i)); } Collections.shuffle(gps); //Now we want to take every other one LinkedList<GreatPerson> gpLinkedList = new LinkedList<>(gps); return gpLinkedList; }
From source file:no.asgari.civilization.server.excel.ItemReader.java
License:Apache License
private void extractShuffledWondersFromExcel(Workbook wb) { Sheet wonderSheet = wb.getSheet(SheetName.WONDERS.getName()); List<Cell> unfilteredCells = new ArrayList<>(); wonderSheet.forEach(row -> row.forEach(unfilteredCells::add)); //Kategoriser wonderne List<String> wonderName = unfilteredCells.stream().filter(p -> !p.toString().trim().isEmpty()) .filter(notRandomPredicate).filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate) .map(Object::toString).collect(Collectors.toList()); List<String> description = unfilteredCells.stream().filter(p -> !p.toString().trim().isEmpty()) .filter(notRandomPredicate).filter(rowNotZeroPredicate).filter(cell -> cell.getColumnIndex() == 1) .map(Object::toString).collect(Collectors.toList()); LinkedList<String> wondersName = new LinkedList<>(wonderName); LinkedList<String> descriptions = new LinkedList<>(description); //Kun ancient ancientWonders = new LinkedList<>(); //There is no break in java 8 forEach, thus we use the old for for (int i = 0; i < wondersName.size(); i++) { String wonder = wondersName.poll(); String desc = descriptions.poll(); if (wonder.toLowerCase().contains(SheetName.WONDERS.getName().toLowerCase())) { break; }//from w w w .j av a 2s. c o m ancientWonders.add(new Wonder(wonder, desc, Wonder.ANCIENT, SheetName.ANCIENT_WONDERS)); } Collections.shuffle(ancientWonders); //Kun ancient medievalWonders = new LinkedList<>(); for (int i = 0; i < wondersName.size(); i++) { String wonder = wondersName.poll(); String desc = descriptions.poll(); if (wonder.toLowerCase().contains(SheetName.WONDERS.getName().toLowerCase())) { break; } medievalWonders.add(new Wonder(wonder, desc, Wonder.MEDIEVAL, SheetName.MEDIEVAL_WONDERS)); } Collections.shuffle(medievalWonders); //Only modern left modernWonders = new LinkedList<>(); int remainingSize = wondersName.size(); for (int i = 0; i < remainingSize; i++) { String wonder = wondersName.poll(); String desc = descriptions.poll(); modernWonders.add(new Wonder(wonder, desc, Wonder.MODERN, SheetName.MODERN_WONDERS)); } Collections.shuffle(modernWonders); }
From source file:no.asgari.civilization.server.excel.ItemReader.java
License:Apache License
private LinkedList<? extends Item> getShuffledTilesFromExcel(Workbook wb) { Sheet tileSheet = wb.getSheet(SheetName.TILES.getName()); List<Cell> unfilteredTileCells = new ArrayList<>(); tileSheet.forEach(row -> row.forEach(unfilteredTileCells::add)); List<Tile> tiles = unfilteredTileCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate) .map(tilename -> new Tile( String.format("%d", (int) Double.valueOf(tilename.toString()).doubleValue()))) .collect(Collectors.toList()); Collections.shuffle(tiles);/* w w w . ja v a 2s . c om*/ return new LinkedList<>(tiles); }
From source file:no.asgari.civilization.server.excel.ItemReader.java
License:Apache License
private LinkedList<? extends Item> getShuffledHutsFromExcel(Workbook wb) { Sheet hutSheet = wb.getSheet(SheetName.HUTS.getName()); List<Cell> unfilteredCivCells = new ArrayList<>(); hutSheet.forEach(row -> row.forEach(unfilteredCivCells::add)); List<Hut> huts = unfilteredCivCells.stream().filter(notEmptyPredicate).filter(notRandomPredicate) .filter(rowNotZeroPredicate).filter(columnIndexZeroPredicate).map(hut -> new Hut(hut.toString())) .collect(Collectors.toList()); Collections.shuffle(huts);//from w w w. j av a 2 s . c om return new LinkedList<>(huts); }