Load document into a named frame
Andrew Douglas Pitonyak <[email protected]> Sat, 12 Mar 2011 00:58:03 -0500
| Newsgroups | gmane.comp.openoffice.devel.api |
|---|---|
| Message-ID | <[email protected]> |
Should I be able to load a document into a named frame? I last wrote about this with OOo version 1.1 Clearly the behavior has changed, and this no longer seems to work. Consider the following macro that used to work (but no longer does). Sub UseAnExistingFrame Dim noArgs() 'An empty array for the arguments Dim vDoc 'The loaded component Dim sURL As String 'URL of the document to load Dim nSearch As Long 'Search flags Dim sFName As String 'Frame Name Dim vFrame 'Document Frame Dim s As String 'Display string REM Search globally for this nSearch = com.sun.star.frame.FrameSearchFlag.GLOBAL + _ com.sun.star.frame.FrameSearchFlag.CREATE REM I can even open a real file for this, but I don't know what files REM you have on your computer so I create a new Writer document instead sURL = "file:///andrew0/home/andy/doc1.odt" sURL = "private:factory/swriter" REM Create a frame with the name MyFrame rather than _default sFName = "MyFrame" vFrame = ThisComponent.CurrentController.Frame vDoc = vFrame.LoadComponentFromUrl(sURL, sFName, nSearch, noArgs()) If IsNull(vDoc) Then Print "Failed to create a document" Exit Sub End If REM The name of the frame is MyFrame. Note that the name has nothing REM to do with the title! sFName = vDoc.CurrentController.Frame.Name s = "Created document to frame " & sFName & CHR$(10) MsgBox s REM This time, do not allow creation; only allow an existing frame nSearch = com.sun.star.frame.FrameSearchFlag.Global sURL = "file:///andrew0/home/andy/doc2.odt" sURL = "private:factory/scalc" sFName = "doc1 – OpenOffice.org Writer" vDoc = vFrame.LoadComponentFromUrl(sURL, sFName, nSearch, noArgs()) If IsNull(vDoc) Then Print "Failed to create a document" Exit Sub End If s = s & "Created document to frame " & sFName MsgBox s End Sub For those that care, this is the text that is current set to be included with the macro When a component (document) is loaded, it is placed into a frame; the second argument to LoadComponentFromUrl() specifies the name of the frame. If a frame with the specified name already exists, the newly loaded document uses the existing frame. The code in Listing 245 demonstrates the special frame name “_blank”—the special frame names are discussed shortly. Frame names that are not “special,” specify the name of an existing frame or a new frame. If you specify a frame name, you must tell OOo how to find the frame. The values in Table 94 enumerate valid values for the frame search flags. In OOo 1.1.0 I could use a document frame to load a new document into a named frame, but not the desktop frame. In OOo 3.3, both seem to be broken. First, loading a document into a named frame does not name the frame when a new frame is used. So, if I create a new document, the frame name is something like “Untitled 1 – OpenOffice.org Writer”. When I load a document and insist that the correct frame name be used (so a new frame cannot be created) the load only works if the named frame exists, but the document is NOT loaded into that named frame. If you experiment with this, be certain to save your documents before running the macro, at least one experiment caused the new document to load into the current frame. Shall I open a bug report on this? -- Andrew Pitonyak My Macro Document: http://www.pitonyak.org/AndrewMacro.odt Info: http://www.pitonyak.org/oo.php -- ----------------------------------------------------------------- To unsubscribe send email to [email protected] For additional commands send email to [email protected] with Subject: help