Difference between revisions of "Opening a document"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(6 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
'''The following function opens a file into a new window. '''
 
'''The following function opens a file into a new window. '''
  
<code>[oobas]
+
<syntaxhighlight lang="oobas">
 
function fnOpenDoc(sFile)
 
function fnOpenDoc(sFile)
 
sURL = ConvertToURL(sFile)
 
sURL = ConvertToURL(sFile)
 
fnOpenDoc = StarDesktop.loadComponentFromURL(sURL, "_blank", 0, Array())
 
fnOpenDoc = StarDesktop.loadComponentFromURL(sURL, "_blank", 0, Array())
 
end function
 
end function
</code>
+
</syntaxhighlight>
 
Examples of calling the function:  
 
Examples of calling the function:  
  
<code>[oobas]
+
<syntaxhighlight lang="oobas">
oDoc = fnOpenDoc("C:\Documents and Settings\danny\Desktop\MyCalc.sxc") ' Windows
+
oDoc = fnOpenDoc("C:\Documents and Settings\danny\Desktop\MyCalc.ods") ' Windows
oDoc = fnOpenDoc("/home/danny/Desktop/MyCalc.sxc") ' Linux
+
oDoc = fnOpenDoc("/home/danny/Desktop/MyCalc.ods") ' Linux
</code>
+
</syntaxhighlight>
 
A more complete function for opening a file:  
 
A more complete function for opening a file:  
  
<code>[oobas]
+
<syntaxhighlight lang="oobas">
 
function fnOpenDoc(sFile, optional bAsTemplate, optional sPassword, optional bReadOnly, _
 
function fnOpenDoc(sFile, optional bAsTemplate, optional sPassword, optional bReadOnly, _
 
   optional nMacroExecutionMode, optional nUpdateDocMode, optional sJumpMark, _
 
   optional nMacroExecutionMode, optional nUpdateDocMode, optional sJumpMark, _
Line 66: Line 66:
 
fnOpenDoc = StarDesktop.loadComponentFromURL(sURL, "_blank", 0, mFileProperties())
 
fnOpenDoc = StarDesktop.loadComponentFromURL(sURL, "_blank", 0, mFileProperties())
 
end function
 
end function
</code>
+
</syntaxhighlight>
 
This function calls subAddProperty which is defined in [[working with properties]].  
 
This function calls subAddProperty which is defined in [[working with properties]].  
  
Line 111: Line 111:
 
|}
 
|}
  
 
+
For a complete reference on FilterOptions and FilterData, consult the [[Documentation/DevGuide/OpenOffice.org_Developers_Guide|Developer's Guide]]. FilterOptions for spreadsheet documents are in the Spreadsheet section.
(Does anyone have a good reference for FilterOptions and FilterData?)
+
  
 
[[Category:Basic:Tutorials]]
 
[[Category:Basic:Tutorials]]
[[Category:Tutorials]]
 

Latest revision as of 12:29, 4 February 2021

The following function opens a file into a new window.

function fnOpenDoc(sFile)
sURL = ConvertToURL(sFile)
fnOpenDoc = StarDesktop.loadComponentFromURL(sURL, "_blank", 0, Array())
end function

Examples of calling the function:

oDoc = fnOpenDoc("C:\Documents and Settings\danny\Desktop\MyCalc.ods") ' Windows
oDoc = fnOpenDoc("/home/danny/Desktop/MyCalc.ods") ' Linux

A more complete function for opening a file:

function fnOpenDoc(sFile, optional bAsTemplate, optional sPassword, optional bReadOnly, _
  optional nMacroExecutionMode, optional nUpdateDocMode, optional sJumpMark, _
  optional nViewId, optional bHidden, optional bStartPresentation,_
  optional sFilterName, optional sFilterOptions, optional vFilterData, optional bRepairPackage)
 
dim mFileProperties()
 
if not isMissing(bAsTemplate) then
        subAddproperty(mFileProperties(), "AsTemplate", bAsTemplate)
end if
if not isMissing(sPassword) then
        subAddproperty(mFileProperties(), "Password", sPassword)
end if
if not isMissing(bReadOnly) then
        subAddproperty(mFileProperties(), "ReadOnly", bReadOnly)
end if
if not isMissing(nMacroExecutionMode) then
        subAddproperty(mFileProperties(), "MacroExecutionMode", nMacroExecutionMode)
end if
if not isMissing(nUpdateDocMode) then
        subAddproperty(mFileProperties(), "UpdateDocMode", nUpdateDocMode)
end if
if not isMissing(sJumpMark) then
        subAddproperty(mFileProperties(), "JumpMark", sJumpMark)
end if
if not isMissing(nViewId) then
        subAddproperty(mFileProperties(), "ViewId", nViewId)
end if
if not isMissing(bHidden) then
        subAddproperty(mFileProperties(), "Hidden", bHidden)
end if
if not isMissing(bStartPresentation) then
        subAddproperty(mFileProperties(), "StartPresentation", bStartPresentation)
end if
if not isMissing(sFilterName) then
        subAddproperty(mFileProperties(), "FilterName", sFilterName)
end if
if not isMissing(sFilterOptions) then
        subAddproperty(mFileProperties(), "FilterOptions", sFilterOptions)
end if
if not isMissing(vFilterData) then
        subAddproperty(mFileProperties(), "FilterData", vFilterData)
end if
if not isMissing(bRepairPackage) then
        subAddproperty(mFileProperties(), "RepairPackage", bRepairPackage)
end if
sURL = ConvertToURL(sFile)
on local error resume next
fnOpenDoc = StarDesktop.loadComponentFromURL(sURL, "_blank", 0, mFileProperties())
end function

This function calls subAddProperty which is defined in working with properties.

Parameter Explanation
bAsTemplate True = Create new document
False = Open document (including templates) for editing
sPassword For opening password protected files
bReadOnly True = In the user interface the document will be presented as read only
nMacroExecutionMode com.sun.star.document.MacroExecMode.NEVER_EXECUTE
com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE
com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE_NO_WARN
nUpdateDocMode com.sun.star.document.UpdateDocMode.NO_UPDATE
com.sun.star.document.UpdateDocMode.QUIET_UPDATE
com.sun.star.document.UpdateDocMode.ACCORDING_TO_CONFIG
com.sun.star.document.UpdateDocMode.FULL_UPDATE
sJumpMark For example the name of a bookmark in a text document
bHidden True = Document opened but not visible. Use with caution
bStartPresentation For Impress documents start the presentation
sFilterName See saving a document for a list of filters
sFilterOptions Use this to supply additional info. to the filter
vFilterData Use this if a string for sFilterOptions is insufficient
bRepairPackage True = opens the document in repair mode, so as much information as possible will be retrieved

For a complete reference on FilterOptions and FilterData, consult the Developer's Guide. FilterOptions for spreadsheet documents are in the Spreadsheet section.

Personal tools