List of usage examples for org.apache.poi.ss.usermodel Cell getRowIndex
int getRowIndex();
From source file:com.dituiba.excel.AdapterException.java
License:Apache License
public AdapterException(String message, Cell cell) { this.message = LanguageUtils.translate(message, cell.getRowIndex(), cell.getColumnIndex(), cell.toString()); }
From source file:com.dituiba.excel.AdapterException.java
License:Apache License
public AdapterException(String fieldName, String message, Cell cell) { this.fieldName = fieldName; this.message = LanguageUtils.translate(message, fieldName, cell.getRowIndex(), cell.getColumnIndex(), cell.toString());/*from ww w .jav a 2 s . c o m*/ }
From source file:com.fanniemae.ezpie.data.connectors.ExcelConnector.java
License:Open Source License
protected void readColumnNames() { // read the schema from the first row or the named row. _headerRange = null;/*from w ww . jav a 2s . c o m*/ Row headerRow = null; if (StringUtilities.isNotNullOrEmpty(_columnNameAddress)) { _headerRange = new ExcelRange(_columnNameAddress); CellReference cr = _headerRange.getStartCell(); headerRow = _sheet.getRow(cr.getRow()); } else { Iterator<Row> iterator = _sheet.iterator(); headerRow = iterator.next(); } _columnCount = 0; int endColumnIndex = (_headerRange == null) ? -1 : _headerRange.getEndColumn(); String value = ""; _columnLabels = new ArrayList<String>(); _columnAddress = new ArrayList<String>(); List<String> usedLabels = new ArrayList<String>(); for (Cell cell : headerRow) { String columnLetter = CellReference.convertNumToColString(cell.getColumnIndex()); if ((endColumnIndex != -1) && (cell.getColumnIndex() > endColumnIndex)) { break; } CellType ct = cell.getCellTypeEnum(); if (ct == CellType.FORMULA) ct = cell.getCachedFormulaResultTypeEnum(); switch (ct) { case STRING: value = cell.getStringCellValue(); if (usedLabels.contains(value.toLowerCase())) value = String.format("%s_%s%d", value, columnLetter, cell.getRowIndex() + 1); else usedLabels.add(value.toLowerCase()); _columnLabels.add(value); _columnAddress.add(columnLetter); break; case BOOLEAN: case NUMERIC: case FORMULA: case BLANK: _columnLabels.add(String.format("Column_%s", columnLetter)); _columnAddress.add(columnLetter); break; default: break; } } _columnCount = _columnLabels.size(); _dataSchema = new String[_columnCount][2]; _dataTypes = new DataType[_columnCount]; for (int i = 0; i < _columnCount; i++) { _dataSchema[i][0] = _columnLabels.get(i); } }
From source file:com.github.camaral.sheeco.exceptions.SpreadsheetViolation.java
License:Apache License
public SpreadsheetViolation(final String msgKey, final Cell cell) { this.msgKey = msgKey; this.colNumber = cell.getColumnIndex(); this.rowRange = new RowRange(cell.getRowIndex()); this.originalValue = new OriginalCellValue(getCellType(cell), getCellValue(cell)); }
From source file:com.github.crab2died.handler.SheetTemplateHandler.java
License:Open Source License
/** * ???/*w w w . j av a2 s . co m*/ */ private static void initStyles(SheetTemplate template, Cell cell, String moduleContext) { if (null == moduleContext || "".equals(moduleContext)) return; if (!moduleContext.startsWith("&")) moduleContext = moduleContext.toLowerCase(); if (HandlerConstant.DEFAULT_STYLE.equals(moduleContext)) { template.defaultStyle = cell.getCellStyle(); clearCell(cell); } if (moduleContext.startsWith("&") && moduleContext.length() > 1) { template.classifyStyle.put(moduleContext.substring(1), cell.getCellStyle()); clearCell(cell); } if (HandlerConstant.APPOINT_LINE_STYLE.equals(moduleContext)) { template.appointLineStyle.put(cell.getRowIndex(), cell.getCellStyle()); clearCell(cell); } if (HandlerConstant.SINGLE_LINE_STYLE.equals(moduleContext)) { template.singleLineStyle = cell.getCellStyle(); clearCell(cell); } if (HandlerConstant.DOUBLE_LINE_STYLE.equals(moduleContext)) { template.doubleLineStyle = cell.getCellStyle(); clearCell(cell); } }
From source file:com.github.crab2died.handler.SheetTemplateHandler.java
License:Open Source License
/** * ??//w w w .j ava 2 s . c o m * * @param cell cell * @param styleKey ? */ private static void setCellStyle(SheetTemplate template, Cell cell, String styleKey) { if (null != styleKey && null != template.classifyStyle.get(styleKey)) { cell.setCellStyle(template.classifyStyle.get(styleKey)); return; } if (null != template.appointLineStyle && template.appointLineStyle.containsKey(cell.getRowIndex())) { cell.setCellStyle(template.appointLineStyle.get(cell.getRowIndex())); return; } if (null != template.singleLineStyle && (cell.getRowIndex() % 2 != 0)) { cell.setCellStyle(template.singleLineStyle); return; } if (null != template.doubleLineStyle && (cell.getRowIndex() % 2 == 0)) { cell.setCellStyle(template.doubleLineStyle); return; } if (null != template.defaultStyle) cell.setCellStyle(template.defaultStyle); }
From source file:com.github.svrtm.xlreport.ACell.java
License:Apache License
List<Cell> findMergedCells(final Cell poiCell) { if (builder.regionsList == null) return null; List<Cell> mergedCells; int rowIndex = poiCell.getRowIndex(); for (final CellRangeAddress region : builder.regionsList) if (region.isInRange(rowIndex, poiCell.getColumnIndex())) { final int firstCol = region.getFirstColumn(); final int lastCol = region.getLastColumn(); final int firstRow = region.getFirstRow(); final int lastRow = region.getLastRow(); mergedCells = new ArrayList<Cell>(region.getNumberOfCells()); for (rowIndex = firstRow; rowIndex <= lastRow; rowIndex++) { final Row<HB, ?, ?, ?> row; row = builder.rowOrCreateIfAbsent(rowIndex); for (int colIdx = firstCol; colIdx <= lastCol; colIdx++) { final Cell mergedCell; mergedCell = row.cellOrCreateIfAbsent(colIdx).poiCell; mergedCells.add(mergedCell); }/*from w w w . ja v a 2 s . c o m*/ } return mergedCells; } return null; }
From source file:com.hauldata.dbpa.file.book.XlsxTargetSheet.java
License:Apache License
private void adjustAdjacentCellStyle(Cell cell, Styles styles, RowPosition rowPosition, ColumnPosition columnPosition, Styles leftStyles, Styles aboveStyles) { if (styles == null) { return;//www .j a v a2 s. c om } if ((leftStyles != null) && (columnPosition != ColumnPosition.LEFT) && (columnPosition != ColumnPosition.SINGLE) && !leftStyles.rightBorder.equals(styles.leftBorder)) { leftStyles.rightBorder = styles.leftBorder; Cell leftCell = cell.getRow().getCell(cell.getColumnIndex() - 1); leftCell.setCellStyle(composeCellStyle(leftCell, leftStyles)); } if ((aboveStyles != null) && (rowPosition != RowPosition.HEADER) && (rowPosition != RowPosition.TOP) && !aboveStyles.bottomBorder.equals(styles.topBorder)) { aboveStyles.bottomBorder = styles.topBorder; Cell aboveCell = sheet.getRow(cell.getRowIndex() - 1).getCell(cell.getColumnIndex()); aboveCell.setCellStyle(composeCellStyle(aboveCell, aboveStyles)); } }
From source file:com.jeefuse.system.code.web.imports.excel.GsysCodeExcelImport.java
License:GNU General Public License
/** * populate model./* w ww. j a va2s.c o m*/ * * @generated */ @Override protected GsysCode readExcelToModel(Row row, String[] columnNames) { if (row == null) return null; GsysCode model = new GsysCode(); int cellLenght = columnNames.length; Cell cell = null; for (int i = 0; i < cellLenght; i++) { cell = row.getCell(i); String columnName = columnNames[i]; GsysCodeField gsysCodeField = GsysCodeField.valueOfFieldLabel(columnName); if (null == gsysCodeField) { gsysCodeField = GsysCodeField.valueOfFieldName(columnName); } if (null == gsysCodeField) throw new DataNoExistException("??:" + columnName); setModelData(model, cell, gsysCodeField); InvalidValue[] invalidValues = GsysCodeValidate.validateProperty(model, gsysCodeField); if (invalidValues.length > 0) { List<String> errors = new ArrayList<String>(); for (InvalidValue invalidValue : invalidValues) { errors.add(gsysCodeField.getFieldLabel() + ": " + invalidValue.getMessage()); } throw new ValidateViolationException("" + (cell.getRowIndex() + 1) + "," + (cell.getColumnIndex() + 1) + "!", errors); } } return model; }
From source file:com.jeefuse.system.code.web.imports.excel.GsysCodevalueExcelImport.java
License:GNU General Public License
/** * populate model.//from ww w . j a v a 2s . c o m * * @generated */ @Override protected GsysCodevalue readExcelToModel(Row row, String[] columnNames) { if (row == null) return null; GsysCodevalue model = new GsysCodevalue(); int cellLenght = columnNames.length; Cell cell = null; for (int i = 0; i < cellLenght; i++) { cell = row.getCell(i); String columnName = columnNames[i]; GsysCodevalueField gsysCodevalueField = GsysCodevalueField.valueOfFieldLabel(columnName); if (null == gsysCodevalueField) { gsysCodevalueField = GsysCodevalueField.valueOfFieldName(columnName); } if (null == gsysCodevalueField) throw new DataNoExistException("??:" + columnName); setModelData(model, cell, gsysCodevalueField); InvalidValue[] invalidValues = GsysCodevalueValidate.validateProperty(model, gsysCodevalueField); if (invalidValues.length > 0) { List<String> errors = new ArrayList<String>(); for (InvalidValue invalidValue : invalidValues) { errors.add(gsysCodevalueField.getFieldLabel() + ": " + invalidValue.getMessage()); } throw new ValidateViolationException("" + (cell.getRowIndex() + 1) + "," + (cell.getColumnIndex() + 1) + "!", errors); } } return model; }