类 Excel
java.lang.Object
cool.scx.ext.util.Excel
todo : (注意 此工具类只支持单 sheet页的情况) 需要改为支持多个 sheet 页的情况
Excel 操作类
对 生成 excel 进行一些简单的封装 方便使用
- 版本:
- 0.9.1
- 作者:
- scx567888
-
字段概要
字段 -
方法概要
修饰符和类型方法说明org.apache.poi.ss.usermodel.CellStyle创建单元格样式org.apache.poi.ss.usermodel.Font创建字体static Excelget03Excel(String sheetName, int rowSize) 获取 03 版 excel (xls)static Excelget07Excel(String sheetName, int rowSize) 获取 07 版 excel (xlsx)org.apache.poi.ss.usermodel.RowgetRow(int rowIndex) 根据索引获取行org.apache.poi.ss.usermodel.SheetgetSheet()获取 sheet 页org.apache.poi.ss.usermodel.Sheet获取指定名称的 sheetorg.apache.poi.ss.util.CellRangeAddressmergedRegion(int firstRow, int firstCol, int down, int right) 合并单元格 注意 right 和 down 为合并大小 及 最终表格大小会是 right 和 down + 1 因为包括原始行org.apache.poi.ss.util.CellRangeAddressmergedRegion(org.apache.poi.ss.util.CellRangeAddress addresses) 根据坐标合并单元格org.apache.poi.ss.util.CellRangeAddresssetBorder(int firstRow, int firstCol) 设置边框 (只设置一个单元格)*org.apache.poi.ss.util.CellRangeAddresssetBorder(int firstRow, int lastRow, int firstCol, int lastCol) 设置边框org.apache.poi.ss.util.CellRangeAddresssetBorder(org.apache.poi.ss.util.CellRangeAddress cellAddresses) 设置边框 根据坐标org.apache.poi.ss.usermodel.CellsetCellValue(int firstRow, int firstCol, String value) 设置单元格样式org.apache.poi.ss.usermodel.CellsetCellValue(int firstRow, int firstCol, String value, org.apache.poi.ss.usermodel.CellStyle xssfCellStyle) 设置单元格数据byte[]toBytes()toBytes.
-
字段详细资料
-
workbook
public final org.apache.poi.ss.usermodel.Workbook workbookExcel 实例 -
sheet
public final org.apache.poi.ss.usermodel.Sheet sheet当前 sheet 后期会修改为 支持多个 sheet 页 -
rowMap
行缓存 此处提前创建 row 方便后续直接根据索引使用
-
-
方法详细资料
-
get03Excel
获取 03 版 excel (xls)- 参数:
sheetName- sheet 名称rowSize- 初始的行大小 建议提前估算一个值 并设置为 估算值的 1.5倍- 返回:
- xls
-
get07Excel
获取 07 版 excel (xlsx)- 参数:
sheetName- sheet 名称rowSize- 初始的行大小 建议提前估算一个值 并设置为 估算值的 1.5倍- 返回:
- xlsx
-
setBorder
public org.apache.poi.ss.util.CellRangeAddress setBorder(int firstRow, int lastRow, int firstCol, int lastCol) 设置边框- 参数:
firstRow- 起始行lastRow- 结束行firstCol- 起始列lastCol- 结束列- 返回:
- 返回坐标地址 方便链式调用
-
setBorder
public org.apache.poi.ss.util.CellRangeAddress setBorder(org.apache.poi.ss.util.CellRangeAddress cellAddresses) 设置边框 根据坐标- 参数:
cellAddresses- 坐标- 返回:
- 返回坐标地址 方便链式调用
-
setBorder
public org.apache.poi.ss.util.CellRangeAddress setBorder(int firstRow, int firstCol) 设置边框 (只设置一个单元格)*- 参数:
firstRow- 起始行firstCol- 起始列- 返回:
- 坐标
-
getSheet
public org.apache.poi.ss.usermodel.Sheet getSheet()获取 sheet 页- 返回:
- 当前 sheet
-
getSheet
获取指定名称的 sheet- 参数:
name- aStringobject.- 返回:
- a
Sheetobject.
-
mergedRegion
public org.apache.poi.ss.util.CellRangeAddress mergedRegion(int firstRow, int firstCol, int down, int right) 合并单元格 注意 right 和 down 为合并大小 及 最终表格大小会是 right 和 down + 1 因为包括原始行- 参数:
firstRow- 起始行 (纵向)firstCol- 起始列 (横向)down- 向下合并几个单元格 可以为负数right- 向左合并几个单元格 可以为负数- 返回:
- a
CellRangeAddressobject.
-
mergedRegion
public org.apache.poi.ss.util.CellRangeAddress mergedRegion(org.apache.poi.ss.util.CellRangeAddress addresses) 根据坐标合并单元格- 参数:
addresses- aCellRangeAddressobject.- 返回:
- a
CellRangeAddressobject.
-
setCellValue
public org.apache.poi.ss.usermodel.Cell setCellValue(int firstRow, int firstCol, String value, org.apache.poi.ss.usermodel.CellStyle xssfCellStyle) 设置单元格数据- 参数:
firstRow- a int.firstCol- a int.value- aStringobject.xssfCellStyle- aCellStyleobject.- 返回:
- a
Cellobject.
-
setCellValue
设置单元格样式- 参数:
firstRow- a int.firstCol- a int.value- aStringobject.- 返回:
- a
Cellobject.
-
createCellStyle
public org.apache.poi.ss.usermodel.CellStyle createCellStyle()创建单元格样式- 返回:
- a
CellStyleobject.
-
createFont
public org.apache.poi.ss.usermodel.Font createFont()创建字体- 返回:
- a
Fontobject.
-
getRow
public org.apache.poi.ss.usermodel.Row getRow(int rowIndex) 根据索引获取行- 参数:
rowIndex- a int.- 返回:
- a
Rowobject.
-
toBytes
public byte[] toBytes()toBytes.
- 返回:
- an array of
objects
引用无效
byte
-