Java Code Examples for org.apache.poi.ss.usermodel.Cell#getColumnIndex()
The following examples show how to use
org.apache.poi.ss.usermodel.Cell#getColumnIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamingReaderTest.java From excel-streaming-reader with Apache License 2.0 | 6 votes |
@Test public void testNullValueType() throws Exception { try( InputStream is = new FileInputStream(new File("src/test/resources/null_celltype.xlsx")); Workbook wb = StreamingReader.builder().open(is); ) { for(Row r : wb.getSheetAt(0)) { for(Cell cell : r) { if(r.getRowNum() == 0 && cell.getColumnIndex() == 8) { assertEquals(NUMERIC, cell.getCellType()); assertEquals("8:00:00", cell.getStringCellValue()); } } } } }
Example 2
Source File: CellRangeTester.java From birt with Eclipse Public License 1.0 | 6 votes |
protected void validateCellRange(Matcher matcher, Cell cell) { int desiredR1 = Integer.parseInt( matcher.group(1) ); int desiredC1 = Integer.parseInt( matcher.group(2) ); int desiredR2 = Integer.parseInt( matcher.group(3) ); int desiredC2 = Integer.parseInt( matcher.group(4) ); int actualR1 = cell.getRowIndex() + 1; int actualC1 = cell.getColumnIndex() + 1; int actualR2 = actualR1; int actualC2 = actualC1; for( int i = 0; i < cell.getSheet().getNumMergedRegions(); ++i) { CellRangeAddress cra = cell.getSheet().getMergedRegion(i); if( ( cra.getFirstRow() == cell.getRowIndex() ) && ( cra.getFirstColumn() == cell.getColumnIndex() ) ) { assertEquals( actualR1, actualR2 ); assertEquals( actualC1, actualC2 ); actualR2 = cra.getLastRow() + 1; actualC2 = cra.getLastColumn() + 1; } } assertEquals( desiredR1, actualR1 ); assertEquals( desiredC1, actualC1 ); assertEquals( desiredR2, actualR2 ); assertEquals( desiredC2, actualC2 ); }
Example 3
Source File: StreamingReaderTest.java From excel-streaming-reader with Apache License 2.0 | 5 votes |
@Test public void testSpecialStyles() throws Exception { File f = new File("src/test/resources/special_types.xlsx"); Map<Integer, List<Cell>> contents = new HashMap<>(); try(Workbook wb = StreamingReader.builder().open(f)) { for(Row row : wb.getSheetAt(0)) { contents.put(row.getRowNum(), new ArrayList<Cell>()); for(Cell c : row) { if(c.getColumnIndex() > 0) { contents.get(row.getRowNum()).add(c); } } } } SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); assertThat(contents.size(), equalTo(2)); assertThat(contents.get(0).size(), equalTo(4)); assertThat(contents.get(0).get(0).getStringCellValue(), equalTo("Thu\", \"Dec 25\", \"14")); assertThat(contents.get(0).get(0).getDateCellValue(), equalTo(df.parse("25/12/2014"))); assertThat(contents.get(0).get(1).getStringCellValue(), equalTo("02/04/15")); assertThat(contents.get(0).get(1).getDateCellValue(), equalTo(df.parse("04/02/2015"))); assertThat(contents.get(0).get(2).getStringCellValue(), equalTo("14\". \"Mar\". \"2015")); assertThat(contents.get(0).get(2).getDateCellValue(), equalTo(df.parse("14/03/2015"))); assertThat(contents.get(0).get(3).getStringCellValue(), equalTo("2015-05-05")); assertThat(contents.get(0).get(3).getDateCellValue(), equalTo(df.parse("05/05/2015"))); assertThat(contents.get(1).size(), equalTo(4)); assertThat(contents.get(1).get(0).getStringCellValue(), equalTo("3.12")); assertThat(contents.get(1).get(0).getNumericCellValue(), equalTo(3.12312312312)); assertThat(contents.get(1).get(1).getStringCellValue(), equalTo("1,023,042")); assertThat(contents.get(1).get(1).getNumericCellValue(), equalTo(1023042.0)); assertThat(contents.get(1).get(2).getStringCellValue(), equalTo("-312,231.12")); assertThat(contents.get(1).get(2).getNumericCellValue(), equalTo(-312231.12123145)); assertThat(contents.get(1).get(3).getStringCellValue(), equalTo("(132)")); assertThat(contents.get(1).get(3).getNumericCellValue(), equalTo(-132.0)); }
Example 4
Source File: ExcelUtils.java From onetwo with Apache License 2.0 | 5 votes |
public static void removeCellRange(Row row){ Sheet sheet = row.getSheet(); for(Cell cell : row){ for(int i=0; i< sheet.getNumMergedRegions(); i++){ CellRangeAddress cr = sheet.getMergedRegion(i); if(cr.getFirstRow()==row.getRowNum() && cr.getFirstColumn()==cell.getColumnIndex()){ sheet.removeMergedRegion(i); } } } }
Example 5
Source File: POIUtils.java From xlsmapper with Apache License 2.0 | 5 votes |
/** * 結合を考慮してセルの罫線(右部)を取得する。 * * @param cell セル * @return {@literal BorderStyle} * @throws IllegalArgumentException {@literal cell is null.} */ public static BorderStyle getBorderLeft(final Cell cell) { ArgUtils.notNull(cell, "cell"); final Sheet sheet = cell.getSheet(); CellRangeAddress mergedRegion = getMergedRegion(sheet, cell.getRowIndex(), cell.getColumnIndex()); final Cell target; if(mergedRegion == null) { // 結合されていない場合 target = cell; } else { if(mergedRegion.getFirstColumn() == cell.getColumnIndex()) { // 引数のCellが左部のセルの場合 target = cell; } else { target = getCell(sheet, mergedRegion.getFirstColumn(), cell.getRowIndex()); } } final CellStyle style = target.getCellStyle(); if(style == null) { return BorderStyle.NONE; } else { return style.getBorderLeftEnum(); } }
Example 6
Source File: ExcelTopicNameExtractor.java From wandora with GNU General Public License v3.0 | 5 votes |
public Topic getDefaultLanguageTopic(Cell cell, TopicMap tm) { if(cell != null && tm != null) { int i = cell.getColumnIndex(); Topic typeTopic = getOrCreateTopic(tm, DEFAULT_LANGUAGE_SI+"/"+i, "Excel language "+i); return typeTopic; } return null; }
Example 7
Source File: IterateTablesProcessor.java From xlsmapper with Apache License 2.0 | 5 votes |
/** * XlsLabelledArrayCellを処理する。 * @param sheet * @param tableObj * @param headerCell * @param config * @throws XlsMapperException */ private void loadSingleLabelledArrayCell(final Sheet sheet, final Object tableObj, final Cell headerCell, final Configuration config, final LoadingWorkObject work) throws XlsMapperException { final LabelledArrayCellsProcessor labelledArrayCellProcessor = (LabelledArrayCellsProcessor) config.getFieldProcessorRegistry().getProcessor(XlsLabelledArrayCells.class); final List<FieldAccessor> properties = FieldAccessorUtils.getPropertiesWithAnnotation( tableObj.getClass(), work.getAnnoReader(), XlsLabelledArrayCells.class) .stream() .filter(p -> p.isReadable()) .collect(Collectors.toList()); for(FieldAccessor property : properties) { final XlsLabelledArrayCells anno = property.getAnnotationNullable(XlsLabelledArrayCells.class); Cell titleCell = null; try { titleCell = CellFinder.query(sheet, anno.label(), config) .startPosition(headerCell) .excludeStartPosition(true) .findWhenNotFoundException(); } catch (CellNotFoundException e) { if (anno.optional()) { continue; } else { throw e; } } final XlsLabelledArrayCells wrapAnno = new XlsLabelledArrayCellsForIterateTable( anno, titleCell.getRowIndex(), titleCell.getColumnIndex()); labelledArrayCellProcessor.loadProcess(sheet, tableObj, wrapAnno, property, config, work); } }
Example 8
Source File: IterateTablesProcessor.java From xlsmapper with Apache License 2.0 | 5 votes |
private void saveSingleLabelledCell(final Sheet sheet, final Object tableObj, final Cell headerCell, final Configuration config, final SavingWorkObject work) throws XlsMapperException { final LabelledCellProcessor labelledCellProcessor = (LabelledCellProcessor) config.getFieldProcessorRegistry().getProcessor(XlsLabelledCell.class); final List<FieldAccessor> properties = FieldAccessorUtils.getPropertiesWithAnnotation( tableObj.getClass(), work.getAnnoReader(), XlsLabelledCell.class) .stream() .filter(p -> p.isWritable()) .collect(Collectors.toList()); for(FieldAccessor property : properties) { final XlsLabelledCell anno = property.getAnnotationNullable(XlsLabelledCell.class); Cell titleCell = null; try { titleCell = CellFinder.query(sheet, anno.label(), config) .startPosition(headerCell) .excludeStartPosition(true) .findWhenNotFoundException(); } catch (CellNotFoundException e) { if (anno.optional()) { continue; } else { throw e; } } final XlsLabelledCell labelledCell = new XlsLabelledCellForIterateTable( anno, titleCell.getRowIndex(), titleCell.getColumnIndex()); labelledCellProcessor.saveProcess(sheet, tableObj, labelledCell, property, config, work); } }
Example 9
Source File: ExcelSheetParser.java From vividus with Apache License 2.0 | 5 votes |
private SheetDataLimits getSheetDataLimits(int lastRowCandidate) { SheetDataLimits sheetDataLimits = new SheetDataLimits(); boolean lastRowFound = false; for (int rowIndex = lastRowCandidate; rowIndex >= 0; rowIndex--) { Row row = sheet.getRow(rowIndex); if (null != row) { for (Cell cell : row) { if (null != cell && !CellUtils.getCellValueAsString(cell).isEmpty()) { if (!lastRowFound) { sheetDataLimits.setLastRowIndex(rowIndex); lastRowFound = true; } int cellIndex = cell.getColumnIndex(); if (cellIndex > sheetDataLimits.getLastColumnIndex()) { sheetDataLimits.setLastColumnIndex(cellIndex); } } } } } return sheetDataLimits; }
Example 10
Source File: HSSFUnmarshaller.java From poiji with MIT License | 5 votes |
private void loadColumnTitles(Sheet sheet, int maxPhysicalNumberOfRows) { if (maxPhysicalNumberOfRows > 0) { int row = options.getHeaderStart(); Row firstRow = sheet.getRow(row); for (Cell cell : firstRow) { final int columnIndex = cell.getColumnIndex(); caseSensitiveTitlePerColumnIndex.put(columnIndex, getTitleNameForMap(cell.getStringCellValue(), columnIndex)); final String titleName = options.getCaseInsensitive() ? cell.getStringCellValue().toLowerCase() : cell.getStringCellValue(); columnIndexPerTitle.put(titleName, columnIndex); titlePerColumnIndex.put(columnIndex, getTitleNameForMap(titleName, columnIndex)); } } }
Example 11
Source File: CustomCellWriteHandler.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { // 这里可以对cell进行任何操作 LOGGER.info("第{}行,第{}列写入完成。", cell.getRowIndex(), cell.getColumnIndex()); if (isHead && cell.getColumnIndex() == 0) { CreationHelper createHelper = writeSheetHolder.getSheet().getWorkbook().getCreationHelper(); Hyperlink hyperlink = createHelper.createHyperlink(HyperlinkType.URL); hyperlink.setAddress("https://github.com/alibaba/easyexcel"); cell.setHyperlink(hyperlink); } }
Example 12
Source File: Excel2007Writer.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private int getLangIndex(Row header, TmxSegement segment) { for (Cell cell : header) { if (segment.getLangCode().equalsIgnoreCase(cell.toString())) { return cell.getColumnIndex(); } } return -1; }
Example 13
Source File: IterateTablesProcessor.java From xlsmapper with Apache License 2.0 | 5 votes |
private void saveSingleLabelledArrayCell(final Sheet sheet, final Object tableObj, final Cell headerCell, final Configuration config, final SavingWorkObject work) throws XlsMapperException { final LabelledArrayCellsProcessor labelledArrayCellProcessor = (LabelledArrayCellsProcessor) config.getFieldProcessorRegistry().getProcessor(XlsLabelledArrayCells.class); final List<FieldAccessor> properties = FieldAccessorUtils.getPropertiesWithAnnotation( tableObj.getClass(), work.getAnnoReader(), XlsLabelledArrayCells.class) .stream() .filter(p -> p.isWritable()) .collect(Collectors.toList()); for(FieldAccessor property : properties) { final XlsLabelledArrayCells anno = property.getAnnotationNullable(XlsLabelledArrayCells.class); Cell titleCell = null; try { titleCell = CellFinder.query(sheet, anno.label(), config) .startPosition(headerCell) .excludeStartPosition(true) .findWhenNotFoundException(); } catch (CellNotFoundException e) { if (anno.optional()) { continue; } else { throw e; } } final XlsLabelledArrayCells labelledCell = new XlsLabelledArrayCellsForIterateTable( anno, titleCell.getRowIndex(), titleCell.getColumnIndex()); labelledArrayCellProcessor.saveProcess(sheet, tableObj, labelledCell, property, config, work); } }
Example 14
Source File: IterateTablesProcessor.java From xlsmapper with Apache License 2.0 | 4 votes |
private void saveMultipleHorizontalTableCell(final Sheet sheet, final Object tableObj, final Cell headerCell, final XlsIterateTables iterateTables, final Configuration config, final SavingWorkObject work) throws XlsMapperException { final int headerColumn = headerCell.getColumnIndex(); int headerRow = headerCell.getRowIndex(); if (iterateTables.bottom() > 0) { // if positive value set to bottom(), row index of table header move headerRow += iterateTables.bottom(); } final HorizontalRecordsProcessor processor = (HorizontalRecordsProcessor) config.getFieldProcessorRegistry().getProcessor(XlsHorizontalRecords.class); final List<FieldAccessor> properties = FieldAccessorUtils.getPropertiesWithAnnotation( tableObj.getClass(), work.getAnnoReader(), XlsHorizontalRecords.class) .stream() .filter(p -> p.isWritable()) .collect(Collectors.toList()); final List<FieldAccessorProxy> accessorProxies = new ArrayList<>(); for(FieldAccessor property : properties) { final XlsHorizontalRecords anno = property.getAnnotationNullable(XlsHorizontalRecords.class); // 処理対象と同じテーブルラベルのとき、マッピングを実行する。 if(iterateTables.tableLabel().equals(anno.tableLabel())) { final XlsHorizontalRecords recordsAnno = new XlsHorizontalRecordsForIterateTables(anno, headerColumn, headerRow); accessorProxies.add(new FieldAccessorProxy(recordsAnno, processor, property)); } } // 順番を並び替えて保存処理を実行する Collections.sort(accessorProxies, new FieldAccessorProxyComparator()); for(FieldAccessorProxy adaptorProxy : accessorProxies) { adaptorProxy.saveProcess(sheet, tableObj, config, work); } }
Example 15
Source File: IterateTablesProcessor.java From xlsmapper with Apache License 2.0 | 4 votes |
private void saveMultipleVerticalTableCell(final Sheet sheet, final Object tableObj, final Cell headerCell, final XlsIterateTables iterateTablesAnno, final Configuration config, final SavingWorkObject work) throws XlsMapperException { int headerColumn = headerCell.getColumnIndex(); int headerRow = headerCell.getRowIndex(); if (iterateTablesAnno.bottom() > 0) { // if positive value set to bottom(), row index of table header move headerRow += iterateTablesAnno.bottom(); } final VerticalRecordsProcessor processor = (VerticalRecordsProcessor) config.getFieldProcessorRegistry().getProcessor(XlsVerticalRecords.class); final List<FieldAccessor> properties = FieldAccessorUtils.getPropertiesWithAnnotation( tableObj.getClass(), work.getAnnoReader(), XlsVerticalRecords.class) .stream() .filter(p -> p.isWritable()) .collect(Collectors.toList()); final List<FieldAccessorProxy> accessorProxies = new ArrayList<>(); for(FieldAccessor property : properties) { final XlsVerticalRecords anno = property.getAnnotationNullable(XlsVerticalRecords.class); // 処理対象と同じテーブルラベルのとき、マッピングを実行する。 if(iterateTablesAnno.tableLabel().equals(anno.tableLabel())) { final XlsVerticalRecords recordsAnno = new XlsVerticalRecordsForIterateTables(anno, headerColumn, headerRow); accessorProxies.add(new FieldAccessorProxy(recordsAnno, processor, property)); } } // 順番を並び替えて保存処理を実行する Collections.sort(accessorProxies, new FieldAccessorProxyComparator()); for(FieldAccessorProxy adaptorProxy : accessorProxies) { adaptorProxy.saveProcess(sheet, tableObj, config, work); } }
Example 16
Source File: ExcelExportOfTemplateUtil.java From easypoi with Apache License 2.0 | 4 votes |
/** * 获取迭代的数据的值 * @param cell * @param name * @return */ private List<ExcelTemplateParams> getAllDataColumns(Cell cell, String name) { List<ExcelTemplateParams> columns = new ArrayList<ExcelTemplateParams>(); cell.setCellValue(""); if (name.contains(END_STR)) { columns.add(new ExcelTemplateParams(name.replace(END_STR, EMPTY).trim(), cell .getCellStyle(), cell.getRow().getHeight())); return columns; } columns.add(new ExcelTemplateParams(name.trim(), cell.getCellStyle(), cell.getRow() .getHeight())); int index = cell.getColumnIndex(); Cell tempCell; while (true) { tempCell = cell.getRow().getCell(++index); if (tempCell == null) { break; } String cellStringString; try {//允许为空,单表示已经完结了,因为可能被删除了 cellStringString = tempCell.getStringCellValue(); if (StringUtils.isBlank(cellStringString)) { break; } } catch (Exception e) { throw new ExcelExportException("for each 当中存在空字符串,请检查模板"); } //把读取过的cell 置为空 tempCell.setCellValue(""); if (cellStringString.contains(END_STR)) { columns.add(new ExcelTemplateParams(cellStringString.trim().replace(END_STR, ""), tempCell.getCellStyle(), tempCell.getRow().getHeight())); break; } else { if (cellStringString.trim().contains(teplateParams.getTempParams())) { columns.add(new ExcelTemplateParams(cellStringString.trim(), tempCell .getCellStyle(), tempCell.getRow().getHeight())); } else { //最后一行被删除了 break; } } } return columns; }
Example 17
Source File: PageHandler.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * <p> * Process a CellImage from the images list and place the image on the sheet. * </p><p> * This involves changing the row height as necesssary and determining the column spread of the image. * </p> * @param cellImage * The image to be placed on the sheet. */ private void processCellImage( HandlerState state, Drawing drawing, CellImage cellImage ) { Coordinate location = cellImage.location; Cell cell = state.currentSheet.getRow( location.getRow() ).getCell( location.getCol() ); IImageContent image = cellImage.image; StyleManagerUtils smu = state.getSmu(); float ptHeight = cell.getRow().getHeightInPoints(); if( image.getHeight() != null ) { ptHeight = smu.fontSizeInPoints( image.getHeight().toString() ); } // Get image width int endCol = cell.getColumnIndex(); double lastColWidth = ClientAnchorConversions.widthUnits2Millimetres( (short)state.currentSheet.getColumnWidth( endCol ) ) + 2.0; int dx = smu.anchorDxFromMM( lastColWidth, lastColWidth ); double mmWidth = 0.0; if( smu.isAbsolute(image.getWidth())) { mmWidth = image.getWidth().convertTo(DimensionType.UNITS_MM); } else if(smu.isPixels(image.getWidth())) { mmWidth = ClientAnchorConversions.pixels2Millimetres( image.getWidth().getMeasure() ); } // Allow image to span multiple columns CellRangeAddress mergedRegion = getMergedRegionBegunBy( state.currentSheet, location.getRow(), location.getCol() ); if( (cellImage.spanColumns) || ( mergedRegion != null ) ) { log.debug( "Image size: ", image.getWidth(), " translates as mmWidth = ", mmWidth ); if( mmWidth > 0) { double mmAccumulatedWidth = 0; int endColLimit = cellImage.spanColumns ? 256 : mergedRegion.getLastColumn(); for( endCol = cell.getColumnIndex(); mmAccumulatedWidth < mmWidth && endCol < endColLimit; ++ endCol ) { lastColWidth = ClientAnchorConversions.widthUnits2Millimetres( (short)state.currentSheet.getColumnWidth( endCol ) ) + 2.0; mmAccumulatedWidth += lastColWidth; log.debug( "lastColWidth = ", lastColWidth, "; mmAccumulatedWidth = ", mmAccumulatedWidth); } if( mmAccumulatedWidth > mmWidth ) { mmAccumulatedWidth -= lastColWidth; --endCol; double mmShort = mmWidth - mmAccumulatedWidth; dx = smu.anchorDxFromMM( mmShort, lastColWidth ); } } } else { float widthRatio = (float)(mmWidth / lastColWidth); ptHeight = ptHeight / widthRatio; } int rowsSpanned = state.findRowsSpanned( cell.getRowIndex(), cell.getColumnIndex() ); float neededRowHeightPoints = ptHeight; for( int i = 0; i < rowsSpanned; ++i ) { int rowIndex = cell.getRowIndex() + 1 + i; neededRowHeightPoints -= state.currentSheet.getRow(rowIndex).getHeightInPoints(); } if( neededRowHeightPoints > cell.getRow().getHeightInPoints()) { cell.getRow().setHeightInPoints( neededRowHeightPoints ); } // ClientAnchor anchor = wb.getCreationHelper().createClientAnchor(); ClientAnchor anchor = state.getWb().getCreationHelper().createClientAnchor(); anchor.setCol1(cell.getColumnIndex()); anchor.setRow1(cell.getRowIndex()); anchor.setCol2(endCol); anchor.setRow2(cell.getRowIndex() + rowsSpanned); anchor.setDx2(dx); anchor.setDy2( smu.anchorDyFromPoints( ptHeight, cell.getRow().getHeightInPoints() ) ); anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE); drawing.createPicture(anchor, cellImage.imageIdx); }
Example 18
Source File: HorizontalRecordsProcessor.java From xlsmapper with Apache License 2.0 | 4 votes |
/** * 上部のセルと同じ値の場合マージする * @param currentCell * @param sheet * @param mergedRanges * @param config * @return */ private boolean processSavingMergedCell(final Cell currentCell, final Sheet sheet, final List<CellRangeAddress> mergedRanges, final Configuration config) { final int row = currentCell.getRowIndex(); final int column = currentCell.getColumnIndex(); if(row <= 0) { return false; } // 上のセルと比較する final String value = POIUtils.getCellContents(currentCell, config.getCellFormatter()); String upperValue = POIUtils.getCellContents(POIUtils.getCell(sheet, column, row-1), config.getCellFormatter()); // 結合されている場合、結合の先頭セルを取得する int startRow = row - 1; CellRangeAddress currentMergedRange = null; for(CellRangeAddress range : mergedRanges) { // 列が範囲外の場合 if((range.getFirstColumn() > column) || (column > range.getLastColumn())) { continue; } // 行が範囲外の場合 if((range.getFirstRow() > startRow) || (startRow > range.getLastRow())) { continue; } upperValue = POIUtils.getCellContents(POIUtils.getCell(sheet, column, range.getFirstRow()), config.getCellFormatter()); currentMergedRange = range; break; } if(!value.equals(upperValue)) { // 値が異なる場合は結合しない return false; } // 既に結合済みの場合は一端解除する if(currentMergedRange != null) { startRow = currentMergedRange.getFirstRow(); mergedRanges.remove(currentMergedRange); POIUtils.removeMergedRange(sheet, currentMergedRange); } final CellRangeAddress newRange = POIUtils.mergeCells(sheet, column, startRow, column, row); mergedRanges.add(newRange); return true; }
Example 19
Source File: HorizontalRecordsProcessor.java From xlsmapper with Apache License 2.0 | 4 votes |
/** * 表の開始位置(見出し)の位置情報を取得する。 * * @param sheet * @param anno * @param accessor * @param config * @return 表の開始位置。指定したラベルが見つからない場合、設定によりnullを返す。 * @throws AnnotationInvalidException アノテーションの値が不正で、表の開始位置が位置が見つからない場合。 * @throws CellNotFoundException 指定したラベルが見つからない場合。 */ private Optional<CellPosition> getHeaderPosition(final Sheet sheet, final XlsHorizontalRecords anno, final FieldAccessor accessor, final Configuration config) throws AnnotationInvalidException, CellNotFoundException { if(Utils.isNotEmpty(anno.headerAddress())) { try { return Optional.of(CellPosition.of(anno.headerAddress())); } catch(IllegalArgumentException e) { throw new AnnotationInvalidException(anno, MessageBuilder.create("anno.attr.invalidAddress") .var("property", accessor.getNameWithClass()) .varWithAnno("anno", XlsHorizontalRecords.class) .var("attrName", "headerAddress") .var("attrValue", anno.headerAddress()) .format()); } } else if(Utils.isNotEmpty(anno.tableLabel())) { try { final Cell labelCell = CellFinder.query(sheet, anno.tableLabel(), config).findWhenNotFoundException(); int initColumn = labelCell.getColumnIndex(); int initRow = labelCell.getRowIndex() + anno.bottom(); return Optional.of(CellPosition.of(initRow, initColumn)); } catch(CellNotFoundException ex) { if(anno.optional()) { return Optional.empty(); } else { throw ex; } } } else { // column, rowのアドレスを直接指定の場合 if(anno.headerRow() < 0) { throw new AnnotationInvalidException(anno, MessageBuilder.create("anno.attr.min") .var("property", accessor.getNameWithClass()) .varWithAnno("anno", XlsHorizontalRecords.class) .var("attrName", "headerRow") .var("attrValue", anno.headerRow()) .var("min", 0) .format()); } if(anno.headerColumn() < 0) { throw new AnnotationInvalidException(anno, MessageBuilder.create("anno.attr.min") .var("property", accessor.getNameWithClass()) .varWithAnno("anno", XlsHorizontalRecords.class) .var("attrName", "column") .var("attrValue", anno.headerColumn()) .var("min", 0) .format()); } return Optional.of(CellPosition.of(anno.headerRow(), anno.headerColumn())); } }
Example 20
Source File: CellAddress.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Create a new CellAddress object. * * @param cell the Cell to get the location of */ public CellAddress(Cell cell) { this(cell.getRowIndex(), cell.getColumnIndex()); }