public class CellUtil extends Object
Constructor and Description |
---|
CellUtil() |
Modifier and Type | Method and Description |
---|---|
static org.apache.poi.ss.usermodel.Cell |
getCell(org.apache.poi.ss.usermodel.Row row,
int cellIndex)
获取单元格,如果单元格不存在,返回
NullCell |
static org.apache.poi.ss.util.CellRangeAddress |
getCellRangeAddress(org.apache.poi.ss.usermodel.Cell cell)
获取合并单元格
CellRangeAddress ,如果不是返回null |
static org.apache.poi.ss.util.CellRangeAddress |
getCellRangeAddress(org.apache.poi.ss.usermodel.Sheet sheet,
int x,
int y)
获取合并单元格
CellRangeAddress ,如果不是返回null |
static org.apache.poi.ss.util.CellRangeAddress |
getCellRangeAddress(org.apache.poi.ss.usermodel.Sheet sheet,
String locationRef)
获取合并单元格
CellRangeAddress ,如果不是返回null |
static Object |
getCellValue(org.apache.poi.ss.usermodel.Cell cell)
获取单元格值
|
static Object |
getCellValue(org.apache.poi.ss.usermodel.Cell cell,
boolean isTrimCellValue)
获取单元格值
|
static Object |
getCellValue(org.apache.poi.ss.usermodel.Cell cell,
CellEditor cellEditor)
获取单元格值
|
static Object |
getCellValue(org.apache.poi.ss.usermodel.Cell cell,
org.apache.poi.ss.usermodel.CellType cellType,
boolean isTrimCellValue)
获取单元格值
|
static Object |
getCellValue(org.apache.poi.ss.usermodel.Cell cell,
org.apache.poi.ss.usermodel.CellType cellType,
CellEditor cellEditor)
获取单元格值
如果单元格值为数字格式,则判断其格式中是否有小数部分,无则返回Long类型,否则返回Double类型 |
static org.apache.poi.ss.usermodel.Cell |
getMergedRegionCell(org.apache.poi.ss.usermodel.Cell cell)
获取合并单元格
传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格 |
static org.apache.poi.ss.usermodel.Cell |
getMergedRegionCell(org.apache.poi.ss.usermodel.Sheet sheet,
int x,
int y)
获取合并单元格
传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格 |
static Object |
getMergedRegionValue(org.apache.poi.ss.usermodel.Sheet sheet,
int x,
int y)
获取合并单元格的值
传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格 |
static Object |
getMergedRegionValue(org.apache.poi.ss.usermodel.Sheet sheet,
String locationRef)
获取合并单元格的值
传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格 |
static org.apache.poi.ss.usermodel.Cell |
getOrCreateCell(org.apache.poi.ss.usermodel.Row row,
int cellIndex)
获取已有单元格或创建新单元格
|
static boolean |
isMergedRegion(org.apache.poi.ss.usermodel.Cell cell)
判断指定的单元格是否是合并单元格
|
static boolean |
isMergedRegion(org.apache.poi.ss.usermodel.Sheet sheet,
int x,
int y)
判断指定的单元格是否是合并单元格
|
static boolean |
isMergedRegion(org.apache.poi.ss.usermodel.Sheet sheet,
String locationRef)
判断指定的单元格是否是合并单元格
|
static int |
mergingCells(org.apache.poi.ss.usermodel.Sheet sheet,
int firstRow,
int lastRow,
int firstColumn,
int lastColumn)
合并单元格,可以根据设置的值来合并行和列
|
static int |
mergingCells(org.apache.poi.ss.usermodel.Sheet sheet,
int firstRow,
int lastRow,
int firstColumn,
int lastColumn,
org.apache.poi.ss.usermodel.CellStyle cellStyle)
合并单元格,可以根据设置的值来合并行和列
|
static void |
setCellValue(org.apache.poi.ss.usermodel.Cell cell,
Object value)
设置单元格值
根据传入的styleSet自动匹配样式 当为头部样式时默认赋值头部样式,但是头部中如果有数字、日期等类型,将按照数字、日期样式设置 |
static void |
setCellValue(org.apache.poi.ss.usermodel.Cell cell,
Object value,
org.apache.poi.ss.usermodel.CellStyle style)
设置单元格值
根据传入的styleSet自动匹配样式 当为头部样式时默认赋值头部样式,但是头部中如果有数字、日期等类型,将按照数字、日期样式设置 |
static void |
setCellValue(org.apache.poi.ss.usermodel.Cell cell,
Object value,
StyleSet styleSet,
boolean isHeader)
设置单元格值
根据传入的styleSet自动匹配样式 当为头部样式时默认赋值头部样式,但是头部中如果有数字、日期等类型,将按照数字、日期样式设置 |
static void |
setComment(org.apache.poi.ss.usermodel.Cell cell,
String commentText,
String commentAuthor,
org.apache.poi.ss.usermodel.ClientAnchor anchor)
为特定单元格添加批注
|
static void |
setMergedRegionStyle(org.apache.poi.ss.usermodel.Cell cell,
org.apache.poi.ss.usermodel.CellStyle cellStyle)
设置合并单元格样式,如果不是则不设置
|
public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell)
cell
- Cell
单元格public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell, boolean isTrimCellValue)
cell
- Cell
单元格isTrimCellValue
- 如果单元格类型为字符串,是否去掉两边空白符public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell, CellEditor cellEditor)
cell
- Cell
单元格cellEditor
- 单元格值编辑器。可以通过此编辑器对单元格值做自定义操作public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellType cellType, boolean isTrimCellValue)
cell
- Cell
单元格cellType
- 单元格值类型CellType
枚举isTrimCellValue
- 如果单元格类型为字符串,是否去掉两边空白符public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellType cellType, CellEditor cellEditor)
cell
- Cell
单元格cellType
- 单元格值类型CellType
枚举,如果为null
默认使用cell的类型cellEditor
- 单元格值编辑器。可以通过此编辑器对单元格值做自定义操作public static void setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value, StyleSet styleSet, boolean isHeader)
cell
- 单元格value
- 值styleSet
- 单元格样式集,包括日期等样式,null表示无样式isHeader
- 是否为标题单元格public static void setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value, org.apache.poi.ss.usermodel.CellStyle style)
cell
- 单元格value
- 值style
- 自定义样式,null表示无样式public static void setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value)
cell
- 单元格value
- 值或CellSetter
public static org.apache.poi.ss.usermodel.Cell getCell(org.apache.poi.ss.usermodel.Row row, int cellIndex)
NullCell
row
- Excel表的行cellIndex
- 列号Cell
public static org.apache.poi.ss.usermodel.Cell getOrCreateCell(org.apache.poi.ss.usermodel.Row row, int cellIndex)
row
- Excel表的行cellIndex
- 列号Cell
public static boolean isMergedRegion(org.apache.poi.ss.usermodel.Sheet sheet, String locationRef)
sheet
- Sheet
locationRef
- 单元格地址标识符,例如A11,B5public static boolean isMergedRegion(org.apache.poi.ss.usermodel.Cell cell)
cell
- Cell
public static boolean isMergedRegion(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
sheet
- Sheet
x
- 列号,从0开始y
- 行号,从0开始null
,返回false
public static org.apache.poi.ss.util.CellRangeAddress getCellRangeAddress(org.apache.poi.ss.usermodel.Sheet sheet, String locationRef)
CellRangeAddress
,如果不是返回nullsheet
- Sheet
locationRef
- 单元格地址标识符,例如A11,B5CellRangeAddress
public static org.apache.poi.ss.util.CellRangeAddress getCellRangeAddress(org.apache.poi.ss.usermodel.Cell cell)
CellRangeAddress
,如果不是返回nullcell
- Cell
CellRangeAddress
public static org.apache.poi.ss.util.CellRangeAddress getCellRangeAddress(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
CellRangeAddress
,如果不是返回nullsheet
- Sheet
x
- 列号,从0开始y
- 行号,从0开始CellRangeAddress
public static void setMergedRegionStyle(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellStyle cellStyle)
cell
- Cell
cellStyle
- CellStyle
public static int mergingCells(org.apache.poi.ss.usermodel.Sheet sheet, int firstRow, int lastRow, int firstColumn, int lastColumn)
sheet
- 表对象firstRow
- 起始行,0开始lastRow
- 结束行,0开始firstColumn
- 起始列,0开始lastColumn
- 结束列,0开始public static int mergingCells(org.apache.poi.ss.usermodel.Sheet sheet, int firstRow, int lastRow, int firstColumn, int lastColumn, org.apache.poi.ss.usermodel.CellStyle cellStyle)
sheet
- 表对象firstRow
- 起始行,0开始lastRow
- 结束行,0开始firstColumn
- 起始列,0开始lastColumn
- 结束列,0开始cellStyle
- 单元格样式,只提取边框样式,null表示无样式public static Object getMergedRegionValue(org.apache.poi.ss.usermodel.Sheet sheet, String locationRef)
sheet
- Sheet
locationRef
- 单元格地址标识符,例如A11,B5public static Object getMergedRegionValue(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
sheet
- Sheet
x
- 列号,从0开始,可以是合并单元格范围中的任意一列y
- 行号,从0开始,可以是合并单元格范围中的任意一行public static org.apache.poi.ss.usermodel.Cell getMergedRegionCell(org.apache.poi.ss.usermodel.Cell cell)
cell
- Cell
public static org.apache.poi.ss.usermodel.Cell getMergedRegionCell(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
sheet
- Sheet
x
- 列号,从0开始,可以是合并单元格范围中的任意一列y
- 行号,从0开始,可以是合并单元格范围中的任意一行Copyright © 2024. All rights reserved.