| View previous topic :: View next topic |
| Author |
Message |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
Posted: Tue Jan 27, 2004 1:00 pm Post subject: Open and Create documents, various prog. languages |
|
|
If you have already been programming OOo's API, this article may be useful to you because it goes into all kinds of interesting things about loadComponentFromURL(). In fact I could have named this article "loadComponentFromURL".
If you are just learning to program OOo's API, this document might be one of the very first ones you should read.
To do almost anything useful with OOo via. the API, in almost all cases, you must either create a new document, or open an existing document. Then you would manipulate the contents of the document, extract information from it, print it, convert it to a different format, work with data forms on the document, or perform various other tasks with office documents.
Therefore, one of the first things to learn is how to open or create documents.
ServiceManager and Desktop objects
In order to work with OOo via. the API, you must first acquire two essential objects.
1. the ServiceManager
2. the Desktop
Once you have the ServiceManager, you call its createInstance() method to get the Desktop object.
Once you have the Desktop object, you can use it to create or open new documents.
Getting the Service Manager
In every different programming language, there are different mechanisms for acquiring the Service Manager.
OOo Basic
In OOo Basic, the global function GetProcessServiceManager() returns a service manager. So you could write...
| Code: | | oServiceManager = GetProcessServiceManager() |
to assign the service manager to a variable. (But wait! You don't have to do this, there is a way to shortcut directly to the Desktop object described later.)
Visual Basic (and other COM languages)
When OpenOffice.org is installed on Windows, it registers a COM object called com.sun.star.ServiceManager. Therefore, a language, such as Visual Basic can use a statement such as...
| Code: | | Set oServiceManager = CreateObject("com.sun.star.ServiceManager") |
to create a Service Manager object.
Note that this accesses the Service Manager of OOo running on the same computer as the program making the CreateObject call.
In Visual FoxPro, I use the statement...
| Code: | | oServiceManager = CREATEOBJECT( "com.sun.star.ServiceManager" ) |
which is very similar to the above.
A similar technique has been seen before on OOoForum in languages such as Delphi, Ruby (for Win32), PHP, and I believe C++.
Python (and Java)
In some cases (Java or Python) your program might not be running on the same computer as OOo. In this case, there is a local Service Manager, and there is the Service Manager which is part of OOo. You first must "bootstrap" a local service manager, then get a URL resolver, then use a specially formed URL to connect to the remote Service Manager in the OOo. For more information see...
http://api.openoffice.org/docs/DevelopersGuide/FirstSteps/FirstSteps.htm#1+3+4+2+Service+Managers
A more detailed description is beyond the scope of this article.
In Python you can do something like this...
| Code: | import uno
# Get the uno component context from the PyUNO runtime
oLocalContext = uno.getComponentContext()
# Get the local Service Manager
oLocalServiceManager = oLocalContext.ServiceManager
# Create the UnoUrlResolver on the Python side.
oLocalResolver = oLocalServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", oLocalContext )
# Connect to the running OpenOffice.org and get its context.
oContext = oLocalResolver.resolve( "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext" )
# Get the ServiceManager object
oServiceManager = oContext.ServiceManager
|
The SDK and the Developer's Guide provide examples in Java using a similar technique, where the local service manager gives you a url resolver, then you use a special URL to connect to OOo (which might be on a different computer), and then get it's service manager.
Note that you would replace "localhost" in the above URL with the name or address of the computer which is running OOo. OOo must already be running, and configured to listen for UNO connections.
Getting the Desktop
Now that we have the office's service manager in the variable oServiceManager, we can create the desktop object.
This is very similar in any programming language. In OOo Basic you would write something like...
| Code: | | oDesktop = oServiceManager.createInstance( "com.sun.star.frame.Desktop" ) |
In Visual Basic...
| Code: | | Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop") |
It is pretty similar in other languages. (In PHP, for instance, you would use dollar signs on variables such as $oDesktop = $oServiceManager->createInstance.....)
Shortcuts in OOo Basic
In OOo Basic, you do not need to write either the line to get the service manager (calling GetProcessServiceManager()) or the line to call createInstance() to get the Desktop. OOo Basic has a convenient handy-dandy variable built in called StarDesktop. This is included in OOo Basic for no extra charge.
OOo Basic also has a shortcut for oServiceManager.createInstance(). Simply use the global function createUnoService(). So for creating any service such as...
| Code: | | oDesktop = oServiceManager.createInstance( "com.sun.star.frame.Desktop" ) |
in OOo Basic, you could instead write...
| Code: | | oDesktop = createUnoService( "com.sun.star.frame.Desktop" ) |
Instead of writing, for example...
| Code: | | oFF = oServiceManager.createInstance( "com.sun.star.document.FilterFactory" ) |
in OOo Basic, you could instead write...
| Code: | | oFF = createUnoService( "com.sun.star.document.FilterFactory" ) |
loadComponentFromURL
Now that you have the desktop object in the variable oDesktop, we can create or open documents. This is done by calling the Desktop object's method loadComponentFromURL().
In OOo Basic, you could write something like this...
oServiceManager = GetProcessServiceManager()
oDesktop = oServiceManager.createInstance( "com.sun.star.frame.Desktop" )
oDoc = oDesktop.loadComponentFromURL( .... )
We could shorten this using OOo Basic's global createUnoService() function (previously described).
oDesktop = createUnoService( "com.sun.star.frame.Desktop" )
oDoc = oDesktop.loadComponentFromURL( .... )
As I previously mentioned, in OOo Basic, the variable StarDesktop already contains the desktop object. So you could instead just write...
oDoc = StarDesktop.loadComponentFromURL( .... )
Notice how oDesktop was replaced with the global variable StarDesktop.
In all future examples, this is how I will write it in OOo Basic. For other languages, you understand that you must get the Desktop object. In order to do that, you must get the ServiceManager object.
In Python you would write...
oDoc = oDesktop.loadComponentFromURL( .... )
Opening documents
The loadComponentFromURL() method of the Desktop object can open a document. To do so, you must pass the URL of a document. In OOo Basic, here is an example...
| Code: | oDoc = StarDesktop.loadComponentFromURL( "file:///home/danny/Desktop/MyDoc.sxd",_
"_blank", 0, Array() ) |
(Note that the underscore at the end of the first line means that the line is continued on the next line.)
Now if you've read the Developer's Guide, or looked at the SDK examples, or recorded a macro, you will have seen much more complicated code for opening a document. Often, examples include a Dim statement to dimension an empty array of no arguments. Instead of doing that, I simply used the Array() function with no arguments to create an empty array and pass it as the fourth argument to loadComponentFromURL(). Very commonly, you'll see something like this...
| Code: | Dim aNoArgs()
oDoc = StarDesktop.loadComponentFromURL( "file:///home/danny/Desktop/MyDoc.sxd",_
"_blank", 0, aNoArgs() ) |
There are four arguments to loadComponentFromURL().
1. The URL.
2. The target frame. (Always use "_blank" for now.)
3. Flags. (Always use zero for now.)
4. An array of arguments to specify "how" to load the url. (Always use Array() for now.)
Instead of a Linux pathname, here is an example with a Windows pathname...
| Code: | oDoc = StarDesktop.loadComponentFromURL( "file:///C:/Documents and Settings/dbrewer/Desktop/MyDoc.sxd",_
"_blank", 0, Array() ) |
In Visual Basic, you would write something like this...
| Code: | Dim aNoArgs()
Set oDoc = oDesktop.loadComponentFromURL( "file:///C:/Documents and Settings/dbrewer/Desktop/MyDoc.sxd",
"_blank", 0, aNoArgs() ) |
Where oDesktop is the variable containing the Desktop object, previously described.
In Visual FoxPro I write this...
| Code: | * Arrays in VFP cannot have zero elements, so we must put something into the array.
LOCAL ARRAY aNoArgs[1]
aNoArgs[1] = MakePropertyValue( "Hidden", .F. )
LOCAL oDoc
oDoc = oDesktop.loadComponentFromUrl( cURL, "_blank", 0, @ aNoArgs )
* Make sure that arrays passed to this document are passed zero based.
COMARRAY( oDoc, 10 )
|
In this example, cURL is a variable containing the URL. The array aNoArgs must be declared with one element, because in VFP, it is not possible to declare empty arrays of no elements. So I had to put something into that array element. I will describe the function MakePropertyValue() later.
In Python, the technique is very similar...
| Code: | | oDoc = oDesktop.loadComponentFromURL( cUrl, "_blank", 0, (,) ) |
where cUrl is a variable containing the string of the url to load.
Instead of an array, the fourth argument must be a "tupple" of arguments. The two parenthesis with the comma is the syntax to create an empty tupple. For a bit more about tupples to loadComponentFromURL, see this...
http://www.oooforum.org/forum/viewtopic.php?p=13519#13519
In OOo Basic, there are two convenient functions:
1. ConvertToURL()
2. ConvertFromURL()
These functions translate between a local file pathname and a URL. On Linux I could write...
| Code: | cFile = "/home/danny/Desktop/MyDoc.sxd"
cUrl = ConvertToURL( cFile )
oDoc = StarDesktop.loadComponentFromURL( cUrl, "_blank", 0, Array() )
|
In OOo Basic on Windows, I would change only the first line...
| Code: | cFile = "C:\Documents and Settings\dbrewer\Desktop\MyDoc.sxd"
cUrl = ConvertToURL( cFile )
oDoc = StarDesktop.loadComponentFromURL( cUrl, "_blank", 0, Array() )
|
The function ConvertFromURL() is useful to take a URL and turn it back into a local pathname.
Other kinds of URLs
The URL that you give to loadComponentFromURL does not have to represent a local file! You can in fact use a URL that loads a document from a web page (http) or ftp site (ftp).
For example....
| Code: | oDoc = StarDesktop.loadComponentFromURL( "http://somewhere.com/some/path/MyDoc.sxd",_
"_blank", 0, Array() ) |
This would open a document that was available from a web site!
Similarly...
| Code: | oDoc = StarDesktop.loadComponentFromURL( "ftp://myname:mypassword@somewhere.com/some/path/MyDoc.sxd",_
"_blank", 0, Array() ) |
This would open a document that was available from an ftp site. "myuname" would the the account name to the ftp site, and "mypassword" would the password. If instead you had written...
| Code: | oDoc = StarDesktop.loadComponentFromURL( "ftp://myname@somewhere.com/some/path/MyDoc.sxd",_
"_blank", 0, Array() ) |
then you will be logged in to the ftp site as "myname", but OOo will interactively prompt you for the password.
In addition to http and ftp, WebDav url's are supported.
How does this work? It is because of the Universal Content Broker (UCB). The UCB has its very own chapter in the Developer's Guide. In a nutshell, the UCB takes a URL, figures out how to access the content, and then provides the content back to loadComponentFromURL(). The process works in reverse when saving. The procedures storeToURL() and storeAsUrl() give their url to the UCB, which then figures out how to "save" the document, even to an ftp site, or WebDav server.
The UCB can be extended with third party modules.
There are modules to access content in Zip files. With a special url syntax, it is possible to open your document even if it is stored inside a Zip file, on a remote web server somewhere.
See these two message I've previously written.
http://www.oooforum.org/forum/viewtopic.php?p=15369#15369
http://www.oooforum.org/forum/viewtopic.php?p=15403#15403
These show you how to open a CSV file from Yahoo stock quotes. The CSV is actually the current price of some stocks. But OOo just treats it as a URL and opens it into a Calc document.
Here are some other articles I've written on the UCB...
http://www.oooforum.org/forum/viewtopic.php?p=17276#17276
http://www.oooforum.org/forum/viewtopic.php?p=17049#17049
http://www.oooforum.org/forum/viewtopic.php?t=4611
Creating new documents
The loadComponentFromURL() method of the Desktop object is used both for opening documents and creating new documents.
To create a new document, you simply use a specially constructed URL. Here are some one liner's in OOo Basic that show how to create some new documents...
| Code: | ' Create a new drawing.
oDoc = StarDesktop.loadComponentFromURL( "private:factory/sdraw", "_blank", 0, Array() )
' Create a new text document.
oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, Array() )
' Create a new presentation document.
oDoc = StarDesktop.loadComponentFromURL( "private:factory/simpress", "_blank", 0, Array() )
' Create a new spreadsheet document.
oDoc = StarDesktop.loadComponentFromURL( "private:factory/scalc", "_blank", 0, Array() )
' Create a new math document.
oDoc = StarDesktop.loadComponentFromURL( "private:factory/smath", "_blank", 0, Array() )
|
So why such a funny way to create new documents? I believe there is a reason.
I believe that loadComponentFromURL passes the URL to the Universal Content Broker (UCB).
These are just URL's that "load" a document. In this case, the document is loaded from a document "template" in your OOo installation. You can change your document template so that whenever you create a "new" spreadsheet, it already has certian things filled in. The "new" document is actually loaded from a template by the UCB.
Here are some other URL examples....
| Code: | ' Open a drawing document on the Windows desktop.
oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( "c:\Documents and Settings\dbrewer\Desktop\UglyMonkeys.sxd" ), "_blank", 0, Array() )
' Open a drawing document on a Linux /tmp directory
oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( "/tmp/DogNFireHydrant.sxd" ), "_blank", 0, Array() )
' Open a document which is on a web server.
oDoc = StarDesktop.loadComponentFromURL( "http://somewhere.com/docs/UglyMonkeys.sxd", "_blank", 0, Array() )
' Open a document which is on an ftp server.
oDoc = StarDesktop.loadComponentFromURL( "ftp://username:password@somewhere.com/docs/UglyMonkeys.sxd", "_blank", 0, Array() )
'....or leave off password to be prompted for password...
oDoc = StarDesktop.loadComponentFromURL( "ftp://username@somewhere.com/docs/UglyMonkeys.sxd", "_blank", 0, Array() )
' The following items are described in the Developer's Guide, under section 6.1.5, under Loading Documents.
' http://api.openoffice.org/docs/DevelopersGuide/OfficeDev/OfficeDev.htm#1+1+5+1+Loading+Documents
' This opens a Data Sources View window. Useful.
oDoc = StarDesktop.loadComponentFromURL( ".component:DB/DataSourceBrowser", "_blank", 0, Array() )
' Interesting, but not useful.
' Perhaps this needs a supplementary MediaDescriptor URL?
oDoc = StarDesktop.loadComponentFromURL( ".component:DB/FormGridView", "_blank", 0, Array() )
' Open up the Bibliography database. Useful.
oDoc = StarDesktop.loadComponentFromURL( ".component:Bibliography/View1", "_blank", 0, Array() )
' CAREFUL!
' WARNING!!!
' This one crashes OOo 1.1.
' oDoc = StarDesktop.loadComponentFromURL( ".component:DB/QueryDesign", "_blank", 0, Array() )
' This one flashes up a window that quickly disappears again.
oDoc = StarDesktop.loadComponentFromURL( ".component:DB/TableDesign", "_blank", 0, Array() )
' This one flashes up a window, then an error message "Connection Lost".
oDoc = StarDesktop.loadComponentFromURL( ".component:DB/RelationDesign", "_blank", 0, Array() )
|
MakePropertyValue
The fourth parameter to loadComponentFromURL() is an empty array, usually written (in OOo Basic) as just Array().
The array doesn't have to be empty. Sometimes you need to pass arguments.
In this article...
http://www.oooforum.org/forum/viewtopic.php?t=5108
I introduce the MakePropertyValue() function, which I use to pass arguments to loadComponentFromURL().
MakePropertyValue() takes two arguments...
1. a property name
2. a property value
It returns a structure (com.sun.star.beans.PropertyValue) which contains both the Name and the Value together.
You can pass arrays of such structures to loadComponentFromURL().
The property names you can use are from the service MediaDescriptor which is documented here...
http://api.openoffice.org/docs/common/ref/com/sun/star/document/MediaDescriptor.html
You'll notice in the Visual FoxPro example I gave earlier that I passed a property called "Hidden", with a value of False. (So that the document would not be hidden.) Here is how the same thing could be written in OOo Basic...
| Code: | oDoc = StarDesktop.loadComponentFromURL( cUrl, "_blank", 0,_
Array(,_
MakePropertyValue( "Hidden", False ) ) )
|
You could open the document hidden, so that it is invisible and does not appear on screen by passing True for the Hidden property. You might want to do this if you are writing code that needs to open a document and do something with it, but not have anything flash up on screen where the user can see it.
You could use the property MacroExecutionMode to open the document in such a way that macros in the document cannot be executed. See a past article I wrote here...
http://www.oooforum.org/forum/viewtopic.php?p=16178#16178
You could use the AsTemplate property to open a document as a template or not.
Importing documents of different type
You can use the FilterName property to specify one of OOo's many import filters. For example, if the URL to the document you are opening, points to, say, a Microsoft Excel document, you might want to specify a filter name so that OOo knows to use an import filter to convert the document when loading it.
| Code: | oDoc = StarDesktop.loadComponentFromURL( cUrl, "_blank", 0,_
Array(,_
MakePropertyValue( "Hidden", False ),_
MakePropertyValue( "AsTemplate", False ),_
MakePropertyValue( "FilerName", "MS Excel 97" ) ) )
|
Notice that I gave three properties here. It is the third one, FilterName that we are talking about.
Usually, you do NOT need to specify an import filter to loadComponentFromURL. OOo's Type Detection will figure out what the incomming type of document is, and then use the appropriate filter to load it.
One case where you DO want to specify a filter to loadComponentFromURL() is when the Type Detection does the WRONG THING!
For example, if you are opening an Html file, OOo will kindly open it as a Web document. If you want the Html file opened as a Writer document (in the word processor) instead, then you MUST specify a filter.
| Code: | oDoc = StarDesktop.loadComponentFromURL( cUrl, "_blank", 0,_
Array(,_
MakePropertyValue( "FilterName", "HTML (StarWriter)" ) ) )
|
So how do I know these filter names? How do I know to use the exact string "HTML (StarWriter)"? (And yes, you must specify filter names exactly.)
See these articles for lists of filter names...
http://www.oooforum.org/forum/viewtopic.php?t=3549
http://www.oooforum.org/forum/viewtopic.php?p=15416#15416
http://www.oooforum.org/forum/viewtopic.php?t=3545
http://www.oooforum.org/forum/viewtopic.php?t=3175
No documentation on filter options
http://www.oooforum.org/forum/viewtopic.php?t=2735
http://www.oooforum.org/forum/viewtopic.php?t=3458
Other articles
Here is a useful article I've written in the past on how to use Python with OOo on Windows.
http://www.oooforum.org/forum/viewtopic.php?t=4818
And some others on Python...
http://www.oooforum.org/forum/viewtopic.php?t=3735
http://www.oooforum.org/forum/viewtopic.php?p=13501#13501
http://www.oooforum.org/forum/viewtopic.php?t=3451
http://www.oooforum.org/forum/viewtopic.php?t=4368
http://www.oooforum.org/forum/viewtopic.php?t=4772
I hope this information is useful. And I hope you had as much fun as I did writing it. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
SilverSurfeur Guest
|
Posted: Fri Mar 05, 2004 5:49 am Post subject: |
|
|
I have some questions about how loading OOo documents :
First question : Can I send parameters (like the parameters sent to functions) to an OOo spreadsheet on loading ?
Second question : If it's possible to send parameters to a spreadsheet, how can i make the loading in PHP language ?
Third question : How can I use these parameters in an OOo macro ? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
Posted: Fri Mar 05, 2004 6:32 am Post subject: |
|
|
| SilverSurfeur wrote: | | Can I send parameters (like the parameters sent to functions) to an OOo spreadsheet on loading ? |
Not in the way you are probably thinking. You can, of course, open a spreadsheet, and then make any adjustments to the spreadsheet. You can call macros within the spreadsheet and pass parameters to those.
If you open a spreadsheet document, you need to open it with a special property so that macros are enabled to run in the spreadsheet. See this article...
Opening document such that Macros can run
http://www.oooforum.org/forum/viewtopic.php?p=16178#16178
Here is information about how to call a macro via. a properly formed URL, and passing parameters to the macro via. the url...
Use a macro:/// url via. the Dispatcher
http://www.oooforum.org/forum/viewtopic.php?t=6079
Calling macro in different document, and pass parameter...
http://www.oooforum.org/forum/viewtopic.php?t=5564
Call macro in different document from VB and pass parameter...
http://www.oooforum.org/forum/viewtopic.php?t=6221
Other articles where this is discussed....
http://www.oooforum.org/forum/viewtopic.php?t=4071
http://www.oooforum.org/forum/viewtopic.php?p=15589#15589
http://www.oooforum.org/forum/viewtopic.php?p=9861#9861
http://www.oooforum.org/forum/viewtopic.php?p=17377#17377
http://www.oooforum.org/forum/viewtopic.php?t=3196
http://www.oooforum.org/forum/viewtopic.php?t=2619
http://www.oooforum.org/forum/viewtopic.php?p=11794#11794
http://www.oooforum.org/forum/viewtopic.php?p=13053#13053
http://www.oooforum.org/forum/viewtopic.php?t=4285
http://www.oooforum.org/forum/viewtopic.php?t=3772
http://www.oooforum.org/forum/viewtopic.php?t=4163
| SilverSurfeur wrote: | | If it's possible to send parameters to a spreadsheet, how can i make the loading in PHP language ? |
In order to use a programming language with OOo, there must be an UNO bridge implemented for that language. I know that there is one for Python. I do not know about PHP in general.
On Windows, PHP supports COM. On Windows, OOo also can be called from COM. Any Windows language that supports COM, such as
Visual Basic
Visual FoxPro
Delphi
PHP
Ruby
....and others...
can use their "CreateObject" to create the Service Manager, as described in my article above. Every other object comes directly or indirectly from the service manager.
Here are some past examples where someone used PHP on Windows to access OOo using COM.
http://www.oooforum.org/forum/viewtopic.php?t=3474
http://www.oooforum.org/forum/viewtopic.php?t=3530
http://www.oooforum.org/forum/viewtopic.php?t=3502
In the first linked article, notice the technique.
| Code: | | $osm = new COM("com.sun.star.ServiceManager") |
Apparently, in PHP on Windows (which I have never used), you can use a function called COM() to create any COM object. The person who posted the first message 3474 above calls COM to create the Service Manager. Everything else comes from the Service Manager as I described at the beginning of this thread.
The next thing the user does is to go through the motions of getting a remote service manager, but he gets the service manager by connecting to localhost. Since that is the service manager he already had, I'm not sure this next part was actually necessary.
| Code: | $resolv = $osm->createInstance("com.sun.star.bridge.UnoUrlResolver") or die ("Resolver not initialized\n");
echo("Resolver initialized\n");
$init = $resolv->resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager") or die ("Resolver not inizialized\n"); |
But I'll leave that for someone who actually uses PHP on Windows to decide. The technique here is very similar to how Java and Python users access the remote service manager. First get a resolver, then resolve a URL to the remote service manager.
| SilverSurfeur wrote: | | How can I use these parameters in an OOo macro ? |
I would propose the following.
1. Open the document. (Using a parameter to make sure that macros within the document can be run.)
2. Use the technique described above to form a url that can call the macro with parameters. Use the dispatcher to execute this url, thus calling a macro that is in the spreadsheet document.
Putting all of the above techniques together may require you to first get some experience using the API. The easiest way to learn the API is to use OOo Basic and study the many numerous examples that have been posted to OOoForum in the last year. Download other macros from OOoMacros.org, and study those. Understanding the API is what you need most. Using PHP is just a matter of using PHP's syntax to access the API. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
SilverSurfeur Guest
|
Posted: Fri Mar 05, 2004 8:20 am Post subject: |
|
|
Thanks for help
i will try this soon...  |
|
| Back to top |
|
 |
Bommi Newbie

Joined: 13 Apr 2004 Posts: 2
|
Posted: Tue Apr 13, 2004 5:26 am Post subject: it doesn´t work.... please check it: |
|
|
<script language=vbscript>
Dim aNoArgs
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
set oDoc = StarDesktop.loadComponentFromURL("file:///C:\test.doc", "_blank", 0, aNoArgs())
</script> |
|
| Back to top |
|
 |
SAnjum Newbie

Joined: 31 Mar 2004 Posts: 3
|
Posted: Thu Apr 22, 2004 8:34 am Post subject: |
|
|
What if i have to load document from one webserver and save it on another ?
Should both servers must be listening to office
if yes
1. can both listen to same host and port
2. or we will have to install separte office on both and then they must be listening to each one |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
Posted: Thu Apr 22, 2004 10:31 am Post subject: |
|
|
| SAnjum wrote: | What if i have to load document from one webserver and save it on another ?
Should both servers must be listening to office |
What are you asking?
Here is one possible way I can interpret your question.
3 Computers: W1, W2 and OOo. Computers W1 and W2 are web servers. Computer OOo is a third computer running OOo.
Computer OOo takes the action of opening a document from a URL that pulls the document from W1. OOo then saves the document using a different URL that stores the document onto W2.
No problem.
Another possible interpretation of the question....
W1 and W2 both run, let's say, Java Server Pages, and both web servers are trying to make a third computer OOo process documents.
The OOo is going to have trouble with multiple threads or multiple computers trying to get it to do something at the same time. This topic has been discussed before over in Macros and API.
Another possibility is that somehow the question involves multiple servers running OOo? Multiple instances of OOo running on different computers?
I simply don't understand the question that is being asked.
Danny _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
SAnjum Newbie

Joined: 31 Mar 2004 Posts: 3
|
Posted: Mon Apr 26, 2004 11:31 am Post subject: |
|
|
< I simply don't understand the question that is being asked. >
I am extreemly sorry Danny for that
Let me explain the scenario i did.
Computer A is running application which will open a remote connection of Open Office on another computer B
Now this application open document -> converts it into corresponding filter correctly and if i try to save it on Computer B as well i dont get any problem...
What i need now from my application is to save the converted document to another computer C which is running a webserver. I tried to provide Computer C URL but it didn't work.
I hope if i am able to communicate the problem well... if not plz let me know so that i will explain more.
Thanks and Regards
--Sheraz |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
Posted: Wed Apr 28, 2004 2:58 pm Post subject: |
|
|
| SAnjum wrote: | | What i need now from my application is to save the converted document to another computer C which is running a webserver. I tried to provide Computer C URL but it didn't work. |
You can save to computer C. When you save you need to use a URL that will save it onto that computer.
There are several possible ways.
Use an "ftp://" url to save it to an FTP server on Computer C.
Use an "http://" url to save it to an HTTP server on Computer C, provided that the server implements allowing you to save.
Another possibility is to use WebDav, which I know nothing about, but WebDav is documented to work in the Universal Content Broker chapter of the Developer's Guide. I suspect, from what I've read, that using an http:// url would work to save to a web server that supports WebDav.
The easy way is to simply run an FTP server on Computer C. If you do this, be sure that both computers are NOT exposed to the Internet, or that Computer C's FTP server is not exposed to the Internet. FTP is not a secure protocol. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
elehenaff Power User

Joined: 16 Apr 2004 Posts: 76 Location: paris - france
|
Posted: Wed Sep 22, 2004 4:34 am Post subject: How to create a new document using a template ? |
|
|
| How to create a new document using a template ? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
Posted: Wed Sep 22, 2004 5:30 am Post subject: Re: How to create a new document using a template ? |
|
|
| elehenaff wrote: | | How to create a new document using a template ? |
If you have a document saved as a template, then simply open the template as if it were any other document. Once opened, it will be Untitled.
| Code: | oDoc = StarDesktop.loadComponentFromURL( "file:///home/danny/Desktop/MyDoc.sxd",_
"_blank", 0, Array() )
|
Instead of MyDoc.sxd, if it were a template, it would probably be named MyDoc.std. (sxd = Drawing, std = Drawing Template, sxw = Writer, stw = Writer Template.) Just change the URL to point to a template rather than a document.
For instance, I just opened a Writer template like this....
| Code: | Sub Main
cFile = "C:\Documents and Settings\dbrewer\Desktop\test.stw"
cUrl = ConvertToUrl( cFile )
oDoc = StarDesktop.loadComponentFromURL( cUrl, "_blank", 0, Array() )
End Sub
|
_________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|