List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet getRow
@Override public XSSFRow getRow(int rownum)
From source file:org.tuxedoberries.transformo.excel.XLSXTableMetaReader.java
License:Open Source License
private TableMeta generateTableMeta(XSSFSheet sheet) { int totalRows = sheet.getLastRowNum(); if (totalRows < ROW_META_COUNT) { Logger.Warning("Total number of rows less than expected [%d]. %d Rows are expected", totalRows, ROW_META_COUNT);//from w w w .jav a 2s . co m return null; } TableMeta meta = new TableMeta(); meta.TableName = sheet.getSheetName(); if (meta.TableName.startsWith("!")) return null; generateTypes(sheet.getRow(0), meta); generateShortNames(sheet.getRow(1), meta); generateNames(sheet.getRow(2), meta); return meta; }
From source file:org.xframium.application.ExcelApplicationProvider.java
License:Open Source License
/** * Read elements.// www . j a v a 2s . c o m * * @param inputStream the input stream */ private void readElements(InputStream inputStream) { XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(inputStream); XSSFSheet sheet = workbook.getSheet(tabName); for (int i = 1; i <= sheet.getLastRowNum(); i++) { XSSFRow currentRow = sheet.getRow(i); if (getCellValue(currentRow.getCell(0)) == null || getCellValue(currentRow.getCell(0)).isEmpty()) break; ApplicationRegistry.instance() .addApplicationDescriptor(new ApplicationDescriptor(getCellValue(currentRow.getCell(0)), getCellValue(currentRow.getCell(4)), getCellValue(currentRow.getCell(1)), getCellValue(currentRow.getCell(2)), getCellValue(currentRow.getCell(3)), getCellValue(currentRow.getCell(5)), getCellValue(currentRow.getCell(6)), new HashMap<String, Object>(0))); } } catch (Exception e) { log.fatal("Error reading Excel Element File", e); } finally { try { workbook.close(); } catch (Exception e) { } } }
From source file:org.xframium.content.provider.ExcelContentProvider.java
License:Open Source License
/** * Read elements.//from w w w . ja v a 2 s. c o m * * @param inputStream the input stream */ private void readElements(InputStream inputStream) { XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(inputStream); XSSFSheet sheet = workbook.getSheet(tabName); for (int i = 1; i <= sheet.getLastRowNum(); i++) { XSSFRow currentRow = sheet.getRow(i); String keyName = getCellValue(currentRow.getCell(keyColumn)); String[] valueList = new String[lookupColumns.length]; for (int x = 0; x < lookupColumns.length; x++) { valueList[x] = getCellValue(currentRow.getCell(lookupColumns[x])); } ContentData contentData = new DefaultContentData(keyName, valueList); ContentManager.instance().addContentData(contentData); } } catch (Exception e) { log.fatal("Error reading Excel Element File", e); } finally { try { workbook.close(); } catch (Exception e) { } } }
From source file:org.xframium.device.cloud.ExcelCloudProvider.java
License:Open Source License
/** * Read elements.//from w w w .jav a 2s . co m * * @param inputStream the input stream */ private void readElements(InputStream inputStream) { XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(inputStream); XSSFSheet sheet = workbook.getSheet(tabName); for (int i = 1; i <= sheet.getLastRowNum(); i++) { XSSFRow currentRow = sheet.getRow(i); if (getCellValue(currentRow.getCell(0)) == null || getCellValue(currentRow.getCell(0)).isEmpty()) break; CloudRegistry.instance() .addCloudDescriptor(new CloudDescriptor(getCellValue(currentRow.getCell(0)), getCellValue(currentRow.getCell(1)), getCellValue(currentRow.getCell(2)), getCellValue(currentRow.getCell(3)), getCellValue(currentRow.getCell(4)), getCellValue(currentRow.getCell(5)), getCellValue(currentRow.getCell(7)), getCellValue(currentRow.getCell(6)), getCellValue(currentRow.getCell(8)))); } } catch (Exception e) { log.fatal("Error reading Excel Element File", e); } finally { try { workbook.close(); } catch (Exception e) { } } }
From source file:org.xframium.device.data.ExcelDataProvider.java
License:Open Source License
/** * Read data.//from w w w . j a v a 2 s . c om * * @param inputStream the input stream */ private void readData(InputStream inputStream) { BufferedReader fileReader = null; XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(inputStream); XSSFSheet sheet = workbook.getSheet(tabName); for (int i = 1; i <= sheet.getLastRowNum(); i++) { XSSFRow currentRow = sheet.getRow(i); if (getCellValue(currentRow.getCell(0)) == null || getCellValue(currentRow.getCell(0)).isEmpty()) break; String driverName = ""; switch (driverType) { case APPIUM: if (getCellValue(currentRow.getCell(3)).toUpperCase().equals("IOS")) driverName = "IOS"; else if (getCellValue(currentRow.getCell(3)).toUpperCase().equals("ANDROID")) driverName = "ANDROID"; else throw new IllegalArgumentException("Appium is not supported on the following OS " + getCellValue(currentRow.getCell(3)).toUpperCase()); break; case PERFECTO: driverName = "PERFECTO"; break; case WEB: driverName = "WEB"; break; } Device currentDevice = new SimpleDevice(getCellValue(currentRow.getCell(0)), getCellValue(currentRow.getCell(1)), getCellValue(currentRow.getCell(2)), getCellValue(currentRow.getCell(3)), getCellValue(currentRow.getCell(4)), getCellValue(currentRow.getCell(5)), getCellValue(currentRow.getCell(6)), Integer.parseInt(getCellValue(currentRow.getCell(7))), driverName, Boolean.parseBoolean(getCellValue(currentRow.getCell(8))), null); if (currentDevice.isActive()) { if (log.isDebugEnabled()) log.debug("Extracted: " + currentDevice); DeviceManager.instance().registerDevice(currentDevice); } } } catch (Exception e) { log.fatal("Error reading Excel Element File", e); } finally { try { workbook.close(); } catch (Exception e) { } } }
From source file:org.xframium.page.data.provider.ExcelPageDataProvider.java
License:Open Source License
/** * Read elements.// ww w .java2s . c o m * * @param inputStream the input stream */ private void readElements(InputStream inputStream) { XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(inputStream); String[] tabs = tabNames.split(","); for (String tabName : tabs) { XSSFSheet sheet = workbook.getSheet(tabName); if (sheet == null) continue; addRecordType(tabName, false); XSSFRow firstRow = sheet.getRow(0); for (int i = 1; i <= sheet.getLastRowNum(); i++) { XSSFRow currentRow = sheet.getRow(i); if (getCellValue(currentRow.getCell(0)) == null || getCellValue(currentRow.getCell(0)).isEmpty()) break; DefaultPageData currentRecord = new DefaultPageData(tabName, tabName + "-" + i, true); for (int x = 0; x < firstRow.getLastCellNum(); x++) { String currentName = getCellValue(firstRow.getCell(x)); String currentValue = getCellValue(currentRow.getCell(x)); if (currentValue == null) currentValue = ""; if (currentValue.startsWith(PageData.TREE_MARKER) && currentValue.endsWith(PageData.TREE_MARKER)) { // // This is a reference to another page data table // currentRecord.addPageData(currentName); currentRecord.addValue(currentName + PageData.DEF, currentValue); currentRecord.setContainsChildren(true); } else currentRecord.addValue(currentName, currentValue); } addRecord(currentRecord); } } } catch (Exception e) { log.fatal("Error reading Excel Element File", e); } finally { try { workbook.close(); } catch (Exception e) { } } }
From source file:org.xframium.page.element.provider.ExcelElementProvider.java
License:Open Source License
/** * Read elements./*from w w w . j a v a 2 s . co m*/ * * @param inputStream the input stream */ private void readElements(InputStream inputStream) { XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(inputStream); boolean elementsRead = true; String[] tabs = tabNames.split(","); for (String tabName : tabs) { XSSFSheet sheet = workbook.getSheet(tabName); if (sheet == null) continue; for (int i = 1; i <= sheet.getLastRowNum(); i++) { System.out.println(i); XSSFRow currentRow = sheet.getRow(i); if (getCellValue(currentRow.getCell(0)) == null || getCellValue(currentRow.getCell(0)).isEmpty()) break; ElementDescriptor elementDescriptor = new ElementDescriptor(tabName, getCellValue(currentRow.getCell(0)), getCellValue(currentRow.getCell(1))); String contextName = null; if (getCellValue(currentRow.getCell(4)) != null && !getCellValue(currentRow.getCell(4)).isEmpty()) { contextName = getCellValue(currentRow.getCell(4)); } Element currentElement = ElementFactory.instance().createElement( BY.valueOf(getCellValue(currentRow.getCell(2))), getCellValue(currentRow.getCell(3)).replace("$$", ","), getCellValue(currentRow.getCell(1)), getCellValue(currentRow.getCell(0)), contextName); if (log.isDebugEnabled()) log.debug("Adding Excel Element using [" + elementDescriptor.toString() + "] as [" + currentElement); elementsRead = elementsRead & validateElement(elementDescriptor, currentElement); elementMap.put(elementDescriptor.toString(), currentElement); } } setInitialized(elementsRead); } catch (Exception e) { log.fatal("Error reading Excel Element File", e); } finally { try { workbook.close(); } catch (Exception e) { } } }
From source file:org.xframium.page.keyWord.provider.ExcelKeyWordProvider.java
License:Open Source License
private void readElements(InputStream inputStream) { List<MatrixTest> testList = new ArrayList<MatrixTest>(10); XSSFWorkbook workbook = null;/*from www . ja v a 2s . c o m*/ try { workbook = new XSSFWorkbook(inputStream); XSSFSheet sheet = workbook.getSheet("Model"); // // Extract the Tests // for (int i = 1; i <= sheet.getLastRowNum(); i++) { XSSFRow currentRow = sheet.getRow(i); String pageName = getCellValue(currentRow.getCell(0)); if (pageName.toLowerCase().equals("name")) continue; String className = getCellValue(currentRow.getCell(1)); try { Class useClass = KeyWordPage.class; if (className != null && !className.isEmpty()) useClass = (Class<Page>) Class.forName(className); if (log.isDebugEnabled()) log.debug("Creating page as " + useClass.getSimpleName() + " for " + pageName); KeyWordDriver.instance().addPage(pageName, useClass); } catch (Exception e) { log.error("Error creating instance of [" + className + "]"); } } sheet = workbook.getSheet("Tests"); // // Extract the Tests // for (int i = 1; i <= sheet.getLastRowNum(); i++) { XSSFRow currentRow = sheet.getRow(i); List<String> testDefinition = new ArrayList<String>(10); for (int j = 0; j < currentRow.getLastCellNum(); j++) testDefinition.add(getCellValue(currentRow.getCell(j))); MatrixTest currentTest = new MatrixTest(testDefinition.toArray(new String[0])); if (currentTest.getName() != null && !currentTest.getName().isEmpty() && currentTest.isActive()) testList.add(currentTest); } for (MatrixTest currentTest : testList) { List<String[]> stepList = new ArrayList<String[]>(20); sheet = workbook.getSheet(currentTest.getName()); if (sheet != null) { for (int i = 1; i <= sheet.getLastRowNum(); i++) { XSSFRow currentRow = sheet.getRow(i); List<String> stepDefinition = new ArrayList<String>(10); for (int j = 0; j < currentRow.getLastCellNum(); j++) stepDefinition.add(getCellValue(currentRow.getCell(j))); stepList.add(stepDefinition.toArray(new String[0])); } } currentTest.setStepDefinition((String[][]) stepList.toArray(new String[0][0])); } for (MatrixTest currentTest : testList) { if (currentTest.getType().equals("function")) KeyWordDriver.instance().addFunction(currentTest.createTest()); else KeyWordDriver.instance().addTest(currentTest.createTest()); } } catch (Exception e) { log.fatal("Error reading Excel Element File", e); } finally { try { workbook.close(); } catch (Exception e) { } } }
From source file:parser.CloudDSFParser.java
License:Apache License
/** * Retrieves the knowledge base of the CloudDSF from the knowledge base sheet and the relations. * /*from w w w .j a v a2 s . c o m*/ * @return cdsf object */ public CloudDSF readExcel() { // Get desired sheet from the workbook XSSFSheet sheet = workbook.getSheet("Knowledge Base"); // setup variables String decisionName = ""; String decisionPointName = ""; DecisionPoint decisionPoint; Decision decision; Outcome outcome; int decisionPointId = 0; int decisionId = 0; int outcomeId = 0; // iterate over all rows skipping headline for (int j = 1; j <= sheet.getLastRowNum(); j++) { Row row = sheet.getRow(j); // select cell A Cell cell = row.getCell(dpCol); // if not empty than new decision Point if (cell.getStringCellValue().equals("") == false) { // calculate Ids decisionPointId++; decisionId = decisionPointId * 100 + 1; outcomeId = decisionId * 100 + 1; // create new DecisionPoint decisionPointName = cell.getStringCellValue(); decisionPoint = new DecisionPoint(decisionPointName, decisionPointId, row.getCell(dpClassCol).getStringCellValue()); // create new Decision Cell decisionCell = row.getCell(decCol); decisionName = decisionCell.getStringCellValue(); decision = new Decision(decisionName, row.getCell(decClassCol).getStringCellValue(), decisionId, decisionPointId); // create new outcome Cell outcomeCell = row.getCell(outCol); outcome = new Outcome(outcomeCell.getStringCellValue(), outcomeId, decisionId); // add outcome to decision decision.addOutcome(outcome); // add decision to decision point decisionPoint.addDecision(decision); // add decision point to cloudDSF cdsf.addDecisionPoint(decisionPoint); } else { // Select Cell B Cell decisionCell = row.getCell(decCol); // if text than new decision if (decisionCell.getStringCellValue().equals("") == false) { decisionId++; outcomeId = decisionId * 100 + 1; // create new decision decisionName = decisionCell.getStringCellValue(); decision = new Decision(decisionName, row.getCell(decClassCol).getStringCellValue(), decisionId, decisionPointId); // create new outcome Cell outcomeCell = row.getCell(outCol); outcome = new Outcome(outcomeCell.getStringCellValue(), outcomeId, decisionId); // add outcome to decision decision.addOutcome(outcome); // add decision to current decision point cdsf.getDecisionPoint(decisionPointName).addDecision(decision); } else { // if no text in dp or d than new outcome outcomeId++; // create new outcome Cell outcomeCell = row.getCell(outCol); outcome = new Outcome(outcomeCell.getStringCellValue(), outcomeId, decisionId); // add outcome to current decision in current decision point cdsf.getDecisionPoint(decisionPointName).getDecision(decisionName).addOutcome(outcome); } } } // parse the relations setInfluencingRelations(); setTasks(); setInfluencingTasks(); // sort knowledge base and relations cdsf.sortEntities(); cdsf.sortLists(); // return cdsf object return cdsf; }
From source file:parser.CloudDSFParser.java
License:Apache License
/** * Retrieves influencing relations between decisions. All decisions (influencing, affecting, * binding) are parsed and stored as basic influencing ones for the cloudDSF. * //w ww . j a v a 2 s . c o m * @return */ private void setInfluencingRelations() { XSSFSheet sheet = workbook.getSheet("Decision Level"); // Column B has name of start Decision int startDecisionColumn = 1; // Row 1 has names of endDecision Row endDecisionRow = sheet.getRow(1); // Iterate over all rows starting at 3 Iterator<Row> rows = sheet.rowIterator(); while (rows.hasNext()) { XSSFRow row = (XSSFRow) rows.next(); // Iterate over cells Iterator<Cell> cells = row.cellIterator(); while (cells.hasNext()) { XSSFCell cell = (XSSFCell) cells.next(); String relationName = cell.getStringCellValue(); if (relationName.equals("Influencing") || relationName.equals("Affecting") || relationName.equals("Binding")) { // if type of relationship matches predefined values get names of the two participating // decisions String startDecision = row.getCell(startDecisionColumn).getStringCellValue(); String endDecision = endDecisionRow.getCell(cell.getColumnIndex()).getStringCellValue(); // add new decision relation cdsf.setLegacyDecisionRelation(startDecision, endDecision); } } } }