diff --git a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelBase.java b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelBase.java index b0ba5c559..427ff1122 100644 --- a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelBase.java +++ b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelBase.java @@ -318,11 +318,7 @@ public class ExcelBase, C extends ExcelConfig> impleme * @since 4.0.6 */ public Cell getCell(final int x, final int y, final boolean isCreateIfNotExist) { - final Row row = isCreateIfNotExist ? RowUtil.getOrCreateRow(this.sheet, y) : this.sheet.getRow(y); - if (null != row) { - return isCreateIfNotExist ? CellUtil.getOrCreateCell(row, x) : row.getCell(x); - } - return null; + return CellUtil.getCell(this.sheet, x, y, isCreateIfNotExist); } diff --git a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/cell/CellUtil.java b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/cell/CellUtil.java index 5ae4a2e2d..aebb6a086 100644 --- a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/cell/CellUtil.java +++ b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/cell/CellUtil.java @@ -22,6 +22,7 @@ import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.RegionUtil; import org.apache.poi.ss.util.SheetUtil; import org.dromara.hutool.core.util.ObjUtil; +import org.dromara.hutool.poi.excel.RowUtil; import org.dromara.hutool.poi.excel.cell.editors.CellEditor; import org.dromara.hutool.poi.excel.cell.editors.TrimEditor; import org.dromara.hutool.poi.excel.cell.setters.CellSetter; @@ -190,6 +191,24 @@ public class CellUtil { // endregion // region ----- getCell + /** + * 获取指定坐标单元格,如果isCreateIfNotExist为false,则在单元格不存在时返回{@code null} + * + * @param sheet {@link Sheet} + * @param x X坐标,从0计数,即列号 + * @param y Y坐标,从0计数,即行号 + * @param isCreateIfNotExist 单元格不存在时是否创建 + * @return {@link Cell} + * @since 6.0.0 + */ + public static Cell getCell(final Sheet sheet, final int x, final int y, final boolean isCreateIfNotExist) { + final Row row = isCreateIfNotExist ? RowUtil.getOrCreateRow(sheet, y) : sheet.getRow(y); + if (null != row) { + return isCreateIfNotExist ? getOrCreateCell(row, x) : row.getCell(x); + } + return null; + } + /** * 获取单元格,如果单元格不存在,返回{@link NullCell} * diff --git a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/writer/ExcelWriter.java b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/writer/ExcelWriter.java index 0f29c1839..c37c342e2 100644 --- a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/writer/ExcelWriter.java +++ b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/writer/ExcelWriter.java @@ -1011,6 +1011,17 @@ public class ExcelWriter extends ExcelBase { // region ----- fill public ExcelWriter fillRow(final Map rowMap){ + rowMap.forEach((key, value)->{ + + }); + return this; + } + + public ExcelWriter fillCell(final String name, final Object value){ + final Cell cell = this.templateContext.getCell(name); + if(null != cell){ + CellUtil.setCellValue(cell, value, this.config.getCellEditor()); + } return this; }