asposecells.api
Class FileFormatUtil

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

Method Summary
static methoddetectFileFormat(stream)
           Detects and returns the information about a format of an excel stored in a stream.
static methoddetectFileFormat(filePath)
           Detects and returns the information about a format of an excel stored in a file.
static methoddetectFileFormat(filePath, password)
           Detects and returns the information about a format of an excel stored in a file.
static methoddetectFileFormatFromBytes(byte_array)
           Detects and returns the information about a format of an excel stored in a byte array.
static methodextensionToSaveFormat(extension)
           Converts a file name extension into a SaveFormat value.
static methodisTemplateFormat(extension)
           Returns true if the extension is .xlt, .xltX, .xltm,.ots.
static methodloadFormatToExtension(loadFormat)
           Converts a load format enumerated value into a file extension.
static methodloadFormatToSaveFormat(loadFormat)
           Converts a LoadFormat value to a SaveFormat value if possible.
static methodsaveFormatToExtension(format)
           Converts a save format enumerated value into a file extension.
static methodsaveFormatToLoadFormat(saveFormat)
           Converts a SaveFormat value to a LoadFormat value if possible.
 

Method Detail

detectFileFormat

static FileFormatInfo detectFileFormat(filePath)
Detects and returns the information about a format of an excel stored in a file.
Parameters:
filePath: String - The file path.
Returns:
A FileFormatInfo object that contains the detected information.

detectFileFormat

static FileFormatInfo detectFileFormat(filePath, password)
Detects and returns the information about a format of an excel stored in a file.
Parameters:
filePath: String - The file path.
password: String - The password for encrypted ooxml files.
Returns:
A FileFormatInfo object that contains the detected information.

detectFileFormat

static FileFormatInfo detectFileFormat(stream)
Detects and returns the information about a format of an excel stored in a stream.
Parameters:
stream: InputStream - The stream
Returns:
A FileFormatInfo object that contains the detected information.

extensionToSaveFormat

static int extensionToSaveFormat(extension)
Converts a file name extension into a SaveFormat value. If the extension cannot be recognized, returns SaveFormat.UNKNOWN.
Parameters:
extension: String - The file extension. Can be with or without a leading dot. Case-insensitive.
Returns:
A SaveFormat value.

isTemplateFormat

static boolean isTemplateFormat(extension)
Returns true if the extension is .xlt, .xltX, .xltm,.ots.
Parameters:
extension: String -
Returns:

loadFormatToExtension

static String loadFormatToExtension(loadFormat)
Converts a load format enumerated value into a file extension. If it can not be converted, returns null.
Parameters:
loadFormat: int - A LoadFormat value. The loaded file format.
Returns:
The returned extension is a lower-case string with a leading dot.

loadFormatToSaveFormat

static int loadFormatToSaveFormat(loadFormat)
Converts a LoadFormat value to a SaveFormat value if possible.
Parameters:
loadFormat: int - A LoadFormat value. The load format.
Returns:
A SaveFormat value. The save format.

saveFormatToExtension

static String saveFormatToExtension(format)
Converts a save format enumerated value into a file extension.
Parameters:
format: int - A SaveFormat value. The save format.
Returns:
The returned extension is a lower-case string with a leading dot.

saveFormatToLoadFormat

static int saveFormatToLoadFormat(saveFormat)
Converts a SaveFormat value to a LoadFormat value if possible.
Parameters:
saveFormat: int - A SaveFormat value. The save format.
Returns:
A LoadFormat value. The load format

detectFileFormatFromBytes

static  detectFileFormatFromBytes(byte_array)
Detects and returns the information about a format of an excel stored in a byte array.
Parameters:
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()
				

See Also:
          Aspose.Cells Documentation - the home page for the Aspose.Cellss Product Documentation.
          Aspose.Cells Support Forum - our preferred method of support.