List of usage examples for org.apache.poi.ss.usermodel Row getCell
Cell getCell(int cellnum);
From source file:b01.officeLink.excel.FocExcelSheet.java
License:Apache License
public void set(int coord0, int coord1, Double dVal) { Row row = sheet.getRow(coord0); Cell cell = null;/* w w w.j a va 2s . c om*/ if (row != null) { cell = row.getCell(coord1); if (cell == null) cell = row.createCell((short) coord1); } if (cell != null) { // cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(dVal); } }
From source file:b01.officeLink.excel.FocExcelSheet.java
License:Apache License
public void set(int coord0, int coord1, String sVal) { Row row = sheet.getRow(coord0); Cell cell = row != null ? row.getCell(coord1) : null; if (cell != null && sVal != null) { cell.setCellType(Cell.CELL_TYPE_STRING); if (sheet.getWorkbook() != null) { RichTextString textString = sheet.getWorkbook().getCreationHelper().createRichTextString(sVal); cell.setCellValue(textString); }//from w ww. java 2 s . com } }
From source file:b01.officeLink.excel.FocExcelSheet.java
License:Apache License
public double getCellNum(int coord0, int coord1) { Row row = sheet.getRow(coord0); Cell cell = row != null ? row.getCell(coord1) : null; double dVal = 0; if (cell != null && (cell.getCellType() == Cell.CELL_TYPE_NUMERIC || cell.getCellType() == Cell.CELL_TYPE_FORMULA)) { dVal = cell.getNumericCellValue(); }/*from w ww. jav a 2 s . c om*/ return dVal; }
From source file:b01.officeLink.excel.FocExcelSheet.java
License:Apache License
public Date getCellDate(int coord0, int coord1) { Row row = sheet.getRow(coord0); Cell cell = row != null ? row.getCell(coord1) : null; return cell != null ? cell.getDateCellValue() : null; }
From source file:b01.officeLink.excel.FocExcelSheet.java
License:Apache License
public String getCellString(int coord0, int coord1) { String str = null;/*from w ww . j a v a2 s. c om*/ try { Row row = sheet.getRow(coord0); Cell cell = row != null ? row.getCell(coord1) : null; if (cell != null) { int type = cell.getCellType(); if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { try { double dVal = cell.getNumericCellValue(); if (Double.isNaN(dVal)) { type = Cell.CELL_TYPE_STRING; } else { type = Cell.CELL_TYPE_NUMERIC; } } catch (Exception e) { Globals.logString("This EXCEPTION is Handles"); Globals.logExceptionWithoutPopup(e); } } if (type == Cell.CELL_TYPE_STRING) { str = cell.getRichStringCellValue().getString(); } else if (type == Cell.CELL_TYPE_NUMERIC) { // str = String.valueOf((int) cell.getNumericCellValue()); str = cell.getNumericCellValue() + ""; } } } catch (Exception e) { Globals.logException(e); Globals.logString("Could Not get Value for cell [" + coord0 + "," + coord1 + "]"); } return str; }
From source file:bad.robot.excel.matchers.CellInRowMatcher.java
License:Apache License
@Override protected boolean matchesSafely(Row row, Description mismatch) { Cell actual = adaptPoi(row.getCell(columnIndex)); if (!expected.equals(actual)) { mismatch.appendText("cell at ").appendValue(coordinate).appendText(" contained ").appendValue(actual) .appendText(" expected ").appendValue(expected); return false; }/*from w w w . j a v a 2 s .co m*/ return true; }
From source file:bad.robot.excel.row.CopyRow.java
License:Apache License
/** * Copies a row from a row index on the given workbook and sheet to another row index. If the destination row is * already occupied, shift all rows down to make room. * *//* w ww .j a va2s . c o m*/ public static void copyRow(Workbook workbook, Sheet worksheet, RowIndex from, RowIndex to) { Row sourceRow = worksheet.getRow(from.value()); Row newRow = worksheet.getRow(to.value()); if (alreadyExists(newRow)) worksheet.shiftRows(to.value(), worksheet.getLastRowNum(), 1); else newRow = worksheet.createRow(to.value()); for (int i = 0; i < sourceRow.getLastCellNum(); i++) { Cell oldCell = sourceRow.getCell(i); Cell newCell = newRow.createCell(i); if (oldCell != null) { copyCellStyle(workbook, oldCell, newCell); copyCellComment(oldCell, newCell); copyCellHyperlink(oldCell, newCell); copyCellDataTypeAndValue(oldCell, newCell); } } copyAnyMergedRegions(worksheet, sourceRow, newRow); }
From source file:bad.robot.excel.WorkbookResource.java
License:Apache License
public static org.apache.poi.ss.usermodel.Cell getCellForCoordinate(Coordinate coordinate, Workbook workbook) throws IOException { org.apache.poi.ss.usermodel.Row row = getRowForCoordinate(coordinate, workbook); return row.getCell(coordinate.getColumn().value()); }
From source file:be.fedict.dcat.scrapers.XlsPsiBelgium.java
License:Open Source License
@Override protected URL getId(Row row) throws MalformedURLException { String s = row.getCell(0).toString(); return makeDatasetURL(stringInt(s)); }
From source file:biz.webgate.dominoext.poi.component.kernel.WorkbookProcessor.java
License:Apache License
public void setCellValue(Sheet shProcess, int nRow, int nCol, Object objValue, boolean isFormula, PoiCellStyle pCellStyle) {//w ww. jav a 2 s. com // Logger logCurrent = // LoggerFactory.getLogger(WorkbookProcessor.class.getCanonicalName()); try { Row rw = shProcess.getRow(nRow); if (rw == null) { // logCurrent.finest("Create Row"); rw = shProcess.createRow(nRow); } Cell c = rw.getCell(nCol); if (c == null) { // logCurrent.finest("Create Cell"); c = rw.createCell(nCol); } if (isFormula) { c.setCellFormula((String) objValue); } else { if (objValue instanceof Double) { c.setCellValue((Double) objValue); } else if (objValue instanceof Integer) { c.setCellValue((Integer) objValue); } else { if (objValue instanceof Date) { c.setCellValue((Date) objValue); } else { c.setCellValue("" + objValue); } } } // *** STYLE CONFIG Since V 1.1.7 *** if (pCellStyle != null) { checkStyleConstantValues(); if (pCellStyle.getCellStyle() != null) { c.setCellStyle(pCellStyle.getCellStyle()); } else { CellStyle style = shProcess.getWorkbook().createCellStyle(); if (pCellStyle.getAlignment() != null) style.setAlignment(m_StyleConstantValues.get(pCellStyle.getAlignment())); if (pCellStyle.getBorderBottom() != null) style.setBorderBottom(m_StyleConstantValues.get(pCellStyle.getBorderBottom())); if (pCellStyle.getBorderLeft() != null) style.setBorderLeft(m_StyleConstantValues.get(pCellStyle.getBorderLeft())); if (pCellStyle.getBorderRight() != null) style.setBorderRight(m_StyleConstantValues.get(pCellStyle.getBorderRight())); if (pCellStyle.getBorderTop() != null) style.setBorderTop(m_StyleConstantValues.get(pCellStyle.getBorderTop())); if (pCellStyle.getBottomBorderColor() != null) style.setBottomBorderColor( IndexedColors.valueOf(pCellStyle.getBottomBorderColor()).getIndex()); if (pCellStyle.getDataFormat() != null) { DataFormat format = shProcess.getWorkbook().createDataFormat(); style.setDataFormat(format.getFormat(pCellStyle.getDataFormat())); } if (pCellStyle.getFillBackgroundColor() != null) style.setFillBackgroundColor( IndexedColors.valueOf(pCellStyle.getFillBackgroundColor()).getIndex()); if (pCellStyle.getFillForegroundColor() != null) style.setFillForegroundColor( IndexedColors.valueOf(pCellStyle.getFillForegroundColor()).getIndex()); if (pCellStyle.getFillPattern() != null) style.setFillPattern(m_StyleConstantValues.get(pCellStyle.getFillPattern())); // Create a new font and alter it. Font font = shProcess.getWorkbook().createFont(); if (pCellStyle.getFontBoldweight() != null) font.setBoldweight(m_StyleConstantValues.get(pCellStyle.getFontBoldweight())); if (pCellStyle.getFontColor() != null) font.setColor(IndexedColors.valueOf(pCellStyle.getFontColor()).getIndex()); if (pCellStyle.getFontHeightInPoints() != 0) font.setFontHeightInPoints(pCellStyle.getFontHeightInPoints()); if (pCellStyle.getFontName() != null) font.setFontName(pCellStyle.getFontName()); if (pCellStyle.isFontItalic()) font.setItalic(pCellStyle.isFontItalic()); if (pCellStyle.isFontStrikeout()) font.setStrikeout(pCellStyle.isFontStrikeout()); if (pCellStyle.getFontUnderline() != null) font.setUnderline(m_StyleByteConstantValues.get(pCellStyle.getFontUnderline())); if (pCellStyle.getFontTypeOffset() != null) font.setTypeOffset(m_StyleConstantValues.get(pCellStyle.getFontTypeOffset())); // Set Font style.setFont(font); if (pCellStyle.isHidden()) style.setHidden(pCellStyle.isHidden()); if (pCellStyle.getIndention() != null) style.setIndention(m_StyleConstantValues.get(pCellStyle.getIndention())); if (pCellStyle.getLeftBorderColor() != null) style.setLeftBorderColor(IndexedColors.valueOf(pCellStyle.getLeftBorderColor()).getIndex()); if (pCellStyle.isLocked()) style.setLocked(pCellStyle.isLocked()); if (pCellStyle.getRightBorderColor() != null) style.setRightBorderColor( IndexedColors.valueOf(pCellStyle.getRightBorderColor()).getIndex()); if (pCellStyle.getRotation() != 0) style.setRotation(pCellStyle.getRotation()); if (pCellStyle.getTopBorderColor() != null) style.setTopBorderColor(IndexedColors.valueOf(pCellStyle.getTopBorderColor()).getIndex()); if (pCellStyle.getVerticalAlignment() != null) style.setVerticalAlignment(m_StyleConstantValues.get(pCellStyle.getVerticalAlignment())); if (pCellStyle.isWrapText()) style.setWrapText(pCellStyle.isWrapText()); c.setCellStyle(style); pCellStyle.setCellStyle(style); } } } catch (Exception e) { e.printStackTrace(); } }