public class SheetUtil
extends java.lang.Object
Constructor and Description |
---|
SheetUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
canComputeColumnWidth(Font font)
Check if the Fonts are installed correctly so that Java can compute the size of columns.
(检查字体是否安装正确,以便 Java 可以计算列的大小。)
|
static Cell |
getCell(Sheet sheet, int rowIx, int colIx)
Return the cell, without taking account of merged regions.
(返回单元格,不考虑合并区域。)
|
static double |
getCellWidth(Cell cell, int defaultCharWidth, DataFormatter formatter, boolean useMergedCells)
Compute width of a single cell
(计算单个单元格的宽度)
|
static double |
getCellWidth(Cell cell, int defaultCharWidth, DataFormatter formatter, boolean useMergedCells, java.util.List<CellRangeAddress> mergedRegions)
Compute width of a single cell This method receives the list of merged regions as querying it from the cell/sheet is time-consuming and thus caching the list across cells speeds up certain operations considerably.
(计算单个单元格的宽度此方法接收合并区域的列表,因为从单元格/工作表中查询它非常耗时,因此跨单元格缓存列表可大大加快某些操作。)
|
static Cell |
getCellWithMerges(Sheet sheet, int rowIx, int colIx)
Return the cell, taking account of merged regions.
(返回单元格,考虑合并区域。)
|
static double |
getColumnWidth(Sheet sheet, int column, boolean useMergedCells)
Compute width of a column and return the result
(计算列宽并返回结果)
|
static double |
getColumnWidth(Sheet sheet, int column, boolean useMergedCells, int firstRow, int lastRow)
Compute width of a column based on a subset of the rows and return the result
(根据行的子集计算列的宽度并返回结果)
|
static int |
getDefaultCharWidth(Workbook wb)
Get default character width using the Workbook's default font
(使用工作簿的默认字体获取默认字符宽度)
|
public static double getCellWidth(Cell cell, int defaultCharWidth, DataFormatter formatter, boolean useMergedCells)
cell
- the cell whose width is to be calculated
(cell - 要计算其宽度的单元格)
defaultCharWidth
- the width of a single character
(defaultCharWidth - 单个字符的宽度)
formatter
- formatter used to prepare the text to be measured
(formatter - 用于准备要测量的文本的格式化程序)
useMergedCells
- whether to use merged cells
(useMergedCells - 是否使用合并单元格)
public static double getCellWidth(Cell cell, int defaultCharWidth, DataFormatter formatter, boolean useMergedCells, java.util.List<CellRangeAddress> mergedRegions)
cell
- the cell whose width is to be calculated
(cell - 要计算其宽度的单元格)
defaultCharWidth
- the width of a single character
(defaultCharWidth - 单个字符的宽度)
formatter
- formatter used to prepare the text to be measured
(formatter - 用于准备要测量的文本的格式化程序)
useMergedCells
- whether to use merged cells
(useMergedCells - 是否使用合并单元格)
mergedRegions
- The list of merged regions as received via cell.getSheet().getMergedRegions()
(mergeRegions - 通过 cell.getSheet().getMergedRegions() 接收的合并区域列表)
public static double getColumnWidth(Sheet sheet, int column, boolean useMergedCells)
sheet
- the sheet to calculate
(sheet - 要计算的工作表)
column
- 0-based index of the column
(column - 从 0 开始的列索引)
useMergedCells
- whether to use merged cells
(useMergedCells - 是否使用合并单元格)
public static double getColumnWidth(Sheet sheet, int column, boolean useMergedCells, int firstRow, int lastRow)
sheet
- the sheet to calculate
(sheet - 要计算的工作表)
column
- 0-based index of the column
(column - 从 0 开始的列索引)
useMergedCells
- whether to use merged cells
(useMergedCells - 是否使用合并单元格)
firstRow
- 0-based index of the first row to consider (inclusive)
(firstRow - 要考虑的第一行的从 0 开始的索引(包括))
lastRow
- 0-based index of the last row to consider (inclusive)
(lastRow - 要考虑的最后一行的从 0 开始的索引(包括))
@Internal public static int getDefaultCharWidth(Workbook wb)
wb
- the workbook to get the default character width from
(wb - 从中获取默认字符宽度的工作簿)
public static boolean canComputeColumnWidth(Font font)
font
- The Font that is used in the Cell
(font - 单元格中使用的字体)
public static Cell getCell(Sheet sheet, int rowIx, int colIx)
Use getCellWithMerges(Sheet, int, int)
if you want the top left cell from merged regions instead when the reference is a merged cell.
Use this where you want to know if the given cell is explicitly defined or not.
(返回单元格,不考虑合并区域。如果您想要来自合并区域的左上角单元格而不是引用是合并单元格时,请使用 getCellWithMerges(Sheet, int, int)。在您想知道给定单元格是否明确定义的地方使用它。)sheet
- The workbook sheet to look at.
(sheet - 要查看的工作簿表。)
rowIx
- The 0-based index of the row.
(rowIx - 行的从 0 开始的索引。)
colIx
- The 0-based index of the cell.
(colIx - 单元格的从 0 开始的索引。)
java.lang.NullPointerException
- if sheet is null
(java.lang.NullPointerException - 如果工作表为空)
public static Cell getCellWithMerges(Sheet sheet, int rowIx, int colIx)
If the cell at the given co-ordinates is a merged cell, this will return the primary (top-left) most cell of the merged region.
If the cell at the given co-ordinates is not in a merged region, then will return the cell itself.
If there is no cell defined at the given co-ordinates, will return null.
(返回单元格,考虑合并区域。允许您查找内容显示在工作表中给定位置的单元格。如果给定坐标处的单元格是合并单元格,则这将返回合并区域的主要(左上角)大多数单元格。如果给定坐标处的单元格不在合并区域中,则将返回单元格本身。如果在给定坐标处没有定义单元格,则返回 null。)sheet
- The workbook sheet to look at.
(sheet - 要查看的工作簿表。)
rowIx
- The 0-based index of the row.
(rowIx - 行的从 0 开始的索引。)
colIx
- The 0-based index of the cell.
(colIx - 单元格的从 0 开始的索引。)
java.lang.NullPointerException
- if sheet is null
(java.lang.NullPointerException - 如果工作表为空)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.