open method
Contents
[
Hide
]open(file_name)
Allows a COM application to load a Document from a file.
def open(self, file_name: str):
...
Parameter | Type | Description |
---|---|---|
file_name | str | Filename 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):
...
Parameter | Type | Description |
---|---|---|
stream | io.BytesIO | A .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(file_name=MY_DIR + 'Document.docx')
self.assertEqual('Hello World!\r\rHello Word!\r\r\rHello World!', doc.get_text().strip())
# 2 - From a stream:
with system_helper.io.FileStream(MY_DIR + 'Document.docx', system_helper.io.FileMode.OPEN) as stream:
doc = com_helper.open(stream=stream)
self.assertEqual('Hello World!\r\rHello Word!\r\r\rHello World!', doc.get_text().strip())
See Also
- module aspose.words
- class ComHelper