[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

##

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

填寫回應

 

 

 

您可使用這些HTML標籤

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

隨機文章

  1. 由Subversion檔案庫匯出特定專案的內容 
  2. WordPress跑馬燈外掛:Running Line 
  3. 將Miranda IM升級至0.5版 
  4. IE7突然出現「存放裝置空間不足,無法完成此操作」錯誤 
  5. [Vista] 路徑分隔字元也能使用正斜線…「部份」成功… (1)
  6. [轉貼PC Office] Skype外掛「SAM」替您錄製離線電話答錄鈴! (1)
  7. iPad免費桌布何處尋? (3)
  8. 修改WordPress 2.8最新迴響的顯示格式 
  9. 終於比較清楚Aqua Data Studio的Execute Current要如何操作了 
  10. 我的Subversion與Trac使用經驗 (4)

歷史熱門文章

  1. 如何手動輸入Plurk的表情圖示? (353,054 點擊/2008-09-29)
  2. 簡單放大Plurk輸入區的方法[修訂] (86,924 點擊/2008-09-29)
  3. 啟用&關閉中華電信ZyXEL P874的無線網路連線功能的步驟[修訂] (83,952 點擊/2011-06-01)
  4. Plurk CSS樣式自訂修改全攻略 (83,108 點擊/2009-07-04)
  5. 網路升級光世代50M/3M與設定ZyXEL P874 (53,279 點擊/2011-05-28)
  6. 輕鬆學會彈指神功-揭露AutoHotkey絕技 (43,156 點擊/2008-04-10)
  7. iPad新手入門技巧 (40,410 點擊/2011-02-05)
  8. 分享世博台灣館主題曲『台灣的心跳聲』MV(附歌詞+下載連結+新歌詞) (38,149 點擊/2010-04-27)
  9. 把HTC Touch HD操作介面換成Spb Mobile Shell,美觀又便利! (37,954 點擊/2009-02-18)
  10. 另一套適用手機的影片轉檔工具:WinAVI 3GP/MP4/PSP/iPod Video Converter (35,920 點擊/2009-04-18)