21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The StarDesktop<br />

The FileProperties array has two elements, one for each option used. The Filtername property defines<br />

whether <strong>OpenOffice</strong>.<strong>org</strong> uses a <strong>OpenOffice</strong>.<strong>org</strong> Calc text filter to open files. The FilterOptions property<br />

contains the description of the syntax of the csv file.<br />

Creating New Documents<br />

<strong>OpenOffice</strong>.<strong>org</strong> automatically creates a new document if the document specified in the URL is a template.<br />

Alternatively, if only an empty document without any adaptation is needed, a private:factory URL can be<br />

specified:<br />

Dim Dummy()<br />

Dim Url As String<br />

Dim Doc As Object<br />

Url = "private:factory/swriter"<br />

Doc = StarDesktop.loadComponentFromURL(Url, "_blank", 0, Dummy())<br />

The call creates an empty <strong>OpenOffice</strong>.<strong>org</strong> writer document.<br />

Document Objects<br />

The loadComponentFromURL function introduced in the previous section returns a document object. This<br />

supports the com.sun.star.document.OfficeDocument service, which in turn provides two central interfaces:<br />

The com.sun.star.frame.XStorable interface, which is responsible for saving documents.<br />

The com.sun.star.view.XPrintable interface, which contains the methods for printing documents.<br />

Saving and Exporting Documents<br />

<strong>OpenOffice</strong>.<strong>org</strong> documents are saved directly through the document object. The store method of the<br />

com.sun.star.frame.XStorable interface is available for this purpose:<br />

Doc.store()<br />

This call functions provided that the document has already been assigned a memory space. This is not the case for<br />

new documents. In this instance, the storeAsURL method is used. This method is also defined in<br />

com.sun.star.frame.XStorable and can be used to define the location of the document:<br />

Dim URL As String<br />

Dim Dummy()<br />

Url = "file:///C:/test3.odt"<br />

Doc.storeAsURL(URL, Dummy())<br />

In addition to the preceding methods, com.sun.star.frame.XStorable also provides some help methods which are<br />

useful when saving documents. These are:<br />

hasLocation()<br />

specifies whether the document has already been assigned a URL.<br />

isReadonly()<br />

specifies whether a document has read-only protection.<br />

isModified()<br />

specifies whether a document has been modified since it was last saved.<br />

The code for saving a document can be extended by these options so that the document is only saved if the object<br />

has actually been modified and the file name is only queried if it is actually needed:<br />

If (Doc.isModified) Then<br />

If (Doc.hasLocation And (Not Doc.isReadOnly)) Then<br />

Doc.store()<br />

Else<br />

Doc.storeAsURL(URL, Dummy())<br />

Chapter 5 · Working with Documents 63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!