return getStringCellValue(); default: return "Unknown Cell Type: " + getCellType();
newCell.setCellValue(oldCell.getStringCellValue()); break; case Cell.CELL_TYPE_BOOLEAN:
public boolean isThereAnyCellWithString(String str){ //Iterate over cells1 and compare //Use contains here if you want to or equals to find exact match for(HSSFCell cell : cells1){ if(cell.getStringCellValue().contains(str)) return true; } return false; }
public Void run() { builder.append(cell.getStringCellValue().toString()).append(" "); return null; } });
int i=1; do{ { HSSFRow row1 = worksheet.getRow(i); HSSFCell cellA1 = row1.getCell((short) 0); String a1Val = cellA1.getStringCellValue().toString(); System.out.println(a1Val); i++; // And if you want to enter this value in sql database , write a odbc connection and insert query to sql database. } }while(a1val.!equals("");
for(int count = 0;count<=sheet.getLastRowNum();count++){ HSSFRow row = sheet.getRow(4); HSSFCell cell = row.getCell(4); System.out.println("Running test case " + cell.getStringCellValue().equalsIgnoreCase("uk"));
private String getValueFromColumn(HSSFRow row, int i) { try { return new Integer(new Double(row.getCell((short) i).getNumericCellValue()).intValue()).toString(); } catch (NumberFormatException e) { return row.getCell((short) i).getStringCellValue(); } catch (IllegalStateException e) { return row.getCell((short) i).getStringCellValue(); } }
private String getValueFromColumn(HSSFRow row, int i) { try { return new Integer(new Double(row.getCell((short) i).getNumericCellValue()).intValue()).toString(); } catch (NumberFormatException e) { return row.getCell((short) i).getStringCellValue(); } catch (IllegalStateException e) { return row.getCell((short) i).getStringCellValue(); } }
public static boolean isBlankRow(HSSFRow row, int index, int rowCount){ if(row == null) return true; for(int i=index; i < rowCount; i++){ if(row.getCell(i) != null && !"".equals(row.getCell(i).getStringCellValue().trim())){ return false; } } return true; }
InputStream myxls = new FileInputStream("workbook.xls"); wb = new HSSFWorkbook(myxls); sheet = wb.getSheetAt(0); // first sheet row = sheet.getRow(0); // third row HSSFCell cell = (HSSFCell) row.getCell((short)1); // fourth cell if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { System.out.println("The Cell was a String with value \" " + cell.getStringCellValue()+" \" "); } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { System.out.println("The cell was a number " + cell.getNumericCellValue()); } else { System.out.println("The cell was nothing we're interested in"); }
@Override protected void readHeader(HSSFRow row) { for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) { HSSFCell cell = row.getCell(i); String id = cell != null ? cell.getStringCellValue() : "Column " + (i + 1); artifactColumnMap.put(i, id); } }
@Override protected void readLicenseMetaDataHeader(HSSFRow row) { for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) { HSSFCell cell = row.getCell(i); if (cell != null) { columnMap.put(i, cell.getStringCellValue()); } } }
public static double getCellValue(HSSFCell cell){ switch (cell.getCachedFormulaResultType()){ case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue(); break; case Cell.CELL_TYPE_STRING: return Double.parse(cell.getStringCellValue()); break; default: throw new RuntimeException("Data type not applicable"); } }
public extractDataFromXls(String fileName, sheetName) throws FileNotFoundException { FileInputStream fileInputStream = new FileInputStream(fileName); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet worksheet = workbook.getSheet(sheetName); HSSFRow row = worksheet.getRow(0); for (short i = 0; i < 5; i++) { HSSFCell cell = row.getCell(i); String value = cell.getStringCellValue(); System.out.println(value); } }
private String getDateFromColumn(HSSFRow row, int i) { try { return new SimpleDateFormat("dd-MM-yy").format(row.getCell((short) i).getDateCellValue()); } catch (Exception e) { return row.getCell((short) i).getStringCellValue(); } }
Map<String, Integer> map = new HashMap<String,Integer>(); //Create map HSSFRow row = sheet.getRow(0); //Get first row //following is boilerplate from the java doc short minColIx = row.getFirstCellNum(); //get the first column index for a row short maxColIx = row.getLastCellNum(); //get the last column index for a row for(short colIx=minColIx; colIx<maxColIx; colIx++) { //loop from first to last index HSSFCell cell = row.getCell(colIx); //get the cell map.put(cell.getStringCellValue(),cell.getColumnIndex()) //add the cell contents (name of column) and cell index to the map }
private Object getCellValue(HSSFCell cell) { if (cell == null) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { switch (cell.getCachedFormulaResultType()) { case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue(); case Cell.CELL_TYPE_STRING: return cell.getStringCellValue().replaceAll("'", ""); } } return null; }
public String peekValueAt(int row, int col) { if (currentWorksheet != null){ if ( row >= 0 && row < currentWorksheet.getLastRowNum() ) { HSSFRow hssfRow = currentWorksheet.getRow(row); if (hssfRow != null && col >= 0 && col < hssfRow.getLastCellNum()){ return hssfRow.getCell(col).getStringCellValue(); } } } return null; }
String getCell(HSSFSheet sheet, int row, int col) { try { return sheet.getRow(row).getCell((short) col).getStringCellValue(); } catch (NullPointerException e) { return null; } }
private static void addLang2Tilte(HSSFWorkbook wb, HSSFSheet sheet, String lang) { HSSFRow titleRow = sheet.getRow(0); HSSFCell lastCell = titleRow.getCell((int)titleRow.getLastCellNum() - 1); if (lang.equals(lastCell.getStringCellValue())) { // language column already exists return; } HSSFCell cell = titleRow.createCell((int)titleRow.getLastCellNum()); cell.setCellStyle(createTilteStyle(wb)); cell.setCellValue(lang); sheet.setColumnWidth(cell.getColumnIndex(), (60 * 256)); }