diff --git a/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java b/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java index 23779d3059..e15b4ec0be 100644 --- a/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java +++ b/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java @@ -185,15 +185,10 @@ public class XLSX2CSV { // with a special style or format int styleIndex = Integer.parseInt(cellStyleStr); XSSFCellStyle style = stylesTable.getStyleAt(styleIndex); - if (style == null && stylesTable.getNumCellStyles() > 0) { - style = stylesTable.getStyleAt(0); - } - if (style != null) { - this.formatIndex = style.getDataFormat(); - this.formatString = style.getDataFormatString(); - if (this.formatString == null) { - this.formatString = BuiltinFormats.getBuiltinFormat(this.formatIndex); - } + this.formatIndex = style.getDataFormat(); + this.formatString = style.getDataFormatString(); + if (this.formatString == null) { + this.formatString = BuiltinFormats.getBuiltinFormat(this.formatIndex); } } } diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index 3c8e5b7ce8..eeed53e4c3 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -447,12 +447,12 @@ public class Section public String getPIDString(final long pid) { String s = null; - if (dictionary != null) + if (dictionary != null) { s = dictionary.get(Long.valueOf(pid)); - if (s == null) + } + if (s == null) { s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid); - if (s == null) - s = SectionIDMap.UNDEFINED; + } return s; } diff --git a/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java b/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java index 42571f1c2b..b270182a0f 100644 --- a/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java +++ b/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java @@ -358,18 +358,11 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p } break; case HSSFCell.CELL_TYPE_NUMERIC: - HSSFCellStyle style = cell.getCellStyle(); - if(style == null) { - text.append( cell.getNumericCellValue() ); - } else { - text.append( - _formatter.formatRawCellContents( - cell.getNumericCellValue(), - style.getDataFormat(), - style.getDataFormatString() - ) - ); - } + HSSFCellStyle style = cell.getCellStyle(); + double nVal = cell.getNumericCellValue(); + short df = style.getDataFormat(); + String dfs = style.getDataFormatString(); + text.append(_formatter.formatRawCellContents(nVal, df, dfs)); break; case HSSFCell.CELL_TYPE_BOOLEAN: text.append(cell.getBooleanCellValue()); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java index c38d027ba2..5cb8d6f333 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java @@ -107,9 +107,6 @@ public final class XSLFPictureData extends POIXMLDocumentPart implements Picture */ public String getFileName() { String name = getPackagePart().getPartName().getName(); - if (name == null) { - return null; - } return name.substring(name.lastIndexOf('/') + 1); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 06dec8da55..ba819ce634 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -259,8 +259,7 @@ public final class XSSFCell implements Cell { */ @Override public String getStringCellValue() { - XSSFRichTextString str = getRichStringCellValue(); - return str == null ? null : str.getString(); + return getRichStringCellValue().getString(); } /** diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java index 0085fddb64..549ae813de 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java @@ -112,9 +112,6 @@ public class XWPFPictureData extends POIXMLDocumentPart { */ public String getFileName() { String name = getPackagePart().getPartName().getName(); - if (name == null) { - return null; - } return name.substring(name.lastIndexOf('/') + 1); } diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelConverter.java index fc1302f0aa..fd4c3dc03d 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelConverter.java @@ -139,14 +139,10 @@ public abstract class AbstractExcelConverter break; case HSSFCell.CELL_TYPE_NUMERIC: HSSFCellStyle style = cell.getCellStyle(); - if ( style == null ) - { - return false; - } - - value = ( _formatter.formatRawCellContents( - cell.getNumericCellValue(), style.getDataFormat(), - style.getDataFormatString() ) ); + double nval = cell.getNumericCellValue(); + short df = style.getDataFormat(); + String dfs = style.getDataFormatString(); + value = _formatter.formatRawCellContents(nval, df, dfs); break; case HSSFCell.CELL_TYPE_BOOLEAN: value = String.valueOf( cell.getBooleanCellValue() ); diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java index 3cce5eebc1..f5ba5f1ea0 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java @@ -228,13 +228,9 @@ public class ExcelToFoConverter extends AbstractExcelConverter break; case HSSFCell.CELL_TYPE_NUMERIC: double nValue = cell.getNumericCellValue(); - if ( cellStyle == null ) { - value = Double.toString( nValue ); - } else { - short df = cellStyle.getDataFormat(); - String dfs = cellStyle.getDataFormatString(); - value = _formatter.formatRawCellContents(nValue, df, dfs ); - } + short df = cellStyle.getDataFormat(); + String dfs = cellStyle.getDataFormatString(); + value = _formatter.formatRawCellContents(nValue, df, dfs ); break; case HSSFCell.CELL_TYPE_BOOLEAN: value = Boolean.toString( cell.getBooleanCellValue() ); @@ -270,7 +266,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter } final boolean noText = ExcelToHtmlUtils.isEmpty( value ); - final boolean wrapInDivs = !noText && (cellStyle == null || !cellStyle.getWrapText()); + final boolean wrapInDivs = !noText && !cellStyle.getWrapText(); final boolean emptyStyle = isEmptyStyle( cellStyle ); if ( !emptyStyle && noText ) { diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java index 1805b15665..b16a961fbf 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java @@ -313,13 +313,9 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter break; case HSSFCell.CELL_TYPE_NUMERIC: double nValue = cell.getNumericCellValue(); - if ( cellStyle == null ) { - value = Double.toString(nValue); - } else { - short df = cellStyle.getDataFormat(); - String dfs = cellStyle.getDataFormatString(); - value = _formatter.formatRawCellContents(nValue, df, dfs); - } + short df = cellStyle.getDataFormat(); + String dfs = cellStyle.getDataFormatString(); + value = _formatter.formatRawCellContents(nValue, df, dfs); break; case HSSFCell.CELL_TYPE_BOOLEAN: value = String.valueOf( cell.getBooleanCellValue() ); @@ -355,10 +351,9 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter } final boolean noText = ExcelToHtmlUtils.isEmpty( value ); - final boolean wrapInDivs = !noText && isUseDivsToSpan() - && (cellStyle == null || !cellStyle.getWrapText()); + final boolean wrapInDivs = !noText && isUseDivsToSpan() && !cellStyle.getWrapText(); - if ( cellStyle != null && cellStyle.getIndex() != 0 ) + if ( cellStyle.getIndex() != 0 ) { @SuppressWarnings("resource") HSSFWorkbook workbook = cell.getRow().getSheet().getWorkbook(); @@ -418,9 +413,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter innerDivStyle.append( "overflow:hidden;max-height:" ); innerDivStyle.append( normalHeightPt ); innerDivStyle.append( "pt;white-space:nowrap;" ); - if (cellStyle != null) { - ExcelToHtmlUtils.appendAlign( innerDivStyle, cellStyle.getAlignment() ); - } + ExcelToHtmlUtils.appendAlign( innerDivStyle, cellStyle.getAlignment() ); htmlDocumentFacade.addStyleClass( outerDiv, cssClassPrefixDiv, innerDivStyle.toString() ); @@ -433,7 +426,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter tableCellElement.appendChild( text ); } - return ExcelToHtmlUtils.isEmpty( value ) && (cellStyle == null || cellStyle.getIndex() == 0); + return ExcelToHtmlUtils.isEmpty( value ) && (cellStyle.getIndex() == 0); } protected void processColumnHeaders( HSSFSheet sheet, int maxSheetColumns,