LoadOptions class

LoadOptions class

Allows a developer to specify additional options (such as a password) when loading a file.

Learn more

The LoadOptions type exposes the following members:

Constructors

Constructor Description
init Initializes a new instance of the LoadOptions class.
init Initializes a new instance of the LoadOptions class.

Properties

Property Description
file_format The exact type of the file that is to be loaded. The default value is FileFormat.unknown, which means that the type should be detected automatically.
password The password used to open an encrypted document.

Example

from groupdocs.metadata import Metadata
from groupdocs.metadata.common import FileFormat
from groupdocs.metadata.options import LoadOptions

def load_password_protected_document():
    # Specify the password for a protected file
    load_options = LoadOptions()
    load_options.password = "123"

    with Metadata("protected.docx", load_options) as metadata:
        print(f"Opened protected {metadata.file_format} document")

def load_file_of_specific_format():
    # Explicitly set the file format to avoid detection overhead
    load_options = LoadOptions(FileFormat.SPREADSHEET)

    with Metadata("input.xlsx", load_options) as metadata:
        root = metadata.get_root_package()
        print(f"Author: {root.document_properties.author}")

if __name__ == "__main__":
    load_password_protected_document()
    load_file_of_specific_format()

See Also