FileFormatUtil
FileFormatUtil class
Provides utility methods for converting file format enums to strings or file extensions and back.
Methods
| Name | Description |
|---|---|
| detectFileFormat | Detects and returns the information about a format of an excel stored in a stream. |
| verifyPassword | Detects and returns the information about a format of an excel stored in a stream. |
| fileFormatToSaveFormat | Converting file format to save format. |
| extensionToSaveFormat | Converts a file name extension into a SaveFormat value. |
If the extension cannot be recognized, returns SaveFormat.UNKNO | | isTemplateFormat | Returns true if the extension is .xlt, .xltX, .xltm,.ots. | | loadFormatToExtension | Converts a load format enumerated value into a file extension.
If it can not be converted, returns null. | | loadFormatToSaveFormat | Converts a LoadFormat value to a SaveFormat value if possible. | | saveFormatToExtension | Converts a save format enumerated value into a file extension. | | saveFormatToLoadFormat | Converts a SaveFormat value to a LoadFormat value if possible. | | detectFileFormatFromBytes | Detects and returns the information about a format of an excel stored in a byte array. |
detectFileFormat(stream) (1 of 4)
Detects and returns the information about a format of an excel stored in a stream.
| Parameter | Type | Description |
|---|---|---|
| stream | InputStream | The stream |
Returns: A FileFormatInfo object that contains the detected information.
detectFileFormat(stream, password) (2 of 4)
Detects and returns the information about a format of an excel stored in a stream.
| Parameter | Type | Description |
|---|---|---|
| stream | InputStream | |
| password | String | The password for encrypted ooxml files. |
Returns: A FileFormatInfo object that contains the detected information.
detectFileFormat(filePath) (3 of 4)
Detects and returns the information about a format of an excel stored in a file.
| Parameter | Type | Description |
|---|---|---|
| filePath | String | The file path. |
Returns: A FileFormatInfo object that contains the detected information.
detectFileFormat(filePath, password) (4 of 4)
Detects and returns the information about a format of an excel stored in a file.
| Parameter | Type | Description |
|---|---|---|
| filePath | String | The file path. |
| password | String | The password for encrypted ooxml files. |
Returns: A FileFormatInfo object that contains the detected information.
verifyPassword(stream, password)
Detects and returns the information about a format of an excel stored in a stream.
| Parameter | Type | Description |
|---|---|---|
| stream | InputStream | |
| password | String | The password for encrypted ooxml files. |
Returns: Returns whether the password is corrected.
fileFormatToSaveFormat(format)
Converting file format to save format.
| Parameter | Type | Description |
|---|---|---|
| format | int | A FileFormatType value. The file format type. |
Returns: A SaveFormat value.
extensionToSaveFormat(extension)
Converts a file name extension into a SaveFormat value.
If the extension cannot be recognized, returns SaveFormat.UNKNOWN .
| Parameter | Type | Description |
|---|---|---|
| extension | String | The file extension. Can be with or without a leading dot. Case-insensitive. |
Returns: A SaveFormat value.
isTemplateFormat(extension)
Returns true if the extension is .xlt, .xltX, .xltm,.ots.
| Parameter | Type | Description |
|---|---|---|
| extension | String |
loadFormatToExtension(loadFormat)
Converts a load format enumerated value into a file extension.
If it can not be converted, returns null.
| Parameter | Type | Description |
|---|---|---|
| loadFormat | int | A LoadFormat value. The loaded file format. |
Returns: The returned extension is a lower-case string with a leading dot.
loadFormatToSaveFormat(loadFormat)
Converts a LoadFormat value to a SaveFormat value if possible.
| Parameter | Type | Description |
|---|---|---|
| loadFormat | int | A LoadFormat value. The load format. |
Returns: A SaveFormat value. The save format.
saveFormatToExtension(format)
Converts a save format enumerated value into a file extension.
| Parameter | Type | Description |
|---|---|---|
| format | int | A SaveFormat value. The save format. |
Returns: The returned extension is a lower-case string with a leading dot.
saveFormatToLoadFormat(saveFormat)
Converts a SaveFormat value to a LoadFormat value if possible.
| Parameter | Type | Description |
|---|---|---|
| saveFormat | int | A SaveFormat value. The save format. |
Returns: A LoadFormat value. The load format
detectFileFormatFromBytes(byte_array)
Detects and returns the information about a format of an excel stored in a byte array.
| Parameter | Type | Description |
|---|---|---|
| byte_array | bytes | The byte array |
Returns: A FileFormatInfo object that contains the detected information.
Example:
import jpype
import asposecells
jpype.startJVM()
from asposecells.api import *
with open('Book2.xlsx', 'rb') as f:
result = FileFormatUtil.detectFileFormatFromBytes(f.read())
print("detect result: %d" %(result.getFileFormatType()))
jpype.shutdownJVM()