open method

open(file_name)

Allows a COM application to load a Document from a file.

def open(self, file_name: str):
    ...
ParameterTypeDescription
file_namestrFilename of the document to load.

Remarks

This method is same as calling the Document constructor with a file name parameter.

Returns

A Document object that represents a Word document.

open(stream)

Allows a COM application to load Document from a stream.

def open(self, stream: io.BytesIO):
    ...
ParameterTypeDescription
streamio.BytesIOA .NET stream object that contains the document to load.

Remarks

This method is same as calling the Document constructor with a stream parameter.

Returns

A Document object that represents a Word document.

Examples

Shows how to open documents using the ComHelper class.

# The ComHelper class allows us to load documents from within COM clients.
com_helper = aw.ComHelper()

# 1 -  Using a local system filename:
doc = com_helper.open(MY_DIR + "Document.docx")

self.assertEqual("Hello World!\r\rHello Word!\r\r\rHello World!", doc.get_text().strip())

# 2 -  From a stream:
with open(MY_DIR + "Document.docx", "rb") as stream:
    doc = com_helper.open(stream)
    self.assertEqual("Hello World!\r\rHello Word!\r\r\rHello World!", doc.get_text().strip())

See Also