public interface Workbook extends java.io.Closeable, java.lang.Iterable<Sheet>
Modifier and Type | Field and Description |
---|---|
static int |
PICTURE_TYPE_DIB
Device independent bitmap
(设备无关位图)
|
static int |
PICTURE_TYPE_EMF
Extended windows meta file
(扩展的 windows 元文件)
|
static int |
PICTURE_TYPE_JPEG
JPEG format
(JPEG 格式)
|
static int |
PICTURE_TYPE_PICT
Mac PICT format
(Mac PICT 格式)
|
static int |
PICTURE_TYPE_PNG
PNG format
(PNG格式)
|
static int |
PICTURE_TYPE_WMF
Windows Meta File
(Windows 元文件)
|
Modifier and Type | Method and Description |
---|---|
int |
addOlePackage(byte[] oleData, java.lang.String label, java.lang.String fileName, java.lang.String command)
Adds an OLE package manager object with the given content to the sheet
(将具有给定内容的 OLE 包管理器对象添加到工作表)
|
int |
addPicture(byte[] pictureData, int format)
Adds a picture to the workbook.
(将图片添加到工作簿。)
|
void |
addToolPack(UDFFinder toopack)
Register a new toolpack in this workbook.
(在此工作簿中注册一个新的工具包。)
|
Sheet |
cloneSheet(int sheetNum)
Create a Sheet from an existing sheet in the Workbook.
(从工作簿中的现有工作表创建工作表。)
|
void |
close()
Close the underlying input resource (File or Stream), from which the Workbook was read.
(关闭从中读取工作簿的基础输入资源(文件或流)。)
|
CellStyle |
createCellStyle()
Create a new Cell style and add it to the workbook's style table
(创建一个新的单元格样式并将其添加到工作簿的样式表中)
|
DataFormat |
createDataFormat()
Returns the instance of DataFormat for this workbook.
(返回此工作簿的 DataFormat 实例。)
|
EvaluationWorkbook |
createEvaluationWorkbook() |
Font |
createFont()
Create a new Font and add it to the workbook's font table
(创建一个新字体并将其添加到工作簿的字体表中)
|
Name |
createName()
Creates a new (uninitialised) defined name in this workbook
(在此工作簿中创建一个新的(未初始化的)定义名称)
|
Sheet |
createSheet()
Create a Sheet for this Workbook, adds it to the sheets and returns the high level representation.
(为此工作簿创建一个工作表,将其添加到工作表并返回高级表示。)
|
Sheet |
createSheet(java.lang.String sheetname)
Create a new sheet for this Workbook and return the high level representation.
(为此工作簿创建一个新工作表并返回高级表示。)
|
Font |
findFont(boolean bold, short color, short fontHeight, java.lang.String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
Finds a font that matches the one with the supplied attributes
(查找与提供的属性匹配的字体)
|
int |
getActiveSheetIndex()
Convenience method to get the active sheet.
(获取活动工作表的便捷方法。)
|
java.util.List<? extends Name> |
getAllNames()
Returns all defined names.
(返回所有定义的名称。)
|
java.util.List<? extends PictureData> |
getAllPictures()
Gets all pictures from the Workbook.
(获取工作簿中的所有图片。)
|
CellStyle |
getCellStyleAt(int idx)
Get the cell style object at the given index
(获取给定索引处的单元格样式对象)
|
CreationHelper |
getCreationHelper()
Returns an object that handles instantiating concrete classes of the various instances one needs for HSSF and XSSF.
(返回一个对象,该对象处理实例化 HSSF 和 XSSF 所需的各种实例的具体类。)
|
int |
getFirstVisibleTab()
Gets the first tab that is displayed in the list of tabs in excel.
(获取在 excel 选项卡列表中显示的第一个选项卡。)
|
Font |
getFontAt(int idx)
Get the font at the given index number
(获取给定索引号的字体)
|
boolean |
getForceFormulaRecalculation()
Whether Excel will be asked to recalculate all formulas when the workbook is opened.
(打开工作簿时是否会要求 Excel 重新计算所有公式。)
|
Row.MissingCellPolicy |
getMissingCellPolicy()
Retrieves the current policy on what to do when getting missing or blank cells from a row.
(检索有关在一行中缺少单元格或空白单元格时要执行的操作的当前策略。)
|
Name |
getName(java.lang.String name) |
java.util.List<? extends Name> |
getNames(java.lang.String name)
Returns all defined names with the given name.
(返回具有给定名称的所有已定义名称。)
|
int |
getNumberOfFonts()
Get the number of fonts in the font table
(获取字体表中的字体数量)
|
int |
getNumberOfFontsAsInt()
Deprecated.
(已弃用。)
|
int |
getNumberOfNames() |
int |
getNumberOfSheets()
Get the number of spreadsheets in the workbook
(获取工作簿中电子表格的数量)
|
int |
getNumCellStyles()
Get the number of styles the workbook contains
(获取工作簿包含的样式数)
|
java.lang.String |
getPrintArea(int sheetIndex)
Retrieves the reference for the printarea of the specified sheet, the sheet name is appended to the reference even if it was not specified.
(检索指定工作表的打印区域的引用,工作表名称即使未指定,也会附加到引用中。)
|
Sheet |
getSheet(java.lang.String name)
Get sheet with the given name
(获取具有给定名称的工作表)
|
Sheet |
getSheetAt(int index)
Get the Sheet object at the given index.
(获取给定索引处的 Sheet 对象。)
|
int |
getSheetIndex(Sheet sheet)
Returns the index of the given sheet
(返回给定工作表的索引)
|
int |
getSheetIndex(java.lang.String name)
Returns the index of the sheet by his name
(按他的名字返回工作表的索引)
|
java.lang.String |
getSheetName(int sheet)
Get the sheet name
(获取工作表名称)
|
SheetVisibility |
getSheetVisibility(int sheetIx)
Get the visibility (visible, hidden, very hidden) of a sheet in this workbook
(获取此工作簿中工作表的可见性(可见、隐藏、非常隐藏))
|
SpreadsheetVersion |
getSpreadsheetVersion()
Returns the spreadsheet version of this workbook
(返回此工作簿的电子表格版本)
|
boolean |
isHidden() |
boolean |
isSheetHidden(int sheetIx)
Check whether a sheet is hidden.
(检查工作表是否隐藏。)
|
boolean |
isSheetVeryHidden(int sheetIx)
Check whether a sheet is very hidden.
(检查工作表是否非常隐藏。)
|
int |
linkExternalWorkbook(java.lang.String name, Workbook workbook)
Adds the linking required to allow formulas referencing the specified external workbook to be added to this one.
(添加允许将引用指定外部工作簿的公式添加到此工作簿所需的链接。)
|
void |
removeName(Name name)
Remove a defined name
(删除定义的名称)
|
void |
removePrintArea(int sheetIndex)
Delete the printarea for the sheet specified
(删除指定工作表的打印区域)
|
void |
removeSheetAt(int index)
Removes sheet at the given index
(删除给定索引处的工作表)
|
void |
setActiveSheet(int sheetIndex)
Convenience method to set the active sheet.
(设置活动工作表的便捷方法。)
|
void |
setFirstVisibleTab(int sheetIndex)
Sets the first tab that is displayed in the list of tabs in excel.
(设置在 excel 选项卡列表中显示的第一个选项卡。)
|
void |
setForceFormulaRecalculation(boolean value)
Whether the application shall perform a full recalculation when the workbook is opened.
(打开工作簿时应用程序是否应执行完全重新计算。)
|
void |
setHidden(boolean hiddenFlag) |
void |
setMissingCellPolicy(Row.MissingCellPolicy missingCellPolicy)
Sets the policy on what to do when getting missing or blank cells from a row.
(设置有关在一行中缺少单元格或空白单元格时要执行的操作的策略。)
|
void |
setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
For the Convenience of Java Programmers maintaining pointers.
(为了方便 Java 程序员维护指针。)
|
void |
setPrintArea(int sheetIndex, java.lang.String reference)
Sets the printarea for the sheet provided
(设置提供的工作表的打印区域)
|
void |
setSelectedTab(int index)
Sets the tab whose data is actually seen when the sheet is opened.
(设置打开工作表时实际看到其数据的选项卡。)
|
void |
setSheetHidden(int sheetIx, boolean hidden)
Hide or unhide a sheet.
(隐藏或取消隐藏工作表。)
|
void |
setSheetName(int sheet, java.lang.String name)
Set the sheet name.
(设置工作表名称。)
|
void |
setSheetOrder(java.lang.String sheetname, int pos)
Sets the order of appearance for a given sheet.
(设置给定工作表的出现顺序。)
|
void |
setSheetVisibility(int sheetIx, SheetVisibility visibility)
Hide or unhide a sheet.
(隐藏或取消隐藏工作表。)
|
java.util.Iterator<Sheet> |
sheetIterator()
Returns an iterator of the sheets in the workbook in sheet order.
(按工作表顺序返回工作簿中工作表的迭代器。)
|
void |
write(java.io.OutputStream stream)
Write out this workbook to an Outputstream.
(将此工作簿写入输出流。)
|
static final int PICTURE_TYPE_EMF
static final int PICTURE_TYPE_WMF
static final int PICTURE_TYPE_PICT
static final int PICTURE_TYPE_JPEG
static final int PICTURE_TYPE_PNG
static final int PICTURE_TYPE_DIB
int getActiveSheetIndex()
void setActiveSheet(int sheetIndex)
sheetIndex
- index of the active sheet (0-based)
(sheetIndex - 活动工作表的索引(从 0 开始))
int getFirstVisibleTab()
void setFirstVisibleTab(int sheetIndex)
sheetIndex
- the first tab that to display in the list of tabs (0-based)
(sheetIndex - 在选项卡列表中显示的第一个选项卡(从 0 开始))
void setSheetOrder(java.lang.String sheetname, int pos)
sheetname
- the name of the sheet to reorder
(sheetname - 要重新排序的工作表的名称)
pos
- the position that we want to insert the sheet into (0 based)
(pos - 我们要将工作表插入的位置(基于 0))
void setSelectedTab(int index)
index
- the index of the sheet to select (0 based)
(index - 要选择的工作表的索引(基于 0))
Sheet.setSelected(boolean)
void setSheetName(int sheet, java.lang.String name)
See WorkbookUtil.createSafeSheetName(String nameProposal)
for a safe way to create valid names
sheet
- number (0 based)
(工作表 - 编号(基于 0))
java.lang.IllegalArgumentException
- if the name is null or invalid or workbook already contains a sheet with this name
(java.lang.IllegalArgumentException - 如果名称为 null 或无效,或者工作簿已包含具有此名称的工作表)
createSheet(String)
,
WorkbookUtil.createSafeSheetName(String nameProposal)
java.lang.String getSheetName(int sheet)
sheet
- sheet number (0 based)
(工作表 - 工作表编号(从 0 开始))
int getSheetIndex(java.lang.String name)
name
- the sheet name
(name - 工作表名称)
int getSheetIndex(Sheet sheet)
sheet
- the sheet to look up
(sheet - 要查找的工作表)
Sheet createSheet()
Sheet createSheet(java.lang.String sheetname)
Note that Excel allows sheet names up to 31 chars in length but other applications (such as OpenOffice) allow more. Some versions of Excel crash with names longer than 31 chars, others - truncate such names to 31 character.
POI's SpreadsheetAPI silently truncates the input argument to 31 characters. Example:
Sheet sheet = workbook.createSheet("My very long sheet name which is longer than 31 chars"); // will be truncated
assert 31 == sheet.getSheetName().length();
assert "My very long sheet name which i" == sheet.getSheetName();
Except the 31-character constraint, Excel applies some other rules:
Sheet name MUST be unique in the workbook and MUST NOT contain the any of the following characters:
See WorkbookUtil.createSafeSheetName(String nameProposal)
for a safe way to create valid names
sheetname
- The name to set for the sheet.
(sheetname - 为工作表设置的名称。)
java.lang.IllegalArgumentException
- if the name is null or invalid or workbook already contains a sheet with this name
(java.lang.IllegalArgumentException - 如果名称为 null 或无效,或者工作簿已包含具有此名称的工作表)
WorkbookUtil.createSafeSheetName(String nameProposal)
Sheet cloneSheet(int sheetNum)
java.util.Iterator<Sheet> sheetIterator()
int getNumberOfSheets()
Sheet getSheetAt(int index)
index
- of the sheet number (0-based physical & logical)
(index - 工作表编号(基于 0 的物理和逻辑))
java.lang.IllegalArgumentException
- if the index is out of range (index < 0 || index >= getNumberOfSheets()).
(java.lang.IllegalArgumentException - 如果索引超出范围(索引 < 0 || 索引 >= getNumberOfSheets())。)
Sheet getSheet(java.lang.String name)
name
- of the sheet
(名称 - 工作表)
null
if it does not exist
(具有提供的名称的工作表,如果不存在,则为 null)
void removeSheetAt(int index)
index
- of the sheet to remove (0-based)
(index - 要删除的工作表(从 0 开始))
Font createFont()
Font findFont(boolean bold, short color, short fontHeight, java.lang.String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
null
(具有匹配属性的字体或 null)
int getNumberOfFonts()
@Deprecated @Removal(version="6.0.0") int getNumberOfFontsAsInt()
Font getFontAt(int idx)
idx
- index number (0-based)
(idx - 索引号(从 0 开始))
CellStyle createCellStyle()
java.lang.IllegalStateException
- if the number of cell styles exceeded the limit for this type of Workbook.
(java.lang.IllegalStateException - 如果单元格样式的数量超过了此类工作簿的限制。)
int getNumCellStyles()
CellStyle getCellStyleAt(int idx)
idx
- index within the set of styles (0-based)
(idx - 样式集中的索引(从 0 开始))
void write(java.io.OutputStream stream) throws java.io.IOException
stream
- - the java OutputStream you wish to write to
(stream - - 你想写入的 java OutputStream)
java.io.IOException
- if anything can't be written.
(java.io.IOException - 如果无法写入任何内容。)
void close() throws java.io.IOException
Once this has been called, no further operations, updates or reads should be performed on the Workbook.
(关闭从中读取工作簿的基础输入资源(文件或流)。一旦调用了它,就不应在工作簿上执行进一步的操作、更新或读取。)close
in interface
java.lang.AutoCloseable
(在接口 java.lang.AutoCloseable 中关闭)
close
in interface
java.io.Closeable
(在接口 java.io.Closeable 中关闭)
java.io.IOException
(java.io.IOException)
int getNumberOfNames()
Name getName(java.lang.String name)
name
- the name of the defined name
(name - 已定义名称的名称)
null
if not found.
(具有指定名称的已定义名称。如果未找到,则为 null。)
java.util.List<? extends Name> getNames(java.lang.String name)
name
- the name of the defined name
(name - 已定义名称的名称)
java.util.List<? extends Name> getAllNames()
Name createName()
void removeName(Name name)
name
- the name of the defined name
(name - 已定义名称的名称)
int linkExternalWorkbook(java.lang.String name, Workbook workbook)
In order for formulas such as "[MyOtherWorkbook]Sheet3!$A$5" to be added to the file, some linking information must first be recorded. Once a given external workbook has been linked, then formulas using it can added. Each workbook needs linking only once.
This linking only applies for writing formulas. To link things for evaluation, see FormulaEvaluator.setupReferencedWorkbooks(java.util.Map)
name
- The name the workbook will be referenced as in formulas
(name - 将在公式中引用工作簿的名称)
workbook
- The open workbook to fetch the link required information from
(工作簿 - 用于从中获取链接所需信息的打开工作簿)
void setPrintArea(int sheetIndex, java.lang.String reference)
i.e. Reference = $A$1:$B$2
(设置提供的工作表的打印区域,即参考 = $A$1:$B$2)sheetIndex
- Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
(sheetIndex - 从零开始的工作表索引(0 表示与 java 保持一致的第一个工作表))
reference
- Valid name Reference for the Print Area
(参考 - 打印区域的有效名称参考)
void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
sheetIndex
- Zero-based sheet index (0 = First Sheet)
(sheetIndex - 从零开始的工作表索引(0 = 第一个工作表))
startColumn
- Column to begin printarea
(startColumn - 列开始 printarea)
endColumn
- Column to end the printarea
(endColumn - 结束打印区域的列)
startRow
- Row to begin the printarea
(startRow - 开始打印区域的行)
endRow
- Row to end the printarea
(endRow - 结束打印区域的行)
setPrintArea(int, String)
java.lang.String getPrintArea(int sheetIndex)
sheetIndex
- Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
(sheetIndex - 从零开始的工作表索引(0 表示与 java 保持一致的第一个工作表))
void removePrintArea(int sheetIndex)
sheetIndex
- Zero-based sheet index (0 = First Sheet)
(sheetIndex - 从零开始的工作表索引(0 = 第一个工作表))
Row.MissingCellPolicy getMissingCellPolicy()
The default is to return blank and null cells. Row.MissingCellPolicy
void setMissingCellPolicy(Row.MissingCellPolicy missingCellPolicy)
Row.getCell(int)
}. See
Row.MissingCellPolicy
(设置有关在一行中缺少单元格或空白单元格时要执行的操作的策略。然后,这将适用于对 Row.getCell(int) } 的所有调用。请参见 Row.MissingCellPolicy)
DataFormat createDataFormat()
int addPicture(byte[] pictureData, int format)
pictureData
- The bytes of the picture
(pictureData - 图片的字节数)
format
- The format of the picture.
(format - 图片的格式。)
PICTURE_TYPE_EMF
,
PICTURE_TYPE_WMF
,
PICTURE_TYPE_PICT
,
PICTURE_TYPE_JPEG
,
PICTURE_TYPE_PNG
,
PICTURE_TYPE_DIB
java.util.List<? extends PictureData> getAllPictures()
PictureData
objects.)
(图片列表(PictureData 对象列表。))
CreationHelper getCreationHelper()
boolean isHidden()
false
if this workbook is not visible in the GUI
(如果此工作簿在 GUI 中不可见,则为 false)
void setHidden(boolean hiddenFlag)
hiddenFlag
- pass
false
to make the workbook visible in the GUI
(hiddenFlag - 传递 false 以使工作簿在 GUI 中可见)
boolean isSheetHidden(int sheetIx)
Note that a sheet could instead be set to be very hidden, which is different (isSheetVeryHidden(int)
)
sheetIx
- Number
(sheetIx - 编号)
true
if sheet is hidden
(如果工作表被隐藏,则为真)
getSheetVisibility(int)
boolean isSheetVeryHidden(int sheetIx)
This is different from the normal hidden status (isSheetHidden(int)
)
sheetIx
- sheet index to check
(sheetIx - 要检查的工作表索引)
true
if sheet is very hidden
(如果工作表非常隐藏,则为 true)
getSheetVisibility(int)
void setSheetHidden(int sheetIx, boolean hidden)
sheetIx
- the sheet index (0-based)
(sheetIx - 工作表索引(从 0 开始))
hidden
- True to mark the sheet as hidden, false otherwise
(hidden - True 将工作表标记为隐藏,否则为 false)
setSheetVisibility(int, SheetVisibility)
SheetVisibility getSheetVisibility(int sheetIx)
sheetIx
- the index of the sheet
(sheetIx - 工作表的索引)
void setSheetVisibility(int sheetIx, SheetVisibility visibility)
sheetIx
- the sheet index (0-based)
(sheetIx - 工作表索引(从 0 开始))
visibility
- the sheet visibility to set
(visibility - 要设置的工作表可见性)
void addToolPack(UDFFinder toopack)
toopack
- the toolpack to register
(Toopack - 要注册的工具包)
void setForceFormulaRecalculation(boolean value)
Typically you want to force formula recalculation when you modify cell formulas or values of a workbook previously created by Excel. When set to true, this flag will tell Excel that it needs to recalculate all formulas in the workbook the next time the file is opened.
Note, that recalculation updates cached formula results and, thus, modifies the workbook. Depending on the version, Excel may prompt you with "Do you want to save the changes in filename?" on close.
(打开工作簿时应用程序是否应执行完全重新计算。通常,当您修改以前由 Excel 创建的工作簿的单元格公式或值时,您希望强制重新计算公式。当设置为 true 时,此标志将告诉 Excel 在下次打开文件时需要重新计算工作簿中的所有公式。请注意,重新计算会更新缓存的公式结果,因此会修改工作簿。根据版本,Excel 可能会提示您“是否要保存文件名中的更改?”关闭。)value
- true if the application will perform a full recalculation of workbook values when the workbook is opened
(value - 如果应用程序将在打开工作簿时完全重新计算工作簿值,则为 true)
boolean getForceFormulaRecalculation()
SpreadsheetVersion getSpreadsheetVersion()
int addOlePackage(byte[] oleData, java.lang.String label, java.lang.String fileName, java.lang.String command) throws java.io.IOException
oleData
- the payload
(oleData - 有效载荷)
label
- the label of the payload
(label - 有效负载的标签)
fileName
- the original filename
(fileName - 原始文件名)
command
- the command to open the payload
(command - 打开有效载荷的命令)
java.io.IOException
- if the object can't be embedded
(java.io.IOException - 如果无法嵌入对象)
EvaluationWorkbook createEvaluationWorkbook()
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.