Difference between revisions of "Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files"
OOoWikiBot (talk | contribs) m (FINAL VERSION FOR L10N) |
m |
||
Line 9: | Line 9: | ||
=== Creating and Loading Spreadsheet Documents === | === Creating and Loading Spreadsheet Documents === | ||
<!--<idltopic>com.sun.star.frame.XComponentLoader</idltopic>--> | <!--<idltopic>com.sun.star.frame.XComponentLoader</idltopic>--> | ||
− | If a document in {{ | + | If a document in {{AOo}} API is required, begin by getting a <idl>com.sun.star.frame.Desktop</idl> service from the service manager. The desktop handles all document components in {{AOo}} API. It is discussed thoroughly in the chapter [[Documentation/DevGuide/OfficeDev/Office Development|Office Development]]. Office documents are often called components, because they support the <idl>com.sun.star.lang.XComponent</idl> interface. An <code>XComponent</code> is a UNO object that can be disposed of directly and broadcast an event to other UNO objects when the object is disposed. |
The Desktop can load new and existing components from a URL. For this purpose it has a <idl>com.sun.star.frame.XComponentLoader</idl> interface that has one single method to load and instantiate components from a URL into a frame: | The Desktop can load new and existing components from a URL. For this purpose it has a <idl>com.sun.star.frame.XComponentLoader</idl> interface that has one single method to load and instantiate components from a URL into a frame: | ||
Line 20: | Line 20: | ||
The interesting parameters in our context is the URL that describes the resource that is loaded and the load arguments. For the target frame, pass a "<code>_blank</code>" and set the search flags to 0. In most cases, existing frames are not reused. | The interesting parameters in our context is the URL that describes the resource that is loaded and the load arguments. For the target frame, pass a "<code>_blank</code>" and set the search flags to 0. In most cases, existing frames are not reused. | ||
− | The URL can be a <code>file:</code> URL, an <code>http:</code> URL, an <code>ftp:</code> URL or a private: URL. Locate the correct URL format in the '''Load URL''' box in the function bar of {{ | + | The URL can be a <code>file:</code> URL, an <code>http:</code> URL, an <code>ftp:</code> URL or a private: URL. Locate the correct URL format in the '''Load URL''' box in the function bar of {{AOo}} API. For new spreadsheet documents, a special URL scheme is used. The scheme is "private:", followed by "factory". The resource is "scalc" for {{AOo}} API spreadsheet documents. For a new spreadsheet document, use "private:factory/scalc". |
− | The load arguments are described in <idl>com.sun.star.document.MediaDescriptor</idl>. The properties <code>AsTemplate</code> and Hidden are boolean values and used for programming. If <code>AsTemplate</code> is true, the loader creates a new untitled document from the given URL. If it is false, template files are loaded for editing. If <code>Hidden</code> is true, the document is loaded in the background. This is useful to generate a document in the background without letting the user observe what is happening. For instance, use it to generate a document and print it out without previewing. Refer to [[Documentation/DevGuide/OfficeDev/Office Development|Office Development]] for other available options. This snippet loads a document in hidden mode: | + | The load arguments are described in <idl>com.sun.star.document.MediaDescriptor</idl>. The properties <code>AsTemplate</code> and <code>Hidden</code> are boolean values and used for programming. If <code>AsTemplate</code> is true, the loader creates a new untitled document from the given URL. If it is false, template files are loaded for editing. If <code>Hidden</code> is true, the document is loaded in the background. This is useful to generate a document in the background without letting the user observe what is happening. For instance, use it to generate a document and print it out without previewing. Refer to [[Documentation/DevGuide/OfficeDev/Office Development|Office Development]] for other available options. This snippet loads a document in hidden mode: |
// the method getRemoteServiceManager is described in the chapter First Steps | // the method getRemoteServiceManager is described in the chapter First Steps |
Revision as of 17:11, 15 December 2020
Creating and Loading Spreadsheet Documents
If a document in Apache OpenOffice API is required, begin by getting a com.sun.star.frame.Desktop service from the service manager. The desktop handles all document components in Apache OpenOffice API. It is discussed thoroughly in the chapter Office Development. Office documents are often called components, because they support the com.sun.star.lang.XComponent interface. An XComponent
is a UNO object that can be disposed of directly and broadcast an event to other UNO objects when the object is disposed.
The Desktop can load new and existing components from a URL. For this purpose it has a com.sun.star.frame.XComponentLoader interface that has one single method to load and instantiate components from a URL into a frame:
com::sun::star::lang::XComponent loadComponentFromURL( [IN] string aURL, [IN] string aTargetFrameName, [IN] long nSearchFlags, [IN] sequence <com::sun::star::beans::PropertyValue[] aArgs > )
The interesting parameters in our context is the URL that describes the resource that is loaded and the load arguments. For the target frame, pass a "_blank
" and set the search flags to 0. In most cases, existing frames are not reused.
The URL can be a file:
URL, an http:
URL, an ftp:
URL or a private: URL. Locate the correct URL format in the Load URL box in the function bar of Apache OpenOffice API. For new spreadsheet documents, a special URL scheme is used. The scheme is "private:", followed by "factory". The resource is "scalc" for Apache OpenOffice API spreadsheet documents. For a new spreadsheet document, use "private:factory/scalc".
The load arguments are described in com.sun.star.document.MediaDescriptor. The properties AsTemplate
and Hidden
are boolean values and used for programming. If AsTemplate
is true, the loader creates a new untitled document from the given URL. If it is false, template files are loaded for editing. If Hidden
is true, the document is loaded in the background. This is useful to generate a document in the background without letting the user observe what is happening. For instance, use it to generate a document and print it out without previewing. Refer to Office Development for other available options. This snippet loads a document in hidden mode:
// the method getRemoteServiceManager is described in the chapter First Steps mxRemoteServiceManager = this.getRemoteServiceManager(unoUrl); // retrieve the Desktop object, we need its XComponentLoader Object desktop = mxRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", mxRemoteContext); // query the XComponentLoader interface from the Desktop service XComponentLoader xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface( XComponentLoader.class, desktop); // define load properties according to com.sun.star.document.MediaDescriptor /* or simply create an empty array of com.sun.star.beans.PropertyValue structs: PropertyValue[] loadProps = new PropertyValue[0] */ // the boolean property Hidden tells the office to open a file in hidden mode PropertyValue[] loadProps = new PropertyValue[1]; loadProps[0] = new PropertyValue(); loadProps[0].Name = "Hidden"; loadProps[0].Value = new Boolean(true); loadUrl = "file:///c:/MyCalcDocument.ods" // load return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps);
Content on this page is licensed under the Public Documentation License (PDL). |