2010年1月13日 星期三
學習記錄:OpenOffice Basic (4)
20100113補充:要先 save 才看到 msgbox 內容。
Sub Main
rem ##### 讀出本工作簿的名稱及位置
DocName=ThisComponent.Title
msgbox "本工作簿的名稱是: " & DocName
msgbox "本工作簿的「名稱」及「位置」是: " & ThisComponent.URL
20100113補充:利用 Ooo 自帶的 fuction 。來源在此。
GlobalScope.BasicLibraries.loadLIbrary( "Tools" )
print DirectoryNameoutofPath( ConvertFromURL( ThisComponent.URL ), getPathSeparator() )
rem ##### 只讀出本工作簿的位置
aURL = CreateUnoStruct("com.sun.star.util.URL")
aURL.Complete = ThisComponent.URL
CreateUnoService("com.sun.star.util.URLTransformer").parseStrict(aURL)
strPath = aURL.Path
msgbox "本工作簿的 path 是: " & strPath
rem ##### 在原 path 增加一個 "/TEST001/"
strPath2=aURL.Path + "/TEST001/"
msgbox "新的 path 是: " & strPath2
rem ##### 利用 "/" 及 UBound 來拆解 path
vntURL = Split(ThisComponent.URL, "/")
i = UBound(vntURL)
msgbox i
ReDim Preserve vntURL(i - 1)
strPath = Join(vntURL, "/")
msgbox strPath
rem ##### 「位置」格式的轉換
rem 由 url 轉為 dos 格式
DosFormatURL=ConvertFromUrl(strPath)
msgbox " DOS 格式的 path : " + DosFormatURL
rem ##### 「位置」格式的轉換
rem ##### 由 dos 轉為 url 格式
UrlFormatURL=ConvertToUrl(DosFormatURL)
msgbox " URL 格式的 path : " + UrlFormatURL
rem ##### 讀取每張 sheet 名稱
For Each oSheet In ThisComponent.Sheets
MsgBox oSheet.getName()
Next oSheet
End Sub
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言