From fa95a3e522660975fcd9d23322fdacacc4f526c2 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Wed, 19 Nov 2025 14:20:56 +0100 Subject: [PATCH] reduce use of setCellType (#943) --- .../main/java/org/apache/poi/xssf/streaming/SXSSFRow.java | 4 ++-- .../main/java/org/apache/poi/xssf/usermodel/XSSFRow.java | 2 +- .../xssf/usermodel/TestXSSFSheetShiftRowsAndColumns.java | 1 - .../main/java/org/apache/poi/hssf/usermodel/HSSFRow.java | 6 +++--- poi/src/main/java/org/apache/poi/ss/usermodel/Row.java | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java index 0e9a2db55f..91a579032b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java @@ -111,7 +111,7 @@ public class SXSSFRow implements Row, Comparable * Use this to create new cells within the row and return it. *

* The cell that is returned is a {@link CellType#BLANK}. The type can be changed - * either through calling {@code setCellValue} or {@code setCellType}. + * either through calling {@code setCellValue} or {@code setCellFormula}. * * @param column - the column number this cell represents (zero-based) * @return Cell a high level representation of the created cell. @@ -128,7 +128,7 @@ public class SXSSFRow implements Row, Comparable * Use this to create new cells within the row and return it. *

* The cell that is returned is a {@link CellType#BLANK}. The type can be changed - * either through calling setCellValue or setCellType. + * either through calling setCellValue or setCellFormula. * * @param column - the column number this cell represents (zero-based) * @return Cell a high level representation of the created cell. diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRow.java index 5e6bd25c46..0c1b6db499 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRow.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFRow.java @@ -187,7 +187,7 @@ public class XSSFRow implements Row, Comparable { * Use this to create new cells within the row and return it. *

* The cell that is returned is a {@link CellType#BLANK}. The type can be changed - * either through calling {@code setCellValue} or {@code setCellType}. + * either through calling {@code setCellValue} or {@code setCellFormula}. *

* @param columnIndex - the column number this cell represents * @return Cell a high level representation of the created cell. diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRowsAndColumns.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRowsAndColumns.java index e31332027a..8d09b8a90a 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRowsAndColumns.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRowsAndColumns.java @@ -71,7 +71,6 @@ class TestXSSFSheetShiftRowsAndColumns { final XSSFRow row = sheet.createRow(nRow); for (int nCol = 0; nCol < numCols; ++nCol) { final XSSFCell cell = row.createCell(nCol); - cell.setCellType(CellType.STRING); cell.setCellValue(String.format(Locale.US, "Row %d col %d", nRow, nCol)); } } diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFRow.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFRow.java index c0b7188409..ad1ba4fe2d 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFRow.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFRow.java @@ -114,7 +114,7 @@ public final class HSSFRow implements Row, Comparable { * Use this to create new cells within the row and return it. *

* The cell that is returned is a {@link CellType#BLANK}. The type can be changed - * either through calling setCellValue or setCellType. + * either through calling setCellValue or setCellFormula. * * @param column - the column number this cell represents * @@ -125,7 +125,7 @@ public final class HSSFRow implements Row, Comparable { @Override public HSSFCell createCell(int column) { - return this.createCell(column,CellType.BLANK); + return this.createCell(column, CellType.BLANK); } /** @@ -133,7 +133,7 @@ public final class HSSFRow implements Row, Comparable { *

* The cell that is returned will be of the requested type. * The type can be changed either through calling setCellValue - * or setCellType, but there is a small overhead to doing this, + * or setCellFormula, but there is a small overhead to doing this, * so it is best to create the required type up front. * * @param columnIndex - the column number this cell represents diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/Row.java b/poi/src/main/java/org/apache/poi/ss/usermodel/Row.java index 2ddb957274..14303dc06f 100644 --- a/poi/src/main/java/org/apache/poi/ss/usermodel/Row.java +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/Row.java @@ -30,7 +30,7 @@ public interface Row extends Iterable { * Use this to create new cells within the row and return it. *

* The cell that is returned is a {@link CellType#BLANK}. The type can be changed - * either through calling setCellValue or setCellType. + * either through calling setCellValue or setCellFormula. * * @param column - the column number this cell represents * @return Cell a high level representation of the created cell. @@ -44,7 +44,7 @@ public interface Row extends Iterable { *

* The cell that is returned will be of the requested type. * The type can be changed either through calling setCellValue - * or setCellType, but there is a small overhead to doing this, + * or setCellFormula, but there is a small overhead to doing this, * so it is best to create of the required type up front. * * @param column - the column number this cell represents