Difference between revisions of "Opening a document"
From Apache OpenOffice Wiki
(remove from Category:Tutorials if in Category:Basic:Tutorials) |
m |
||
Line 1: | Line 1: | ||
'''The following function opens a file into a new window. ''' | '''The following function opens a file into a new window. ''' | ||
− | < | + | <source 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 | ||
− | </ | + | </source> |
Examples of calling the function: | Examples of calling the function: | ||
− | < | + | <source lang="oobas"> |
oDoc = fnOpenDoc("C:\Documents and Settings\danny\Desktop\MyCalc.sxc") ' Windows | oDoc = fnOpenDoc("C:\Documents and Settings\danny\Desktop\MyCalc.sxc") ' Windows | ||
oDoc = fnOpenDoc("/home/danny/Desktop/MyCalc.sxc") ' Linux | oDoc = fnOpenDoc("/home/danny/Desktop/MyCalc.sxc") ' Linux | ||
− | </ | + | </source> |
A more complete function for opening a file: | A more complete function for opening a file: | ||
− | < | + | <source 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 | ||
− | </ | + | </source> |
This function calls subAddProperty which is defined in [[working with properties]]. | This function calls subAddProperty which is defined in [[working with properties]]. | ||
Revision as of 17:52, 10 July 2008
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.sxc") ' Windows oDoc = fnOpenDoc("/home/danny/Desktop/MyCalc.sxc") ' 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 |
(Does anyone have a good reference for FilterOptions and FilterData?)