Class ExcelWriter

java.lang.Object
org.aoju.bus.office.excel.ExcelBase<ExcelWriter>
org.aoju.bus.office.excel.ExcelWriter
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
BigExcelWriter

public class ExcelWriter extends ExcelBase<ExcelWriter>
Excel 写入器 此工具用于通过POI将数据写出到Excel,此对象可完成以下两个功能
 1. 编辑已存在的Excel,可写出原Excel文件,也可写出到其它地方(到文件或到流)
 2. 新建一个空的Excel工作簿,完成数据填充后写出(到文件或到流)
 
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ExcelWriter

      public ExcelWriter()
      构造,默认生成xls格式的Excel文件 此构造不传入写出的Excel文件路径,只能调用flush(OutputStream)方法写出到流 若写出到文件,还需调用setDestFile(File)方法自定义写出的文件,然后调用flush()方法写出到文件
    • ExcelWriter

      public ExcelWriter(boolean isXlsx)
      构造 此构造不传入写出的Excel文件路径,只能调用flush(OutputStream)方法写出到流 若写出到文件,需要调用flush(File) 写出到文件
      Parameters:
      isXlsx - 是否为xlsx格式
    • ExcelWriter

      public ExcelWriter(String destFilePath)
      构造,默认写出到第一个sheet,第一个sheet名为sheet1
      Parameters:
      destFilePath - 目标文件路径,可以不存在
    • ExcelWriter

      public ExcelWriter(boolean isXlsx, String sheetName)
      构造 此构造不传入写出的Excel文件路径,只能调用flush(OutputStream)方法写出到流 若写出到文件,需要调用flush(File) 写出到文件
      Parameters:
      isXlsx - 是否为xlsx格式
      sheetName - sheet名,第一个sheet名并写出到此sheet,例如sheet1
    • ExcelWriter

      public ExcelWriter(String destFilePath, String sheetName)
      构造
      Parameters:
      destFilePath - 目标文件路径,可以不存在
      sheetName - sheet名,第一个sheet名并写出到此sheet,例如sheet1
    • ExcelWriter

      public ExcelWriter(File destFile)
      构造,默认写出到第一个sheet,第一个sheet名为sheet1
      Parameters:
      destFile - 目标文件,可以不存在
    • ExcelWriter

      public ExcelWriter(File destFile, String sheetName)
      构造
      Parameters:
      destFile - 目标文件,可以不存在
      sheetName - sheet名,做为第一个sheet名并写出到此sheet,例如sheet1
    • ExcelWriter

      public ExcelWriter(org.apache.poi.ss.usermodel.Workbook workbook, String sheetName)
      构造 此构造不传入写出的Excel文件路径,只能调用flush(OutputStream)方法写出到流 若写出到文件,还需调用setDestFile(File)方法自定义写出的文件,然后调用flush()方法写出到文件
      Parameters:
      workbook - Workbook
      sheetName - sheet名,做为第一个sheet名并写出到此sheet,例如sheet1
    • ExcelWriter

      public ExcelWriter(org.apache.poi.ss.usermodel.Sheet sheet)
      构造 此构造不传入写出的Excel文件路径,只能调用flush(OutputStream)方法写出到流 若写出到文件,还需调用setDestFile(File)方法自定义写出的文件,然后调用flush()方法写出到文件
      Parameters:
      sheet - Sheet
  • Method Details

    • setCellEditor

      public ExcelWriter setCellEditor(CellEditor cellEditor)
      设置单元格值处理逻辑
      当Excel中的值并不能满足我们的读取要求时,通过传入一个编辑接口,可以对单元格值自定义,例如对数字和日期类型值转换为字符串等
      Parameters:
      cellEditor - 单元格值处理接口
      Returns:
      this
    • setSheet

      public ExcelWriter setSheet(int sheetIndex)
      Description copied from class: ExcelBase
      自定义需要读取或写出的Sheet,如果给定的sheet不存在,创建之(命名为默认) 在读取中,此方法用于切换读取的sheet,在写出时,此方法用于新建或者切换sheet
      Overrides:
      setSheet in class ExcelBase<ExcelWriter>
      Parameters:
      sheetIndex - sheet序号,从0开始计数
      Returns:
      this
    • setSheet

      public ExcelWriter setSheet(String sheetName)
      Description copied from class: ExcelBase
      自定义需要读取或写出的Sheet,如果给定的sheet不存在,创建之 在读取中,此方法用于切换读取的sheet,在写出时,此方法用于新建或者切换sheet
      Overrides:
      setSheet in class ExcelBase<ExcelWriter>
      Parameters:
      sheetName - sheet名
      Returns:
      this
    • reset

      public ExcelWriter reset()
      重置Writer,包括:
       1. 当前行游标归零
       2. 清空别名比较器
       
      Returns:
      this
    • renameSheet

      public ExcelWriter renameSheet(String sheetName)
      重命名当前sheet
      Overrides:
      renameSheet in class ExcelBase<ExcelWriter>
      Parameters:
      sheetName - 新的sheet名
      Returns:
      this
      See Also:
      • Workbook.setSheetName(int, String)
    • renameSheet

      public ExcelWriter renameSheet(int sheet, String sheetName)
      重命名sheet
      Parameters:
      sheet - sheet需要,0表示第一个sheet
      sheetName - 新的sheet名
      Returns:
      this
    • autoSizeColumnAll

      public ExcelWriter autoSizeColumnAll()
      设置所有列为自动宽度,不考虑合并单元格 此方法必须在指定列数据完全写出后调用才有效 列数计算是通过第一行计算的
      Returns:
      this
    • autoSizeColumn

      public ExcelWriter autoSizeColumn(int columnIndex)
      设置某列为自动宽度,不考虑合并单元格 此方法必须在指定列数据完全写出后调用才有效
      Parameters:
      columnIndex - 第几列,从0计数
      Returns:
      this
    • autoSizeColumn

      public ExcelWriter autoSizeColumn(int columnIndex, boolean useMergedCells)
      设置某列为自动宽度 此方法必须在指定列数据完全写出后调用才有效
      Parameters:
      columnIndex - 第几列,从0计数
      useMergedCells - 是否适用于合并单元格
      Returns:
      this
    • getStyleSet

      public StyleSet getStyleSet()
      获取样式集,样式集可以自定义包括:
       1. 头部样式
       2. 一般单元格样式
       3. 默认数字样式
       4. 默认日期样式
       
      Returns:
      样式集
    • setStyleSet

      public ExcelWriter setStyleSet(StyleSet styleSet)
      设置样式集,如果不使用样式,传入null
      Parameters:
      styleSet - 样式集,null表示无样式
      Returns:
      this
    • getHeadCellStyle

      public org.apache.poi.ss.usermodel.CellStyle getHeadCellStyle()
      获取头部样式,获取样式后可自定义样式
      Returns:
      头部样式
    • getCellStyle

      public org.apache.poi.ss.usermodel.CellStyle getCellStyle()
      获取单元格样式,获取样式后可自定义样式
      Returns:
      单元格样式
    • getCurrentRow

      public int getCurrentRow()
      获得当前行
      Returns:
      当前行
    • setCurrentRow

      public ExcelWriter setCurrentRow(int rowIndex)
      设置当前所在行
      Parameters:
      rowIndex - 行号
      Returns:
      this
    • passCurrentRow

      public ExcelWriter passCurrentRow()
      跳过当前行
      Returns:
      this
    • passRows

      public ExcelWriter passRows(int rows)
      跳过指定行数
      Parameters:
      rows - 跳过的行数
      Returns:
      this
    • resetRow

      public ExcelWriter resetRow()
      重置当前行为0
      Returns:
      this
    • setDestFile

      public ExcelWriter setDestFile(File destFile)
      设置写出的目标文件
      Parameters:
      destFile - 目标文件
      Returns:
      this
    • setHeaderAlias

      public ExcelWriter setHeaderAlias(Map<String,String> headerAlias)
      Description copied from class: ExcelBase
      设置标题行的别名Map
      Overrides:
      setHeaderAlias in class ExcelBase<ExcelWriter>
      Parameters:
      headerAlias - 别名Map
      Returns:
      this
    • clearHeaderAlias

      public ExcelWriter clearHeaderAlias()
      Description copied from class: ExcelBase
      清空标题别名,key为Map中的key,value为别名
      Overrides:
      clearHeaderAlias in class ExcelBase<ExcelWriter>
      Returns:
      this
    • addHeaderAlias

      public ExcelWriter addHeaderAlias(String name, String alias)
      Description copied from class: ExcelBase
      增加标题别名
      Overrides:
      addHeaderAlias in class ExcelBase<ExcelWriter>
      Parameters:
      name - 标题
      alias - 别名
      Returns:
      this
    • setOnlyAlias

      public ExcelWriter setOnlyAlias(boolean isOnlyAlias)
      设置是否只保留别名中的字段值,如果为true,则不设置alias的字段将不被输出,false表示原样输出
      Parameters:
      isOnlyAlias - 是否只保留别名中的字段值
      Returns:
      this
    • setFreezePane

      public ExcelWriter setFreezePane(int rowSplit)
      设置窗口冻结,之前冻结的窗口会被覆盖,如果rowSplit为0表示取消冻结
      Parameters:
      rowSplit - 冻结的行及行数,2表示前两行
      Returns:
      this
    • setFreezePane

      public ExcelWriter setFreezePane(int colSplit, int rowSplit)
      设置窗口冻结,之前冻结的窗口会被覆盖,如果colSplit和rowSplit为0表示取消冻结
      Parameters:
      colSplit - 冻结的列及列数,2表示前两列
      rowSplit - 冻结的行及行数,2表示前两行
      Returns:
      this
    • setColumnWidth

      public ExcelWriter setColumnWidth(int columnIndex, int width)
      设置列宽(单位为一个字符的宽度,例如传入width为10,表示10个字符的宽度)
      Parameters:
      columnIndex - 列号(从0开始计数,-1表示所有列的默认宽度)
      width - 宽度(单位1~256个字符宽度)
      Returns:
      this
    • setRowHeight

      public ExcelWriter setRowHeight(int rownum, int height)
      设置行高,值为一个点的高度
      Parameters:
      rownum - 行号(从0开始计数,-1表示所有行的默认高度)
      height - 高度
      Returns:
      this
    • setHeaderOrFooter

      public ExcelWriter setHeaderOrFooter(String text, org.aoju.bus.core.lang.Align align, boolean isFooter)
      设置Excel页眉或页脚
      Parameters:
      text - 页脚的文本
      align - 对齐方式枚举 Align
      isFooter - 是否为页脚,false表示页眉,true表示页脚
      Returns:
      this
    • merge

      public ExcelWriter merge(int lastColumn)
      合并当前行的单元格 样式为默认标题样式,可使用getHeadCellStyle()方法调用后自定义默认样式
      Parameters:
      lastColumn - 合并到的最后一个列号
      Returns:
      this
    • merge

      public ExcelWriter merge(int lastColumn, Object content)
      合并当前行的单元格,并写入对象到单元格 如果写到单元格中的内容非null,行号自动+1,否则当前行号不变 样式为默认标题样式,可使用getHeadCellStyle()方法调用后自定义默认样式
      Parameters:
      lastColumn - 合并到的最后一个列号
      content - 合并单元格后的内容
      Returns:
      this
    • merge

      public ExcelWriter merge(int lastColumn, Object content, boolean isSetHeaderStyle)
      合并某行的单元格,并写入对象到单元格 如果写到单元格中的内容非null,行号自动+1,否则当前行号不变 样式为默认标题样式,可使用getHeadCellStyle()方法调用后自定义默认样式
      Parameters:
      lastColumn - 合并到的最后一个列号
      content - 合并单元格后的内容
      isSetHeaderStyle - 是否为合并后的单元格设置默认标题样式
      Returns:
      this
    • merge

      public ExcelWriter merge(int firstRow, int lastRow, int firstColumn, int lastColumn, Object content, boolean isSetHeaderStyle)
      合并某行的单元格,并写入对象到单元格 如果写到单元格中的内容非null,行号自动+1,否则当前行号不变 样式为默认标题样式,可使用getHeadCellStyle()方法调用后自定义默认样式
      Parameters:
      firstRow - 第一行
      lastRow - 最后一行
      firstColumn - 第一列
      lastColumn - 合并到的最后一个列号
      content - 合并单元格后的内容
      isSetHeaderStyle - 是否为合并后的单元格设置默认标题样式
      Returns:
      this
    • merge

      public ExcelWriter merge(int firstRow, int lastRow, int firstColumn, int lastColumn, Object content, org.apache.poi.ss.usermodel.CellStyle cellStyle)
      合并单元格,并写入对象到单元格,使用指定的样式 指定样式传入null,则不使用任何样式
      Parameters:
      firstRow - 起始行,0开始
      lastRow - 结束行,0开始
      firstColumn - 起始列,0开始
      lastColumn - 结束列,0开始
      content - 合并单元格后的内容
      cellStyle - 合并后单元格使用的样式,可以为null
      Returns:
      this
    • write

      public ExcelWriter write(Iterable<?> data)
      写出数据,本方法只是将数据写入Workbook中的Sheet,并不写出到文件 写出的起始行为当前行号,可使用getCurrentRow()方法调用,根据写出的的行数,当前行号自动增加 样式为默认样式,可使用getCellStyle()方法调用后自定义默认样式 默认的,当当前行号为0时,写出标题(如果为Map或Bean),否则不写标题

      data中元素支持的类型有:

       1. Iterable,既元素为一个集合,元素被当作一行,data表示多行
       2. Map,既元素为一个Map,第一个Map的keys作为首行,剩下的行为Map的values,data表示多行
       3. Bean,既元素为一个Bean,第一个Bean的字段名列表会作为首行,剩下的行为Bean的字段值列表,data表示多行
       4. 其它类型,按照基本类型输出(例如字符串)
       
      Parameters:
      data - 数据
      Returns:
      this
    • write

      public ExcelWriter write(Iterable<?> data, boolean isWriteKeyAsHead)
      写出数据,本方法只是将数据写入Workbook中的Sheet,并不写出到文件 写出的起始行为当前行号,可使用getCurrentRow()方法调用,根据写出的的行数,当前行号自动增加 样式为默认样式,可使用getCellStyle()方法调用后自定义默认样式

      data中元素支持的类型有:

       1. Iterable,既元素为一个集合,元素被当作一行,data表示多行
       2. Map,既元素为一个Map,第一个Map的keys作为首行,剩下的行为Map的values,data表示多行
       3. Bean,既元素为一个Bean,第一个Bean的字段名列表会作为首行,剩下的行为Bean的字段值列表,data表示多行
       4. 其它类型,按照基本类型输出(例如字符串)
       
      Parameters:
      data - 数据
      isWriteKeyAsHead - 是否强制写出标题行(Map或Bean)
      Returns:
      this
    • write

      public ExcelWriter write(Iterable<?> data, Comparator<String> comparator)
      写出数据,本方法只是将数据写入Workbook中的Sheet,并不写出到文件 写出的起始行为当前行号,可使用getCurrentRow()方法调用,根据写出的的行数,当前行号自动增加 样式为默认样式,可使用getCellStyle()方法调用后自定义默认样式 data中元素支持的类型有:

      1. Map,既元素为一个Map,第一个Map的keys作为首行,剩下的行为Map的values,data表示多行 2. Bean,既元素为一个Bean,第一个Bean的字段名列表会作为首行,剩下的行为Bean的字段值列表,data表示多行

      Parameters:
      data - 数据
      comparator - 比较器,用于字段名的排序
      Returns:
      this
    • writeImg

      public ExcelWriter writeImg(File imgFile, int col1, int row1, int col2, int row2)
      写出数据,本方法只是将数据写入Workbook中的Sheet,并不写出到文件 添加图片到当前sheet中 / 默认图片类型png / 默认的起始坐标和结束坐标都为0
      Parameters:
      imgFile - 图片文件
      col1 - 指定起始的列,下标从0开始
      row1 - 指定起始的行,下标从0开始
      col2 - 指定结束的列,下标从0开始
      row2 - 指定结束的行,下标从0开始
      Returns:
      this
    • writeImg

      public ExcelWriter writeImg(File imgFile, int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2)
      写出数据,本方法只是将数据写入Workbook中的Sheet,并不写出到文件 添加图片到当前sheet中 / 默认图片类型png
      Parameters:
      imgFile - 图片文件
      dx1 - 起始单元格中的x坐标
      dy1 - 起始单元格中的y坐标
      dx2 - 结束单元格中的x坐标
      dy2 - 结束单元格中的y坐标
      col1 - 指定起始的列,下标从0开始
      row1 - 指定起始的行,下标从0开始
      col2 - 指定结束的列,下标从0开始
      row2 - 指定结束的行,下标从0开始
      Returns:
      this
    • writeImg

      public ExcelWriter writeImg(File imgFile, int imgType, int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2)
      写出数据,本方法只是将数据写入Workbook中的Sheet,并不写出到文件 添加图片到当前sheet中
      Parameters:
      imgFile - 图片文件
      imgType - 图片类型,对应poi中Workbook类中的图片类型2-7变量
      dx1 - 起始单元格中的x坐标
      dy1 - 起始单元格中的y坐标
      dx2 - 结束单元格中的x坐标
      dy2 - 结束单元格中的y坐标
      col1 - 指定起始的列,下标从0开始
      row1 - 指定起始的行,下标从0开始
      col2 - 指定结束的列,下标从0开始
      row2 - 指定结束的行,下标从0开始
      Returns:
      this
    • writeImg

      public ExcelWriter writeImg(byte[] pictureData, int imgType, int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2)
      写出数据,本方法只是将数据写入Workbook中的Sheet,并不写出到文件 添加图片到当前sheet中
      Parameters:
      pictureData - 数据bytes
      imgType - 图片类型,对应poi中Workbook类中的图片类型2-7变量
      dx1 - 起始单元格中的x坐标
      dy1 - 起始单元格中的y坐标
      dx2 - 结束单元格中的x坐标
      dy2 - 结束单元格中的y坐标
      col1 - 指定起始的列,下标从0开始
      row1 - 指定起始的行,下标从0开始
      col2 - 指定结束的列,下标从0开始
      row2 - 指定结束的行,下标从0开始
      Returns:
      this
    • writeHeadRow

      public ExcelWriter writeHeadRow(Iterable<?> rowData)
      写出一行标题数据 本方法只是将数据写入Workbook中的Sheet,并不写出到文件 写出的起始行为当前行号,可使用getCurrentRow()方法调用,根据写出的的行数,当前行号自动+1 样式为默认标题样式,可使用getHeadCellStyle()方法调用后自定义默认样式
      Parameters:
      rowData - 一行的数据
      Returns:
      this
    • writeRow

      public ExcelWriter writeRow(Object rowBean, boolean isWriteKeyAsHead)
      写出一行,根据rowBean数据类型不同,写出情况如下:
       1、如果为Iterable,直接写出一行
       2、如果为Map,isWriteKeyAsHead为true写出两行,Map的keys做为一行,values做为第二行,否则只写出一行values
       3、如果为Bean,转为Map写出,isWriteKeyAsHead为true写出两行,Map的keys做为一行,values做为第二行,否则只写出一行values
       
      Parameters:
      rowBean - 写出的Bean
      isWriteKeyAsHead - 为true写出两行,Map的keys做为一行,values做为第二行,否则只写出一行values
      Returns:
      this
      See Also:
    • writeRow

      public ExcelWriter writeRow(Map<?,?> rowMap, boolean isWriteKeyAsHead)
      将一个Map写入到Excel,isWriteKeyAsHead为true写出两行,Map的keys做为一行,values做为第二行,否则只写出一行values 如果rowMap为空(包括null),则写出空行
      Parameters:
      rowMap - 写出的Map,为空(包括null),则写出空行
      isWriteKeyAsHead - 为true写出两行,Map的keys做为一行,values做为第二行,否则只写出一行values
      Returns:
      this
    • writeRow

      public ExcelWriter writeRow(Iterable<?> rowData)
      写出一行数据 本方法只是将数据写入Workbook中的Sheet,并不写出到文件 写出的起始行为当前行号,可使用getCurrentRow()方法调用,根据写出的的行数,当前行号自动+1 样式为默认样式,可使用getCellStyle()方法调用后自定义默认样式
      Parameters:
      rowData - 一行的数据
      Returns:
      this
    • writeSecHeadRow

      public ExcelWriter writeSecHeadRow(Iterable<?> rowData)
      写出复杂标题的第二行标题数据 本方法只是将数据写入Workbook中的Sheet,并不写出到文件 写出的起始行为当前行号,可使用getCurrentRow()方法调用,根据写出的的行数,当前行号自动+1 样式为默认标题样式,可使用getHeadCellStyle()方法调用后自定义默认样式
      Parameters:
      rowData - 一行的数据
      Returns:
      this
    • writeCellValue

      public ExcelWriter writeCellValue(int x, int y, Object value)
      给指定单元格赋值,使用默认单元格样式
      Parameters:
      x - X坐标,从0计数,既列号
      y - Y坐标,从0计数,既行号
      value - 值
      Returns:
      this
    • writeCellValue

      public ExcelWriter writeCellValue(String locationRef, Object value)
      给指定单元格赋值,使用默认单元格样式
      Parameters:
      locationRef - 单元格地址标识符,例如A11,B5
      value - 值
      Returns:
      this
    • setStyle

      public ExcelWriter setStyle(org.apache.poi.ss.usermodel.CellStyle style, int x, int y)
      设置某个单元格的样式 此方法用于多个单元格共享样式的情况 可以调用ExcelBase.getOrCreateCellStyle(int, int) 方法创建或取得一个样式对象 需要注意的是,共享样式会共享同一个CellStyle,一个单元格样式改变,全部改变
      Parameters:
      style - 单元格样式
      x - X坐标,从0计数,即列号
      y - Y坐标,从0计数,即行号
      Returns:
      this
    • setStyle

      public ExcelWriter setStyle(org.apache.poi.ss.usermodel.CellStyle style, String locationRef)
      设置某个单元格的样式 此方法用于多个单元格共享样式的情况 可以调用ExcelBase.getOrCreateCellStyle(int, int) 方法创建或取得一个样式对象 需要注意的是,共享样式会共享同一个CellStyle,一个单元格样式改变,全部改变
      Parameters:
      style - 单元格样式
      locationRef - 单元格地址标识符,例如A11,B5
      Returns:
      this
    • setRowStyle

      public ExcelWriter setRowStyle(int y, org.apache.poi.ss.usermodel.CellStyle style)
      设置行样式
      Parameters:
      y - Y坐标,从0计数,即行号
      style - 样式
      Returns:
      this
      See Also:
      • Row.setRowStyle(CellStyle)
    • setColumnStyle

      public ExcelWriter setColumnStyle(int x, org.apache.poi.ss.usermodel.CellStyle style)
      设置列的默认样式
      Parameters:
      x - 列号,从0开始
      style - 样式
      Returns:
      this
    • createFont

      public org.apache.poi.ss.usermodel.Font createFont()
      创建字体
      Returns:
      字体
    • flush

      public ExcelWriter flush() throws org.aoju.bus.core.exception.InternalException
      将Excel Workbook刷出到预定义的文件 如果用户未自定义输出的文件,将抛出NullPointerException 预定义文件可以通过setDestFile(File) 方法预定义,或者通过构造定义
      Returns:
      this
      Throws:
      org.aoju.bus.core.exception.InternalException - IO异常
    • flush

      public ExcelWriter flush(File destFile) throws org.aoju.bus.core.exception.InternalException
      将Excel Workbook刷出到文件 如果用户未自定义输出的文件,将抛出InternalException
      Parameters:
      destFile - 写出到的文件
      Returns:
      this
      Throws:
      org.aoju.bus.core.exception.InternalException - IO异常
    • flush

      public ExcelWriter flush(OutputStream out) throws org.aoju.bus.core.exception.InternalException
      将Excel Workbook刷出到输出流
      Parameters:
      out - 输出流
      Returns:
      this
      Throws:
      org.aoju.bus.core.exception.InternalException - IO异常
    • flush

      public ExcelWriter flush(OutputStream out, boolean isCloseOut) throws org.aoju.bus.core.exception.InternalException
      将Excel Workbook刷出到输出流
      Parameters:
      out - 输出流
      isCloseOut - 是否关闭输出流
      Returns:
      this
      Throws:
      org.aoju.bus.core.exception.InternalException - IO异常
    • addSelect

      public ExcelWriter addSelect(int x, int y, String... selectList)
      增加下拉列表
      Parameters:
      x - x坐标,列号,从0开始
      y - y坐标,行号,从0开始
      selectList - 下拉列表
      Returns:
      this
    • addSelect

      public ExcelWriter addSelect(org.apache.poi.ss.util.CellRangeAddressList regions, String... selectList)
      增加下拉列表
      Parameters:
      regions - CellRangeAddressList 指定下拉列表所占的单元格范围
      selectList - 下拉列表内容
      Returns:
      this
    • addValidationData

      public ExcelWriter addValidationData(org.apache.poi.ss.usermodel.DataValidation dataValidation)
      增加单元格控制,比如下拉列表、日期验证、数字范围验证等
      Parameters:
      dataValidation - DataValidation
      Returns:
      this
    • close

      public void close()
      关闭工作簿 如果用户设定了目标文件,先写出目标文件后给关闭工作簿
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class ExcelBase<ExcelWriter>
    • getDisposition

      public String getDisposition(String fileName, Charset charset)
      获取Content-Disposition头对应的值,可以通过调用以下方法快速设置下载Excel的头信息:
       response.setHeader("Content-Disposition", excelWriter.getDisposition("test.xlsx", CharsetUtil.CHARSET_UTF_8));
       
      Parameters:
      fileName - 文件名,如果文件名没有扩展名,会自动按照生成Excel类型补齐扩展名,如果提供空,使用随机UUID
      charset - 编码,null则使用默认UTF-8编码
      Returns:
      Content-Disposition值
    • getContentType

      public String getContentType()
      获取Content-Type头对应的值,可以通过调用以下方法快速设置下载Excel的头信息:
       response.setContentType(excelWriter.getContentType());
       
      Returns:
      Content-Type值
    • isXlsx

      public boolean isXlsx()
      判断是否为xlsx格式的Excel表(Excel07格式)
      Returns:
      是否为xlsx格式的Excel表(Excel07格式)
    • closeWithoutFlush

      protected void closeWithoutFlush()
      关闭工作簿但是不写出