FileFormatUtil

FileFormatUtil class

Provides utility methods for converting file format enums to strings or file extensions and back.

Methods

NameDescription
detectFileFormatDetects and returns the information about a format of an excel stored in a stream.
verifyPasswordDetects and returns the information about a format of an excel stored in a stream.
fileFormatToSaveFormatConverting file format to save format.
extensionToSaveFormatConverts 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.

ParameterTypeDescription
streamInputStreamThe 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.

ParameterTypeDescription
streamInputStream
passwordStringThe 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.

ParameterTypeDescription
filePathStringThe 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.

ParameterTypeDescription
filePathStringThe file path.
passwordStringThe 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.

ParameterTypeDescription
streamInputStream
passwordStringThe password for encrypted ooxml files.

Returns: Returns whether the password is corrected.

fileFormatToSaveFormat(format)

Converting file format to save format.

ParameterTypeDescription
formatintA 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 .

ParameterTypeDescription
extensionStringThe 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.

ParameterTypeDescription
extensionString

loadFormatToExtension(loadFormat)

Converts a load format enumerated value into a file extension.

If it can not be converted, returns null.

ParameterTypeDescription
loadFormatintA 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.

ParameterTypeDescription
loadFormatintA LoadFormat value. The load format.

Returns: A SaveFormat value. The save format.

saveFormatToExtension(format)

Converts a save format enumerated value into a file extension.

ParameterTypeDescription
formatintA 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.

ParameterTypeDescription
saveFormatintA 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.

ParameterTypeDescription
byte_arraybytesThe 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()