[OOo] DOC轉成ODT格式的Script

以下是在Windows底下把Word的DOC格式轉換成OpenOffice Writer的ODT格式,這樣可以方便的執行已存在檔案的格式轉換。

doc2odt1.vbs
'***********************************************************
'$Id: doc2odt1.vbs 908 2006-06-08 09:01:48Z jerry $
'
'將DOC檔轉換成ODT檔; 必須傳入完整路徑的檔名
'***********************************************************
dim oArgs, oDoc
dim xExt, sURL, sSourceFile, sOutputFile

set oArgs = WScript.Arguments
if oArgs.Count > 0 then
sSourceFile = oArgs(0)
end if

'The service manager is always the starting point
'If there is no office running then an office is started up
Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")

'Create the CoreReflection service that is later used to create structs
'Set objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")

'Create the Desktop
Set objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop")

sExt = right(sSourceFile,4)

if (sExt = ".doc") then
if InStr(sSourceFile, "") <= 0 then
Wscript.echo "參數必須包含路徑"
else
sOutputFile = left(sSourceFile,len(sSourceFile)-4) & ".odt"

sURL = ConvertToUrl(sSourceFile)
'Wscript.echo cFile & "==>" & sURL
Set oDoc = objDesktop.loadComponentFromUrl(sURL,"_blank", 0, Array())
sURL = convertToURL(sOutputFile)

oDoc.storeAsURL sURL, Array()
oDoc.close( True )
end if
end if
WScript.Quit

Function ConvertToUrl(strFile)
strFile = Replace(strFile, "", "/")
strFile = Replace(strFile, ":", "|")
strFile = Replace(strFile, " ", "%20")
strFile = "file:///" + strFile
ConvertToUrl = strFile
End Function

##

您可能也會有興趣的類似文章

簡睿

服務於軟體業的資訊老兵。興趣廣泛,學習力佳,樂於分享所知所學。

您可能也會喜歡…

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *