public abstract class OPCPackage extends java.lang.Object implements RelationshipSource, java.io.Closeable
Modifier and Type | Field and Description |
---|---|
protected ContentTypeManager |
contentTypeManager
Manage parts content types of this package.
(管理此包的部件内容类型。)
|
protected static PackageAccess |
defaultPackageAccess
Default package access.
(默认包访问。)
|
protected PartMarshaller |
defaultPartMarshaller
Default part marshaller.
(默认部分编组器。)
|
protected boolean |
isDirty
Flag if a modification is done to the document.
(标记是否对文档进行了修改。)
|
protected java.lang.String |
originalPackagePath
File path of this package.
(此包的文件路径。)
|
protected java.io.OutputStream |
output
Output stream for writing this package.
(用于编写此包的输出流。)
|
protected PackagePropertiesPart |
packageProperties
Core package properties.
(核心包属性。)
|
protected java.util.Map<ContentType,PartMarshaller> |
partMarshallers
Part marshallers by content type.
(按内容类型划分的部分编组器。)
|
protected java.util.Map<ContentType,PartUnmarshaller> |
partUnmarshallers
Part unmarshallers by content type.
(按内容类型的部分解组器。)
|
protected PackageRelationshipCollection |
relationships
Package relationships.
(包关系。)
|
Modifier and Type | Method and Description |
---|---|
PackageRelationship |
addExternalRelationship(java.lang.String target, java.lang.String relationshipType)
Adds an external relationship to a part (except relationships part).
(将外部关系添加到零件(关系零件除外)。)
|
PackageRelationship |
addExternalRelationship(java.lang.String target, java.lang.String relationshipType, java.lang.String id)
Adds an external relationship to a part (except relationships part).
(将外部关系添加到零件(关系零件除外)。)
|
void |
addMarshaller(java.lang.String contentType, PartMarshaller marshaller)
Add a marshaller.
(添加编组器。)
|
protected PackagePart |
addPackagePart(PackagePart part)
Add the specified part to the package.
(将指定部件添加到包中。)
|
PackageRelationship |
addRelationship(PackagePartName targetPartName, TargetMode targetMode, java.lang.String relationshipType)
Add a package relationship.
(添加包关系。)
|
PackageRelationship |
addRelationship(PackagePartName targetPartName, TargetMode targetMode, java.lang.String relationshipType, java.lang.String relID)
Add a relationship to the package (except relationships part).
(向包中添加关系(关系部分除外)。)
|
void |
addThumbnail(java.lang.String path)
Add a thumbnail to the package.
(将缩略图添加到包中。)
|
void |
addThumbnail(java.lang.String filename, java.io.InputStream data)
Add a thumbnail to the package.
(将缩略图添加到包中。)
|
void |
addUnmarshaller(java.lang.String contentType, PartUnmarshaller unmarshaller)
Add an unmarshaller.
(添加解组器。)
|
void |
clearRelationships()
Clear package relationships.
(清除包关系。)
|
void |
close()
Close the open, writable package and save its content.
(关闭打开的可写包并保存其内容。)
|
protected abstract void |
closeImpl()
Close the package and cause a save of the package.
(关闭包并保存包。)
|
boolean |
containPart(PackagePartName partName)
Check if a part already exists in this package from its name.
(从其名称检查此包中是否已存在部件。)
|
static OPCPackage |
create(java.io.File file)
Creates a new package.
(创建一个新包。)
|
static OPCPackage |
create(java.io.OutputStream output) |
static OPCPackage |
create(java.lang.String path)
Creates a new package.
(创建一个新包。)
|
PackagePart |
createPart(PackagePartName partName, java.lang.String contentType)
Create and add a part, with the specified name and content type, to the package.
(创建具有指定名称和内容类型的部件并将其添加到包中。)
|
PackagePart |
createPart(PackagePartName partName, java.lang.String contentType, java.io.ByteArrayOutputStream content)
Add a part to the package.
(将零件添加到包中。)
|
protected abstract PackagePart |
createPartImpl(PackagePartName partName, java.lang.String contentType, boolean loadRelationships)
Core method to create a package part.
(创建包部件的核心方法。)
|
void |
deletePart(PackagePartName partName)
Delete the part with the specified name and its associated relationships part if one exists.
(删除具有指定名称的部件及其关联关系部件(如果存在)。)
|
void |
deletePartRecursive(PackagePartName partName)
Delete the part with the specified name and all part listed in its associated relationships part if one exists.
(删除具有指定名称的部件及其关联关系部件中列出的所有部件(如果存在)。)
|
void |
ensureRelationships()
Ensure that the relationships collection is not null.
(确保关系集合不为空。)
|
void |
flush()
Flush the package : save all.
(冲洗包装:全部保存。)
|
protected abstract void |
flushImpl()
Flush the package but not save.
(刷新包但不保存。)
|
PackageAccess |
getPackageAccess()
Get the package access mode.
(获取包访问模式。)
|
PackageProperties |
getPackageProperties()
Retrieves or creates if none exists, core package property part.
(如果不存在,则检索或创建核心包属性部分。)
|
PackagePart |
getPart(PackagePartName partName)
Retrieve a part identified by its name.
(检索由其名称标识的部件。)
|
PackagePart |
getPart(PackageRelationship partRel)
Get the target part from the specified relationship.
(从指定的关系中获取目标零件。)
|
java.util.ArrayList<PackagePart> |
getParts()
Load the parts of the archive if it has not been done yet.
(如果尚未完成,请加载存档的部分。)
|
java.util.ArrayList<PackagePart> |
getPartsByContentType(java.lang.String contentType)
Retrieve parts by content type.
(按内容类型检索部件。)
|
java.util.List<PackagePart> |
getPartsByName(java.util.regex.Pattern namePattern)
Retrieve parts by name
(按名称检索零件)
|
java.util.ArrayList<PackagePart> |
getPartsByRelationshipType(java.lang.String relationshipType)
Retrieve parts by relationship type.
(按关系类型检索零件。)
|
protected abstract PackagePartCollection |
getPartsImpl()
Get all parts link to the package.
(获取包的所有部件链接。)
|
PackageRelationship |
getRelationship(java.lang.String id)
Retrieves a package relationship from its id.
(从其 id 检索包关系。)
|
PackageRelationshipCollection |
getRelationships()
Retrieves all package relationships.
(检索所有包关系。)
|
PackageRelationshipCollection |
getRelationshipsByType(java.lang.String relationshipType)
Retrieves all relationships with the specified type.
(检索具有指定类型的所有关系。)
|
int |
getUnusedPartIndex(java.lang.String nameTemplate)
Get an unused part index based on the namePattern, which doesn't exist yet and has the lowest positive index
(根据 namePattern 获取未使用的零件索引,该零件索引尚不存在且具有最低的正索引)
|
boolean |
hasRelationships()
Knows if the part have any relationships.
(知道零件是否有任何关系。)
|
abstract boolean |
isClosed()
Has close been called already?
(close 已经被调用了吗?)
|
boolean |
isRelationshipExists(PackageRelationship rel)
Checks if the specified relationship is part of this package part.
(检查指定的关系是否是此包部分的一部分。)
|
static OPCPackage |
open(java.io.File file)
Open a package with read/write permission.
(打开具有读/写权限的包。)
|
static OPCPackage |
open(java.io.File file, PackageAccess access)
Open a package.
(打开一个包裹。)
|
static OPCPackage |
open(java.io.InputStream in)
Open a package.
(打开一个包裹。)
|
static OPCPackage |
open(java.lang.String path)
Open a package with read/write permission.
(打开具有读/写权限的包。)
|
static OPCPackage |
open(java.lang.String path, PackageAccess access)
Open a package.
(打开一个包裹。)
|
static OPCPackage |
open(ZipEntrySource zipEntry)
Open an user provided
ZipEntrySource with read-only permission.
(打开具有只读权限的用户提供的 ZipEntrySource。)
|
static OPCPackage |
openOrCreate(java.io.File file)
Opens a package if it exists, else it creates one.
(如果存在,则打开一个包,否则创建一个。)
|
void |
registerPartAndContentType(PackagePart part)
Add the specified part, and register its content type with the content type manager.
(添加指定的部分,并将其内容类型注册到内容类型管理器。)
|
void |
removeMarshaller(java.lang.String contentType)
Remove a marshaller by its content type.
(按内容类型删除编组器。)
|
void |
removePart(PackagePart part)
Remove the specified part in this package.
(删除此包中的指定部分。)
|
void |
removePart(PackagePartName partName)
Remove a part in this package.
(删除此包中的一部分。)
|
protected abstract void |
removePartImpl(PackagePartName partName)
Core method to delete a package part.
(删除包部分的核心方法。)
|
void |
removePartRecursive(PackagePartName partName)
Remove a part from this package as well as its relationship part, if one exists, and all parts listed in the relationship part.
(从此包中删除零件及其关系零件(如果存在)以及关系零件中列出的所有零件。)
|
void |
removeRelationship(java.lang.String id)
Delete a relationship from this package.
(从此包中删除关系。)
|
void |
removeUnmarshaller(java.lang.String contentType)
Remove an unmarshaller by its content type.
(按内容类型删除解组器。)
|
boolean |
replaceContentType(java.lang.String oldContentType, java.lang.String newContentType)
Replace a content type in this package.
(替换此包中的内容类型。)
|
void |
revert()
Close the package WITHOUT saving its content.
(关闭包而不保存其内容。)
|
protected abstract void |
revertImpl()
Close the package without saving the document.
(关闭包而不保存文档。)
|
void |
save(java.io.File targetFile)
Save the document in the specified file.
(将文档保存在指定的文件中。)
|
void |
save(java.io.OutputStream outputStream)
Save the document in the specified output stream.
(将文档保存在指定的输出流中。)
|
protected abstract void |
saveImpl(java.io.OutputStream outputStream)
Save the package into the specified output stream.
(将包保存到指定的输出流中。)
|
void |
unregisterPartAndContentType(PackagePartName partName)
Remove the specified part, and clear its content type from the content type manager.
(移除指定部分,并从内容类型管理器中清除其内容类型。)
|
boolean |
validatePackage(OPCPackage pkg)
Validates the package compliance with the OPC specifications.
(验证包是否符合 OPC 规范。)
|
protected static final PackageAccess defaultPackageAccess
protected PackageRelationshipCollection relationships
protected final java.util.Map<ContentType,PartMarshaller> partMarshallers
protected final PartMarshaller defaultPartMarshaller
protected final java.util.Map<ContentType,PartUnmarshaller> partUnmarshallers
protected PackagePropertiesPart packageProperties
protected ContentTypeManager contentTypeManager
protected boolean isDirty
protected java.lang.String originalPackagePath
protected java.io.OutputStream output
public static OPCPackage open(java.lang.String path) throws InvalidFormatException
path
- The document path.
(path - 文档路径。)
InvalidFormatException
- If the specified file doesn't exist, and a parsing error occur.
(InvalidFormatException - 如果指定的文件不存在,并且发生解析错误。)
public static OPCPackage open(java.io.File file) throws InvalidFormatException
file
- The file to open.
(file - 要打开的文件。)
InvalidFormatException
- If the specified file doesn't exist, and a parsing error occur.
(InvalidFormatException - 如果指定的文件不存在,并且发生解析错误。)
public static OPCPackage open(ZipEntrySource zipEntry) throws InvalidFormatException
ZipEntrySource
with read-only permission. This method can be used to stream data into POI. Opposed to other open variants, the data is read as-is, e.g. there aren't any zip-bomb protection put in place.
(打开具有只读权限的用户提供的 ZipEntrySource。此方法可用于将数据流式传输到 POI。与其他开放变体相反,数据按原样读取,例如,没有任何 zip-bomb 保护到位。)
zipEntry
- the custom source
(zipEntry - 自定义源)
InvalidFormatException
- if a parsing error occur.
(InvalidFormatException - 如果发生解析错误。)
public static OPCPackage open(java.lang.String path, PackageAccess access) throws InvalidFormatException, InvalidOperationException
path
- The document path.
(path - 文档路径。)
access
- PackageBase access.
(访问 - PackageBase 访问。)
InvalidFormatException
- If the specified file doesn't exist, and a parsing error occur.
(InvalidFormatException - 如果指定的文件不存在,并且发生解析错误。)
InvalidOperationException
- If the zip file cannot be opened.
(InvalidOperationException - 如果 zip 文件无法打开。)
InvalidFormatException
- if the package is not valid.
(InvalidFormatException - 如果包无效。)
public static OPCPackage open(java.io.File file, PackageAccess access) throws InvalidFormatException
file
- The file to open.
(file - 要打开的文件。)
access
- PackageBase access.
(访问 - PackageBase 访问。)
InvalidFormatException
- If the specified file doesn't exist, and a parsing error occur.
(InvalidFormatException - 如果指定的文件不存在,并且发生解析错误。)
public static OPCPackage open(java.io.InputStream in) throws InvalidFormatException, java.io.IOException
open(String)
, which doesn't need to hold the whole zip file in memory, and can take advantage of native methods
(打开一个包裹。注意 - 使用比 open(String) 更多的内存,它不需要将整个 zip 文件保存在内存中,并且可以利用本地方法)
in
- The InputStream to read the package from
(in - 要从中读取包的 InputStream)
InvalidFormatException
- Throws if the specified file exist and is not valid.
(InvalidFormatException - 如果指定的文件存在且无效则抛出。)
java.io.IOException
- If reading the stream fails
(java.io.IOException - 如果读取流失败)
public static OPCPackage openOrCreate(java.io.File file) throws InvalidFormatException
file
- The file to open or to create.
(file - 要打开或创建的文件。)
InvalidFormatException
- Throws if the specified file exist and is not valid.
(InvalidFormatException - 如果指定的文件存在且无效则抛出。)
public static OPCPackage create(java.lang.String path)
path
- Path of the document.
(path - 文档的路径。)
public static OPCPackage create(java.io.File file)
file
- Path of the document.
(file - 文档的路径。)
public static OPCPackage create(java.io.OutputStream output)
public void flush()
close()
public void close() throws java.io.IOException
revert()
when finished with the package. This method is not thread-safe.
(关闭打开的可写包并保存其内容。如果您的包是只读打开的,那么您应该在完成包后调用 revert()。此方法不是线程安全的。)
close
in interface
java.io.Closeable
(在接口 java.io.Closeable 中关闭)
close
in interface
java.lang.AutoCloseable
(在接口 java.lang.AutoCloseable 中关闭)
java.io.IOException
- If an IO exception occur during the saving process.
(java.io.IOException - 如果在保存过程中发生 IO 异常。)
public void revert()
public void addThumbnail(java.lang.String path) throws java.io.IOException
path
- The full path to the image file.
(path - 图像文件的完整路径。)
java.io.IOException
(java.io.IOException)
public void addThumbnail(java.lang.String filename, java.io.InputStream data) throws java.io.IOException
filename
- The full path to the image file.
(文件名 - 图像文件的完整路径。)
data
- the image data
(data - 图像数据)
java.io.IOException
(java.io.IOException)
public PackageProperties getPackageProperties() throws InvalidFormatException
InvalidFormatException
(无效格式异常)
public PackagePart getPart(PackagePartName partName)
partName
- Part name of the part to retrieve.
(partName - 要检索的部件的部件名称。)
null
.
(具有指定名称的部分,否则为空。)
public java.util.ArrayList<PackagePart> getPartsByContentType(java.lang.String contentType)
contentType
- The content type criteria.
(contentType - 内容类型标准。)
public java.util.ArrayList<PackagePart> getPartsByRelationshipType(java.lang.String relationshipType)
relationshipType
- Relationship type. Must not be
null
.
(relationshipType - 关系类型。不得为空。)
InvalidOperationException
- If called on a write-only package.
(InvalidOperationException - 如果在只写包上调用。)
java.lang.IllegalArgumentException
- if relationshipType input param is null.
(java.lang.IllegalArgumentException - 如果 relationshipType 输入参数为空。)
public java.util.List<PackagePart> getPartsByName(java.util.regex.Pattern namePattern)
namePattern
- The pattern for matching the names
(namePattern - 匹配名称的模式)
public PackagePart getPart(PackageRelationship partRel)
partRel
- The part relationship uses to retrieve the part.
(partRel - 零件关系用于检索零件。)
public java.util.ArrayList<PackagePart> getParts() throws InvalidFormatException
InvalidFormatException
- if the package is not valid.
(InvalidFormatException - 如果包无效。)
public PackagePart createPart(PackagePartName partName, java.lang.String contentType)
partName
- Part name.
(partName - 部件名称。)
contentType
- Part content type.
(contentType - 部件内容类型。)
PartAlreadyExistsException
- If rule M1.12 is not verified : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names.
(PartAlreadyExistsException - 如果未验证规则 M1.12:包不应包含等效的部件名称,并且包实现者不应创建或识别具有等效部件名称的包。)
createPartImpl(PackagePartName, String, boolean)
public PackagePart createPart(PackagePartName partName, java.lang.String contentType, java.io.ByteArrayOutputStream content)
partName
- Part name of the part to create.
(partName - 要创建的零件的零件名称。)
contentType
- type associated with the file
(contentType - 与文件关联的类型)
content
- the contents to add. In order to have faster operation in document merge, the data are stored in memory not on a hard disk
(content - 要添加的内容。为了在文档合并中进行更快的操作,数据存储在内存中而不是硬盘上)
createPart(PackagePartName, String)
protected PackagePart addPackagePart(PackagePart part)
part
- The part to add (or replace).
(part - 要添加(或替换)的部分。)
InvalidOperationException
- If rule M1.12 is not verified : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names.
(InvalidOperationException - 如果未验证规则 M1.12:包不应包含等效的部件名称,并且包实施者不应创建或识别具有等效部件名称的包。)
public void removePart(PackagePart part)
part
- The part to remove. If
null
, skip the action.
(part - 要删除的部分。如果为 null,则跳过该操作。)
removePart(PackagePartName)
public void removePart(PackagePartName partName)
partName
- The part name of the part to remove.
(partName - 要移除的部件的部件名称。)
public void removePartRecursive(PackagePartName partName) throws InvalidFormatException
partName
- The name of the part to delete.
(partName - 要删除的部分的名称。)
InvalidFormatException
- Throws if the associated relationship part of the specified part is not valid.
(InvalidFormatException - 如果指定部分的关联关系部分无效,则引发。)
public void deletePart(PackagePartName partName)
partName
- Name of the part to delete
(partName - 要删除的部分的名称)
public void deletePartRecursive(PackagePartName partName)
partName
- Name of the part to delete
(partName - 要删除的部分的名称)
public boolean containPart(PackagePartName partName)
partName
- Part name to check.
(partName - 要检查的部件名称。)
public PackageRelationship addRelationship(PackagePartName targetPartName, TargetMode targetMode, java.lang.String relationshipType, java.lang.String relID)
addRelationship
in interface
RelationshipSource
(接口RelationshipSource中的addRelationship)
targetPartName
- Target part name.
(targetPartName - 目标部件名称。)
targetMode
- Target mode, either Internal or External.
(targetMode - 目标模式,内部或外部。)
relationshipType
- Relationship type.
(relationshipType - 关系类型。)
relID
- ID of the relationship.
(relID - 关系的 ID。)
PackageRelationshipTypes
public PackageRelationship addRelationship(PackagePartName targetPartName, TargetMode targetMode, java.lang.String relationshipType)
addRelationship
in interface
RelationshipSource
(接口RelationshipSource中的addRelationship)
targetPartName
- Target part name.
(targetPartName - 目标部件名称。)
targetMode
- Target mode, either Internal or External.
(targetMode - 目标模式,内部或外部。)
relationshipType
- Relationship type.
(relationshipType - 关系类型。)
PackageRelationshipTypes
public PackageRelationship addExternalRelationship(java.lang.String target, java.lang.String relationshipType)
addExternalRelationship
in interface
RelationshipSource
(接口RelationshipSource中的addExternalRelationship)
target
- External target of the relationship
(target - 关系的外部目标)
relationshipType
- Type of relationship.
(relationshipType - 关系类型。)
RelationshipSource.addExternalRelationship(java.lang.String, java.lang.String)
public PackageRelationship addExternalRelationship(java.lang.String target, java.lang.String relationshipType, java.lang.String id)
addExternalRelationship
in interface
RelationshipSource
(接口RelationshipSource中的addExternalRelationship)
target
- External target of the relationship
(target - 关系的外部目标)
relationshipType
- Type of relationship.
(relationshipType - 关系类型。)
id
- Relationship unique id.
(id - 关系唯一 ID。)
RelationshipSource.addExternalRelationship(java.lang.String, java.lang.String)
public void removeRelationship(java.lang.String id)
removeRelationship
in interface
RelationshipSource
(接口RelationshipSource中的removeRelationship)
id
- Id of the relationship to delete.
(id - 要删除的关系的 ID。)
public PackageRelationshipCollection getRelationships()
getRelationships
in interface
RelationshipSource
(接口RelationshipSource中的getRelationships)
InvalidOperationException
- if a read operation is done on a write only package.
(InvalidOperationException - 如果对只写包执行读取操作。)
getRelationshipsHelper(String)
public PackageRelationshipCollection getRelationshipsByType(java.lang.String relationshipType)
getRelationshipsByType
in interface
RelationshipSource
(接口RelationshipSource中的getRelationshipsByType)
relationshipType
- The filter specifying the relationship type.
(relationshipType - 指定关系类型的过滤器。)
public void clearRelationships()
clearRelationships
in interface
RelationshipSource
(接口RelationshipSource中的clearRelationships)
public void ensureRelationships()
public PackageRelationship getRelationship(java.lang.String id)
RelationshipSource
getRelationship
in interface
RelationshipSource
(接口RelationshipSource中的getRelationship)
id
- ID of the package relationship to retrieve.
(id - 要检索的包关系的 ID。)
RelationshipSource.getRelationship(java.lang.String)
public boolean hasRelationships()
RelationshipSource
hasRelationships
in interface
RelationshipSource
(接口RelationshipSource中的hasRelationships)
RelationshipSource.hasRelationships()
public boolean isRelationshipExists(PackageRelationship rel)
RelationshipSource
isRelationshipExists
in interface
RelationshipSource
(isRelationship存在于接口RelationshipSource中)
rel
- The relationship to check.
(rel - 要检查的关系。)
RelationshipSource.isRelationshipExists(org.apache.poi.openxml4j.opc.PackageRelationship)
public void addMarshaller(java.lang.String contentType, PartMarshaller marshaller)
contentType
- The content type to bind to the specified marshaller.
(contentType - 要绑定到指定编组器的内容类型。)
marshaller
- The marshaller to register with the specified content type.
(marshaller - 使用指定内容类型注册的编组器。)
public void addUnmarshaller(java.lang.String contentType, PartUnmarshaller unmarshaller)
contentType
- The content type to bind to the specified unmarshaller.
(contentType - 要绑定到指定解组器的内容类型。)
unmarshaller
- The unmarshaller to register with the specified content type.
(unmarshaller - 使用指定内容类型注册的解组器。)
public void removeMarshaller(java.lang.String contentType)
contentType
- The content type associated with the marshaller to remove.
(contentType - 与要删除的编组器关联的内容类型。)
public void removeUnmarshaller(java.lang.String contentType)
contentType
- The content type associated with the unmarshaller to remove.
(contentType - 与要删除的解组器关联的内容类型。)
public PackageAccess getPackageAccess()
@NotImplemented public boolean validatePackage(OPCPackage pkg) throws InvalidFormatException
InvalidFormatException
(无效格式异常)
public void save(java.io.File targetFile) throws java.io.IOException
targetFile
- Destination file.
(targetFile - 目标文件。)
java.io.IOException
- Throws if an IO exception occur.
(java.io.IOException - 如果发生 IO 异常则抛出。)
save(OutputStream)
public void save(java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- The stream to save the package.
(outputStream - 保存包的流。)
java.io.IOException
(java.io.IOException)
saveImpl(OutputStream)
protected abstract PackagePart createPartImpl(PackagePartName partName, java.lang.String contentType, boolean loadRelationships)
partName
- URI of the part to create.
(partName - 要创建的部件的 URI。)
contentType
- Content type of the part to create.
(contentType - 要创建的部件的内容类型。)
protected abstract void removePartImpl(PackagePartName partName)
partName
- The URI of the part to delete.
(partName - 要删除的部分的 URI。)
protected abstract void flushImpl()
protected abstract void closeImpl() throws java.io.IOException
java.io.IOException
(java.io.IOException)
protected abstract void revertImpl()
protected abstract void saveImpl(java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- The output stream use to save this package.
(outputStream - 用于保存此包的输出流。)
java.io.IOException
(java.io.IOException)
protected abstract PackagePartCollection getPartsImpl() throws InvalidFormatException
InvalidFormatException
(无效格式异常)
public boolean replaceContentType(java.lang.String oldContentType, java.lang.String newContentType)
A typical scneario to call this method is to rename a template file to the main format, e.g. ".dotx" to ".docx" ".dotm" to ".docm" ".xltx" to ".xlsx" ".xltm" to ".xlsm" ".potx" to ".pptx" ".potm" to ".pptm"
For example, a code converting a .xlsm macro workbook to .xlsx would look as follows:
OPCPackage pkg = OPCPackage.open(new FileInputStream("macro-workbook.xlsm"));
pkg.replaceContentType(
"application/vnd.ms-excel.sheet.macroEnabled.main+xml",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
FileOutputStream out = new FileOutputStream("workbook.xlsx");
pkg.save(out);
out.close();
(替换此包中的内容类型。调用此方法的一个典型场景是将模板文件重命名为主要格式,例如“.dotx”到“.docx”“.dotm”到“.docm”“.xltx”到“.xlsx”“.xltm”到 ".xlsm" ".potx" 到 ".pptx" ".potm" 到 ".pptm" 例如,将 .xlsm 宏工作簿转换为 .xlsx 的代码如下所示: OPCPackage pkg = OPCPackage.open(new FileInputStream("macro-workbook.xlsm")); pkg.replaceContentType("application/vnd.ms-excel.sheet.macroEnabled.main+xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"); FileOutputStream out = new FileOutputStream("workbook.xlsx"); pkg.save(出); out.close();)
oldContentType
- the content type to be replaced
(oldContentType - 要替换的内容类型)
newContentType
- the replacement
(newContentType - 替换)
public void registerPartAndContentType(PackagePart part)
part
- The part to add.
(part - 要添加的部分。)
public void unregisterPartAndContentType(PackagePartName partName)
partName
- The part name of the part to remove.
(partName - 要移除的部件的部件名称。)
public int getUnusedPartIndex(java.lang.String nameTemplate) throws InvalidFormatException
nameTemplate
- The template for new part names containing a
'#'
for the index, e.g. "/ppt/slides/slide#.xml"
(nameTemplate - 新零件名称的模板,其中包含索引的“#”,例如“/ppt/slides/slide#.xml”)
InvalidFormatException
- if the nameTemplate is null or doesn't contain the index char (#) or results in an invalid part name
(InvalidFormatException - 如果 nameTemplate 为 null 或不包含索引字符 (#) 或导致无效的部件名称)
public abstract boolean isClosed()
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.