List of usage examples for org.apache.poi.xssf.usermodel XSSFRow getCell
@Override public XSSFCell getCell(int cellnum)
From source file:org.xframium.device.cloud.ExcelCloudProvider.java
License:Open Source License
/** * Read elements./* w w w . j a v a2 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); 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./* ww w. j av a 2s . 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./*from w ww. j a va 2 s . 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 va 2 s .c om * * @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 va 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:packtest.AligningCells.java
License:Apache License
/** * Center a text over multiple columns using ALIGN_CENTER_SELECTION * * @param wb the workbook//ww w. ja va2 s.c o m * @param row the row to create the cell in * @param start_column the column number to create the cell in and where the selection starts * @param end_column the column number where the selection ends * @param valign the horizontal alignment for the cell. * * @author Cristian Petrula, Romania */ private static void centerAcrossSelection(XSSFWorkbook wb, XSSFRow row, short start_column, short end_column, short valign) { // Create cell style with ALIGN_CENTER_SELECTION XSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER_SELECTION); cellStyle.setVerticalAlignment(valign); // Create cells over the selected area for (int i = start_column; i <= end_column; i++) { XSSFCell cell = row.createCell(i); cell.setCellStyle(cellStyle); } // Set value to the first cell XSSFCell cell = row.getCell(start_column); cell.setCellValue(new XSSFRichTextString("Align It")); // Make the selection CTRowImpl ctRow = (CTRowImpl) row.getCTRow(); // Add object with format start_coll:end_coll. For example 1:3 will span from // cell 1 to cell 3, where the column index starts with 0 // // You can add multiple spans for one row Object span = start_column + ":" + end_column; List<Object> spanList = new ArrayList<Object>(); spanList.add(span); //add spns to the row ctRow.setSpans(spanList); }
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. * //from w ww.j av a 2s. c om * @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); } } } }
From source file:parser.CloudDSFParser.java
License:Apache License
/** * Retrieves influencing relations between tasks and decisions. *//* w w w. j ava2 s. c o m*/ private void setInfluencingTasks() { XSSFSheet sheet = workbook.getSheet("Task Level"); // Column A has name of start Task int startTaskColumn = 0; // Row 1 has names of endDecision Row endDecisionRow = sheet.getRow(1); // Iterate over all rows Iterator<Row> rows = sheet.rowIterator(); while (rows.hasNext()) { XSSFRow row = (XSSFRow) rows.next(); Iterator<Cell> cells = row.cellIterator(); while (cells.hasNext()) { XSSFCell cell = (XSSFCell) cells.next(); if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { // Depending on the relation type source and target are set // accordingly String relationName = cell.getStringCellValue(); String sourceDesc = row.getCell(startTaskColumn).getStringCellValue(); String targetDesc = endDecisionRow.getCell(cell.getColumnIndex()).getStringCellValue(); switch (relationName) { case "Affecting": cdsf.setTaskRelation(sourceDesc, targetDesc, "oneWay"); break; case "Both": cdsf.setTaskRelation(sourceDesc, targetDesc, "twoWay"); break; case "Affected": cdsf.setTaskRelation(sourceDesc, targetDesc, "backwards"); break; // no default } } } } }
From source file:parser.CloudDSFPlusParser.java
License:Apache License
/** * Retrieves influencing relations between decisions. * // www . j ava2s . 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(); // select cell C Iterator<Cell> cells = row.cellIterator(); // Iterate of all cells in row while (cells.hasNext()) { XSSFCell cell = (XSSFCell) cells.next(); String relationType = cell.getStringCellValue(); if (relationType.equals("Influencing") || relationType.equals("Affecting") || relationType.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 decision relation to cloudDSFPlus cdsf.setDecisionRelation(startDecision, endDecision, relationType, null); } } } }
From source file:parser.CloudDSFPlusParser.java
License:Apache License
/** * Retrieves requiring relations between decisions. * //from ww w . ja va2s . co m * @return */ private void setRequiringRelations() { XSSFSheet sheet = workbook.getSheet("Required 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(); Iterator<Cell> cells = row.cellIterator(); while (cells.hasNext()) { XSSFCell cell = (XSSFCell) cells.next(); String relationType = cell.getStringCellValue(); if (relationType.equals("Requiring")) { // if requiring relationship is denoted get names of both decisions String startDecision = row.getCell(startDecisionColumn).getStringCellValue(); String endDecision = endDecisionRow.getCell(cell.getColumnIndex()).getStringCellValue(); // add requiring relation to cloudDSFPlus cdsf.setDecisionRelation(startDecision, endDecision, relationType, null); } } } }