2006-06-08 22:07 [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

##
平均分數:0 顆星    投票人數:0
我要評分:
回應
挺不賴地~贊助一下
服務於軟體業的資訊老兵。興趣廣泛,學習力佳,好奇心強。
噗浪/互動式留言板
累積 | 今日
loading......
關鍵字
Re:[使用svchost viewer檢視你電...],By 科技與資訊研究所 於2008-11-11
Re:[【部落格更新】 增加中央氣象局衛星雲圖],By ~平淡生活~ 於2008-11-04
Re:[【部落格更新】 增加中央氣象局衛星雲圖],By ~平淡生活~ 於2008-10-07
Re:[標籤雲-翻譯自wikipedia],By 4664-1946~1964嬰兒潮、Baby Boomers 於2008-07-22
Re:[標籤雲-翻譯自wikipedia],By 4664-1946~1964嬰兒潮、Baby Boomers 於2008-07-22
熱門搜尋書籤
有朋自遠方來~

website counter
台灣部落格列表 PageRank
沒有新回應!






如何使用RSS
Powered by Xuite