I am currently reading values from an excel spreadsheet and assigning this value to a String variable.
Below is a sample of the code I am using:
Workbook workbook = new XSSFWorkbook(iStream);
Sheet firstSheet = workbook.getSheetAt(0);
Iterator<Row> iterator = firstSheet.iterator();
// Skips the header row
iterator.next();
// Iterate through the first sheet and get the cell values
while (iterator.hasNext()) {
Row nextRow = iterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
int columnIndex = cell.getColumnIndex();
switch (columnIndex) {
case 0:
String userName;
if (cell.getStringCellValue() == "") {
userName = "BlankCell";
} else {
userName = cell.getStringCellValue();
}
break;
}
I have multiple blank cells within this excel spreadsheet which I am trying to replace with the phrase "BlankCell".
I have used this piece of code successfully in the past but for some reason it does not work anymore.
Is my logic in this instance wrong for replacing blank cells?