List of usage examples for org.apache.poi.ss.usermodel Sheet getPhysicalNumberOfRows
int getPhysicalNumberOfRows();
From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java
public List<Camera> readCameraRows(Sheet sheet, Organ organ, List<Dvr> dvrs, License license) { List<Camera> list = new ArrayList<Camera>(); List<Manufacturer> manufs = manufacturerDAO.findAll(); // license//w w w. j a v a2 s . c o m int rows = sheet.getPhysicalNumberOfRows(); int cameraAmount = Integer.parseInt(license.getCameraAmount()); int cameraCount = countCamera(); if (((rows - 1) + cameraCount) > cameraAmount) { throw new BusinessException(ErrorCode.CAMERA_AMOUNT_LIMIT, "camera more than limit"); } // ?standardNumber String[] standardNumber = batchGenerateSN("Camera", organ.getId(), (rows - 1)); List<TemplateDvrIsChannelNumberVO> tdcs = new ArrayList<TemplateDvrIsChannelNumberVO>(); List<String> cameraNames = cameraDAO.findNameByCamera(); // ??? List<String> snList = cameraDAO.listCameraSN(); List<String> dvrNumbers = new ArrayList<String>(); // excel?dvrNumber? int rowIndex = 0; // ? int notnullRowIndex = 0; // ? int[] arrayChannelAmount = null; // dvr?? Dvr dvr = null; while (notnullRowIndex < rows) { Row row = sheet.getRow(rowIndex); if (row != null) { if (rowIndex != 0) {// ?? // excel?standardNumber?dvr???dvr String dvrNumber = findDvrNumber(row, rowIndex); // cameraNames.add(isCameraNameExist(cameraNames, rowIndex, // row)); // ?????? if (dvr == null) { TemplateDvrIsChannelNumberVO tdc = new TemplateDvrIsChannelNumberVO(); dvr = findDvr(dvrs, dvrNumber, rowIndex); arrayChannelAmount = new int[dvr.getChannelAmount()]; for (int i = 0; i < arrayChannelAmount.length; i++) {// ? arrayChannelAmount[i] = i + 1; } dvrNumbers.add(dvrNumber); tdc.setDvrNumber(dvrNumber); tdc.setArrayChannelAmount(arrayChannelAmount); tdcs.add(tdc); } else { if (!dvrNumbers.contains(dvrNumber)) { TemplateDvrIsChannelNumberVO tdc = new TemplateDvrIsChannelNumberVO(); dvr = findDvr(dvrs, dvrNumber, rowIndex); arrayChannelAmount = new int[dvr.getChannelAmount()]; for (int n = 0; n < arrayChannelAmount.length; n++) {// ? arrayChannelAmount[n] = n + 1; } dvrNumbers.add(dvrNumber); tdc.setDvrNumber(dvrNumber); tdc.setArrayChannelAmount(arrayChannelAmount); tdcs.add(tdc); } } isExistChannelNumber(row, dvr, rowIndex, tdcs);// ????? list.add(readCameraCells(row, rowIndex, organ, dvr, standardNumber[notnullRowIndex - 1], manufs, snList)); } notnullRowIndex++; } rowIndex++; } return list; }
From source file:com.znsx.cms.service.impl.TmDeviceManagerImpl.java
private List<FireDetector> readFireDetectors(Sheet sheet) { List<FireDetector> list = new ArrayList<FireDetector>(); int rows = sheet.getPhysicalNumberOfRows(); int rowIndex = 0; // ? int notnullRowIndex = 0; // ? while (notnullRowIndex < rows) { Row row = sheet.getRow(rowIndex); if (row != null) { if (rowIndex != 0) { list.add(readFireDetector(row, rowIndex)); }//from w ww .ja v a 2 s. c o m notnullRowIndex++; } rowIndex++; } return list; }
From source file:com.znsx.cms.service.impl.TmDeviceManagerImpl.java
private List<ControlDeviceLight> readControlDeviceLightWbs(Sheet sheet) { List<ControlDeviceLight> list = new ArrayList<ControlDeviceLight>(); int rows = sheet.getPhysicalNumberOfRows(); int rowIndex = 0; // ? int notnullRowIndex = 0; // ? while (notnullRowIndex < rows) { Row row = sheet.getRow(rowIndex); if (row != null) { if (rowIndex != 0) { list.add(readControlDeviceLightWb(row, rowIndex)); }//from w w w. j a v a2 s .com notnullRowIndex++; } rowIndex++; } return list; }
From source file:com.znsx.cms.service.impl.TmDeviceManagerImpl.java
private List<ControlDeviceWp> readControlDeviceWps(Sheet sheet) { List<ControlDeviceWp> list = new ArrayList<ControlDeviceWp>(); int rows = sheet.getPhysicalNumberOfRows(); int rowIndex = 0; // ? int notnullRowIndex = 0; // ? while (notnullRowIndex < rows) { Row row = sheet.getRow(rowIndex); if (row != null) { if (rowIndex != 0) { list.add(readControlDeviceWp(row, rowIndex)); }/*w w w .j ava 2s. c o m*/ notnullRowIndex++; } rowIndex++; } return list; }
From source file:com.znsx.cms.service.impl.TmDeviceManagerImpl.java
private List<PushButton> readPushButtonWbs(Sheet sheet) { List<PushButton> list = new ArrayList<PushButton>(); int rows = sheet.getPhysicalNumberOfRows(); int rowIndex = 0; // ? int notnullRowIndex = 0; // ? while (notnullRowIndex < rows) { Row row = sheet.getRow(rowIndex); if (row != null) { if (rowIndex != 0) { list.add(readPushButtonWb(row, rowIndex)); }/*from w ww . java 2s. c o m*/ notnullRowIndex++; } rowIndex++; } return list; }
From source file:com.znsx.cms.service.impl.TmDeviceManagerImpl.java
private List<ControlDeviceLil> readControlDeviceLilWbs(Sheet sheet) { List<ControlDeviceLil> list = new ArrayList<ControlDeviceLil>(); int rows = sheet.getPhysicalNumberOfRows(); int rowIndex = 0; // ? int notnullRowIndex = 0; // ? while (notnullRowIndex < rows) { Row row = sheet.getRow(rowIndex); if (row != null) { if (rowIndex != 0) { list.add(readControlDeviceLilWb(row, rowIndex)); }// w ww.ja v a 2 s. co m notnullRowIndex++; } rowIndex++; } return list; }
From source file:com.znsx.cms.service.impl.TmDeviceManagerImpl.java
private List<ControlDeviceFan> readControlDeviceFanWbs(Sheet sheet) { List<ControlDeviceFan> list = new ArrayList<ControlDeviceFan>(); int rows = sheet.getPhysicalNumberOfRows(); int rowIndex = 0; // ? int notnullRowIndex = 0; // ? while (notnullRowIndex < rows) { Row row = sheet.getRow(rowIndex); if (row != null) { if (rowIndex != 0) { list.add(readControlDeviceFanWb(row, rowIndex)); }//from w w w . j a v a 2 s .c om notnullRowIndex++; } rowIndex++; } return list; }
From source file:controller.VisitasController.java
public void autoSizeColumns(Workbook workbook) { int numberOfSheets = workbook.getNumberOfSheets(); for (int i = 0; i < numberOfSheets; i++) { Sheet sheet = workbook.getSheetAt(i); if (sheet.getPhysicalNumberOfRows() > 0) { Row row = sheet.getRow(8);// www. j av a2 s .co m Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); int columnIndex = cell.getColumnIndex(); sheet.autoSizeColumn(columnIndex); } } } }
From source file:controllers.TargetController.java
License:Open Source License
private static void excelParser(File inputFile) throws Throwable { FileInputStream file = new FileInputStream(inputFile); //Create Workbook instance holding reference to .xls[x] file Workbook workbook = WorkbookFactory.create(file); //Get first/desired sheet from the workbook Sheet sheet = workbook.getSheetAt(0); // Check total row: if (sheet.getPhysicalNumberOfRows() <= 1) { throw new Exception("Sheet should have at least one row."); }//from w w w .j a va 2 s . c o m Logger.debug("Sheet has " + sheet.getPhysicalNumberOfRows() + " rows."); //Iterate through each rows one by one Iterator<Row> rowIterator = sheet.iterator(); // Header row: Row header = rowIterator.next(); Logger.debug("HEADER: " + header); // TODO Check header row is right. // And the rest: StringBuilder sb = new StringBuilder(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); // Get Target target = new Target(); target.title = row.getCell(0).getStringCellValue(); target.fieldUrls = new ArrayList<FieldUrl>(); // Check URL FieldUrl url = new FieldUrl(row.getCell(1).getStringCellValue()); target.fieldUrls.add(url); FieldUrl existingFieldUrl = FieldUrl.findByUrl(url.url); if (existingFieldUrl != null) { String error = "Row # " + row.getRowNum() + ": CONFLICT - URL " + existingFieldUrl.url + " is already part of target " + existingFieldUrl.target.id + "\n"; Logger.debug(error); sb.append(error); continue; } //Collection c = new Collection(); //c.name = // System.out.println(target); // TODO Merge with controllers.ApplicationController.bulkImport() code to avoid repetition. target.revision = Const.INITIAL_REVISION; target.active = true; target.selectionType = Const.SelectionType.SELECTION.name(); if (target.noLdCriteriaMet == null) { target.noLdCriteriaMet = Boolean.FALSE; } if (target.keySite == null) { target.keySite = Boolean.FALSE; } if (target.ignoreRobotsTxt == null) { target.ignoreRobotsTxt = Boolean.FALSE; } // Save - disabled right now, as we do not want this live as yet. /* target.runChecks(); target.save(); */ // System.out.println(target); } workbook.close(); file.close(); // And report errors if (sb.length() > 0) { throw (new Exception(sb.toString())); } }
From source file:edu.gatech.pmase.capstone.awesome.impl.database.AbstractDatabaseDriver.java
License:Open Source License
/** * Reads the custom attribute values from the custom attribute sheet. * * @param wb the workbook to read the custom attributes from *//*w w w . ja v a 2s. co m*/ protected synchronized void setCustomAttributes(final Workbook wb) { LOGGER.info("Loading custom attribute list"); customAttributes.clear(); final Sheet customSheet = wb.getSheetAt(CUSTOM_ATTR_SHEET_NUM); if (null != customSheet) { LOGGER.debug("Custom attribute list stored in sheet: " + customSheet.getSheetName()); final int maxRows = customSheet.getPhysicalNumberOfRows(); if (maxRows > 1) { for (int rowIter = 1; rowIter < maxRows; rowIter++) { final Row row = customSheet.getRow(rowIter); if (null != row) { try { customAttributes.add(AbstractDatabaseDriver.getAttributeDescriptionFromRow(row)); } catch (ClassNotFoundException ex) { LOGGER.error("Could not load custom attribute for row: " + row.getRowNum(), ex); } } } } } else { LOGGER.warn("Could not load customer sheet"); } }