_savage wrote:It turns out though that I can now load any kind of file type: text documents, images, tables, ... However, I'd like to restrict the file types to supported text documents only (i.e. open Writer only) and reject the rest. Is that possible?
Do what the user interface does: open only documents having specific extensions.
- Types of documents
Note that a Writer document may be an OpenOffice Writer, Microsoft Word, etc. The extension (and sometimes the structure of the document) is used by OpenOffice to find the filter required to load the document.
_savage wrote:how can I query that document object once it's open? It seems that a Writer document supports only a certain set of services
Once the document is loaded, it provides some services and interfaces, as you can see with MRI or Xray.
With Python or Basic the
supported services and their interfaces are directly usable, no need for invocation (contrary to Java, C++).
The
available services of the object need to be invoked from the object, but you have to know how to use them. Example, inserting a text section in a Writer document:
Code: Select all
...
myText = myDoc.getText()
aCursor = myText.createTextCursor()
aCursor.gotoEnd(False)
' invocation of a service of a Writer document
aSection = myDoc.createInstance("com.sun.star.text.TextSection")
myText.insertTextContent(aCursor, aSection, False)
With Python, Basic, etc, you cannot invoke an interface. You can only use the interfaces provided by a service.
Some services are independent of a document.
Code: Select all
' *** Basic ***
Dim dispatcher As Object
dispatcher = CreateUnoService("com.sun.star.frame.DispatchHelper")
Internally CreateUnoService invokes the service from a primary object : the Service Manager.
With Python you have to do it yourself : get the Service Manager, then use method createInstance or createInstanceWith Context.