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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

XML File Format<br />

The StarDesktop<br />

<strong>OpenOffice</strong>.<strong>org</strong> documents are based on the XML file format. XML-based files can be opened and edited with<br />

other programs.<br />

Compression of Files<br />

Since XML is based on standard text files, the resultant files are usually very large. <strong>OpenOffice</strong>.<strong>org</strong> therefore<br />

compresses the files and saves them as a ZIP file. By means of a storeAsURL method option, the user can save<br />

the original XML files directly. See storeAsURL Method Options, below.<br />

Creating, Opening and Importing Documents<br />

Documents are opened, imported and created using the method StarDesktop.loadComponentFromURL(URL,<br />

Frame, SearchFlags, FileProperties) The first parameter of loadComponentFromURL specifies the URL of the<br />

associated file.<br />

As the second parameter, loadComponentFromURL expects a name for the frame object of the window that<br />

<strong>OpenOffice</strong>.<strong>org</strong> creates internally for its administration. The predefined _blank name is usually specified here,<br />

and this ensures that <strong>OpenOffice</strong>.<strong>org</strong> creates a new window.<br />

Using these parameters, the user can open a <strong>OpenOffice</strong>.<strong>org</strong> document, since place holders (dummy values) can<br />

be assigned to the last two parameters:<br />

Dim Doc As Object<br />

Dim Url As String<br />

Dim Dummy() 'An (empty) array of PropertyValues<br />

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

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

The preceding call opens the test.odt file and displays this in a new window.<br />

Any number of documents can be opened in this way in <strong>OpenOffice</strong>.<strong>org</strong> Basic and then edited using the returned<br />

document objects.<br />

Note – StarOffice 5 : StarDesktop.loadComponentFromURL supersedes the Documents.Add and<br />

Documents.Open methods from the old <strong>OpenOffice</strong>.<strong>org</strong> API.<br />

Replacing the Content of the Document Window<br />

The named _blank value for the Frame parameter ensures that <strong>OpenOffice</strong>.<strong>org</strong> creates a new window for every<br />

call from loadComponentFromURL. In some situations, it is useful to replace the content of an existing window.<br />

In this case, the frame object of the window should contain an explicit name. Note that this name must not begin<br />

with an underscore. Furthermore, the SearchFlags parameter must be set so that the corresponding framework<br />

is created, if it does not already exist. The corresponding constant for SearchFlags is:<br />

SearchFlags = com.sun.star.frame.FrameSearchFlag.CREATE + _<br />

com.sun.star.frame.FrameSearchFlag.ALL<br />

The following example shows how the content of an opened window can be replaced with the help of the frame<br />

parameter and SearchFlags:<br />

Dim Doc As Object<br />

Dim Dummy()<br />

Dim Url As String<br />

Dim SearchFlags As Long<br />

SearchFlags = com.sun.star.frame.FrameSearchFlag.CREATE + _<br />

com.sun.star.frame.FrameSearchFlag.ALL<br />

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

Doc = StarDesktop.loadComponentFromURL(Url, "MyFrame", SearchFlags, Dummy)<br />

Chapter 5 · Working with Documents 61

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

Saved successfully!

Ooh no, something went wrong!