added getStringValue method

This commit is contained in:
2019-09-15 17:24:15 +02:00
parent 626ab1b528
commit ee1a20836d

View File

@ -144,6 +144,23 @@ public abstract class PoiUtil {
currentCell.setCellValue(date); currentCell.setCellValue(date);
} }
/**
* Returns the string value from the given cell. If the value is mandatory but the cell does not contain a value a {@link PoiException} is thrown.
*
* @param row the row to read the value from
* @param cellNumber the cellnumber (starting with 0) of the {@link Row} to read the content from.
* @param mandatory if set to true, a {@link PoiException} is thrown, if the specified cell, does not contain any value. Otherwise null is returned if the cell is empty.
* @return the String value of the specified cell.
* @throws PoiException if the cell value cannot be read or if the cell is empty and mandatory has been set to true.
*/
public static String getStringValue(Row row, int cellNumber, boolean mandatory) throws PoiException {
String returnValue = getStringValue(row, cellNumber, false, null);
if (returnValue == null) {
throw new PoiException("Value in row=" + row.getRowNum() + ", cell=" + cellNumber + " is mandatory but not available");
}
return returnValue;
}
public static String getStringValue(Row row, int cellNumber) throws PoiException { public static String getStringValue(Row row, int cellNumber) throws PoiException {
return getStringValue(row, cellNumber, false, null); return getStringValue(row, cellNumber, false, null);
} }
@ -239,8 +256,7 @@ public abstract class PoiUtil {
} }
/** /**
* remove charecters which often cause troubles in other applications - e.g. * remove charecters which often cause troubles in other applications - e.g. em dash (long dash) is created by Excel automatically
* em dash (long dash) is created by Excel automatically
* *
* @param sourceValue the input string to execute the replacement * @param sourceValue the input string to execute the replacement
* @return sourceValue with replaced characters * @return sourceValue with replaced characters