From c07a3d94bfb20863cce5bf0e36e7005d05826ffd Mon Sep 17 00:00:00 2001 From: hower Date: Fri, 26 May 2023 12:49:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0writeCellValue=E7=9A=84?= =?UTF-8?q?=E9=87=8D=E8=BD=BD=EF=BC=8C=E4=BB=A5=E6=94=AF=E6=8C=81isHeader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/poi/excel/ExcelWriter.java | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java index 9d052b9ba..770e259e2 100755 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java @@ -889,7 +889,7 @@ public class ExcelWriter extends ExcelBase { public ExcelWriter writeImg(File imgFile, int imgType, int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) { return writeImg(FileUtil.readBytes(imgFile), imgType, dx1, - dy1, dx2, dy2, col1, row1, col2, row2); + dy1, dx2, dy2, col1, row1, col2, row2); } /** @@ -1105,22 +1105,49 @@ public class ExcelWriter extends ExcelBase { * @since 5.1.4 */ public ExcelWriter writeCellValue(String locationRef, Object value) { - final CellLocation cellLocation = ExcelUtil.toLocation(locationRef); - return writeCellValue(cellLocation.getX(), cellLocation.getY(), value); + return writeCellValue(locationRef, value, false); } /** * 给指定单元格赋值,使用默认单元格样式 * - * @param x X坐标,从0计数,即列号 - * @param y Y坐标,从0计数,即行号 - * @param value 值 + * @param locationRef 单元格地址标识符,例如A11,B5 + * @param value 值 + * @param isHeader 是否为Header + * @return this + * @since 5.1.4 + */ + public ExcelWriter writeCellValue(String locationRef, Object value, boolean isHeader) { + final CellLocation cellLocation = ExcelUtil.toLocation(locationRef); + return writeCellValue(cellLocation.getX(), cellLocation.getY(), value, isHeader); + } + + /** + * 给指定单元格赋值,使用默认单元格样式 + * + * @param x X坐标,从0计数,即列号 + * @param y Y坐标,从0计数,即行号 + * @param value 值 * @return this * @since 4.0.2 */ public ExcelWriter writeCellValue(int x, int y, Object value) { + return writeCellValue(x, y, value, false); + } + + /** + * 给指定单元格赋值,使用默认单元格样式 + * + * @param x X坐标,从0计数,即列号 + * @param y Y坐标,从0计数,即行号 + * @param value 值 + * @param isHeader 是否为Header + * @return this + * @since 4.0.2 + */ + public ExcelWriter writeCellValue(int x, int y, Object value, boolean isHeader) { final Cell cell = getOrCreateCell(x, y); - CellUtil.setCellValue(cell, value, this.styleSet, false); + CellUtil.setCellValue(cell, value, this.styleSet, isHeader); return this; } From 4323a98969dfb558220d3cc68fe318ee4d51c992 Mon Sep 17 00:00:00 2001 From: hower Date: Fri, 26 May 2023 13:02:39 +0800 Subject: [PATCH 2/3] roll back code --- .../java/cn/hutool/poi/excel/ExcelWriter.java | 37 +++---------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java index 770e259e2..9677ccb38 100755 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java @@ -1105,49 +1105,22 @@ public class ExcelWriter extends ExcelBase { * @since 5.1.4 */ public ExcelWriter writeCellValue(String locationRef, Object value) { - return writeCellValue(locationRef, value, false); - } - - /** - * 给指定单元格赋值,使用默认单元格样式 - * - * @param locationRef 单元格地址标识符,例如A11,B5 - * @param value 值 - * @param isHeader 是否为Header - * @return this - * @since 5.1.4 - */ - public ExcelWriter writeCellValue(String locationRef, Object value, boolean isHeader) { final CellLocation cellLocation = ExcelUtil.toLocation(locationRef); - return writeCellValue(cellLocation.getX(), cellLocation.getY(), value, isHeader); + return writeCellValue(cellLocation.getX(), cellLocation.getY(), value); } /** * 给指定单元格赋值,使用默认单元格样式 * - * @param x X坐标,从0计数,即列号 - * @param y Y坐标,从0计数,即行号 - * @param value 值 + * @param x X坐标,从0计数,即列号 + * @param y Y坐标,从0计数,即行号 + * @param value 值 * @return this * @since 4.0.2 */ public ExcelWriter writeCellValue(int x, int y, Object value) { - return writeCellValue(x, y, value, false); - } - - /** - * 给指定单元格赋值,使用默认单元格样式 - * - * @param x X坐标,从0计数,即列号 - * @param y Y坐标,从0计数,即行号 - * @param value 值 - * @param isHeader 是否为Header - * @return this - * @since 4.0.2 - */ - public ExcelWriter writeCellValue(int x, int y, Object value, boolean isHeader) { final Cell cell = getOrCreateCell(x, y); - CellUtil.setCellValue(cell, value, this.styleSet, isHeader); + CellUtil.setCellValue(cell, value, this.styleSet, false); return this; } From 64f575fe74c97f4dae4d0133f64aa9aa8b4ad729 Mon Sep 17 00:00:00 2001 From: hower Date: Fri, 26 May 2023 13:08:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0writeCellValue=E7=9A=84?= =?UTF-8?q?=E9=87=8D=E8=BD=BD=EF=BC=8C=E4=BB=A5=E6=94=AF=E6=8C=81isHeader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/poi/excel/ExcelWriter.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java index 9677ccb38..e52d87a5f 100755 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java @@ -1097,7 +1097,7 @@ public class ExcelWriter extends ExcelBase { } /** - * 给指定单元格赋值,使用默认单元格样式 + * 给指定单元格赋值,使用默认单元格样式,默认不是Header * * @param locationRef 单元格地址标识符,例如A11,B5 * @param value 值 @@ -1105,13 +1105,26 @@ public class ExcelWriter extends ExcelBase { * @since 5.1.4 */ public ExcelWriter writeCellValue(String locationRef, Object value) { - final CellLocation cellLocation = ExcelUtil.toLocation(locationRef); - return writeCellValue(cellLocation.getX(), cellLocation.getY(), value); + return writeCellValue(locationRef, value, false); } /** * 给指定单元格赋值,使用默认单元格样式 * + * @param locationRef 单元格地址标识符,例如A11,B5 + * @param value 值 + * @param isHeader 是否为Header + * @return this + * @since 5.1.4 + */ + public ExcelWriter writeCellValue(String locationRef, Object value, boolean isHeader) { + final CellLocation cellLocation = ExcelUtil.toLocation(locationRef); + return writeCellValue(cellLocation.getX(), cellLocation.getY(), value, isHeader); + } + + /** + * 给指定单元格赋值,使用默认单元格样式,默认不是Header + * * @param x X坐标,从0计数,即列号 * @param y Y坐标,从0计数,即行号 * @param value 值 @@ -1119,8 +1132,22 @@ public class ExcelWriter extends ExcelBase { * @since 4.0.2 */ public ExcelWriter writeCellValue(int x, int y, Object value) { + return writeCellValue(x, y, value, false); + } + + /** + * 给指定单元格赋值,使用默认单元格样式 + * + * @param x X坐标,从0计数,即列号 + * @param y Y坐标,从0计数,即行号 + * @param isHeader 是否为Header + * @param value 值 + * @return this + * @since 4.0.2 + */ + public ExcelWriter writeCellValue(int x, int y, Object value, boolean isHeader) { final Cell cell = getOrCreateCell(x, y); - CellUtil.setCellValue(cell, value, this.styleSet, false); + CellUtil.setCellValue(cell, value, this.styleSet, isHeader); return this; }