/** * 写一行数据 * @param row 行 * @param rowData 一行的数据 * @param styleSet 单元格样式集,包括日期等样式 * @param isHeader 是否为标题行 public static void writeRow(Row row, Iterable<?> rowData, StyleSet styleSet, boolean isHeader) { int i = 0; Cell cell; for (Object value : rowData) { cell = row.createCell(i); CellUtil.setCellValue(cell, value, styleSet, isHeader);
/** * 写一行数据 * @param row 行 * @param rowData 一行的数据 * @param styleSet 单元格样式集,包括日期等样式 * @param isHeader 是否为标题行 public static void writeRow(Row row, Iterable<?> rowData, StyleSet styleSet, boolean isHeader) { int i = 0; Cell cell; for (Object value : rowData) { cell = row.createCell(i); CellUtil.setCellValue(cell, value, styleSet, 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) {
final Cell cell = getOrCreateCell(x, y);
CellUtil.setCellValue(cell, value, this.styleSet, false);
return this;
/**
* 给指定单元格赋值,使用默认单元格样式
* @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) {
final Cell cell = getOrCreateCell(x, y);
CellUtil.setCellValue(cell, value, this.styleSet, false);
return this;
/**
* 合并某行的单元格,并写入对象到单元格<br>
* 如果写到单元格中的内容非null,行号自动+1,否则当前行号不变<br>
* 样式为默认标题样式,可使用{@link #getHeadCellStyle()}方法调用后自定义默认样式
* @param lastColumn 合并到的最后一个列号
* @param content 合并单元格后的内容
* @param isSetHeaderStyle 是否为合并后的单元格设置默认标题样式
* @return this
* @since 4.0.10
public ExcelWriter merge(int firstRow, int lastRow, int firstColumn, int lastColumn, Object content, boolean isSetHeaderStyle) {
Assert.isFalse(this.isClosed, "ExcelWriter has been closed!");
final CellStyle style = (isSetHeaderStyle && null != this.styleSet && null != this.styleSet.headCellStyle) ? this.styleSet.headCellStyle : this.styleSet.cellStyle;
CellUtil.mergingCells(this.sheet, firstRow, lastRow, firstColumn, lastColumn, style);
// 设置内容
if (null != content) {
final Cell cell = getOrCreateCell(firstColumn, firstRow);
CellUtil.setCellValue(cell, content, this.styleSet, isSetHeaderStyle);
return this;
/**
* 合并某行的单元格,并写入对象到单元格<br>
* 如果写到单元格中的内容非null,行号自动+1,否则当前行号不变<br>
* 样式为默认标题样式,可使用{@link #getHeadCellStyle()}方法调用后自定义默认样式
* @param lastColumn 合并到的最后一个列号
* @param content 合并单元格后的内容
* @param isSetHeaderStyle 是否为合并后的单元格设置默认标题样式
* @return this
* @since 4.0.10
public ExcelWriter merge(int firstRow, int lastRow, int firstColumn, int lastColumn, Object content, boolean isSetHeaderStyle) {
Assert.isFalse(this.isClosed, "ExcelWriter has been closed!");
final CellStyle style = (isSetHeaderStyle && null != this.styleSet && null != this.styleSet.headCellStyle) ? this.styleSet.headCellStyle : this.styleSet.cellStyle;
CellUtil.mergingCells(this.sheet, firstRow, lastRow, firstColumn, lastColumn, style);
// 设置内容
if (null != content) {
final Cell cell = getOrCreateCell(firstColumn, firstRow);
CellUtil.setCellValue(cell, content, this.styleSet, isSetHeaderStyle);
return this;
/** * 写一行数据 * @param row 行 * @param rowData 一行的数据 * @param styleSet 单元格样式集,包括日期等样式 * @param isHeader 是否为标题行 public static void writeRow(Row row, Iterable<?> rowData, StyleSet styleSet, boolean isHeader) { int i = 0; Cell cell; for (Object value : rowData) { cell = row.createCell(i); CellUtil.setCellValue(cell, value, styleSet, 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) {
final Cell cell = getOrCreateCell(x, y);
CellUtil.setCellValue(cell, value, this.styleSet, false);
return this;
/**
* 合并某行的单元格,并写入对象到单元格<br>
* 如果写到单元格中的内容非null,行号自动+1,否则当前行号不变<br>
* 样式为默认标题样式,可使用{@link #getHeadCellStyle()}方法调用后自定义默认样式
* @param lastColumn 合并到的最后一个列号
* @param content 合并单元格后的内容
* @param isSetHeaderStyle 是否为合并后的单元格设置默认标题样式
* @return this
* @since 4.0.10
public ExcelWriter merge(int firstRow, int lastRow, int firstColumn, int lastColumn, Object content, boolean isSetHeaderStyle) {
Assert.isFalse(this.isClosed, "ExcelWriter has been closed!");
final CellStyle style = (isSetHeaderStyle && null != this.styleSet && null != this.styleSet.headCellStyle) ? this.styleSet.headCellStyle : this.styleSet.cellStyle;
CellUtil.mergingCells(this.sheet, firstRow, lastRow, firstColumn, lastColumn, style);
// 设置内容
if (null != content) {
final Cell cell = getOrCreateCell(firstColumn, firstRow);
CellUtil.setCellValue(cell, content, this.styleSet, isSetHeaderStyle);
return this;