[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. 解決Joomla! 突然出現的鎖定圖示 
  2. 中國時報的Blog專題報導: 全研究!Blog究極歷險 
  3. [NetBeans] 5.0 RC2新推出 
  4. [Xuite] 變更有文章日期的日曆樣式 (5)
  5. 由.txt自製電子書.epub並傳入iPad的步驟 
  6. Foobar2000 音樂播放軟體 
  7. Xuite自動書籤按鈕 V1.1 
  8. [OOo] 幾個Writer翻譯上的小問題 (1)
  9. [Tools] Qm: The Quick Mailer (2)
  10. [轉貼] Unlocker - 解除佔用檔案又無法刪除的程式 

歷史熱門文章

  1. 如何手動輸入Plurk的表情圖示? (368,444 點擊/2008-09-29)
  2. 啟用&關閉中華電信ZyXEL P874的無線網路連線功能的步驟[修訂] (120,467 點擊/2011-06-01)
  3. Plurk CSS樣式自訂修改全攻略 (89,476 點擊/2009-07-04)
  4. 簡單放大Plurk輸入區的方法[修訂] (88,895 點擊/2008-09-29)
  5. 網路升級光世代50M/3M與設定ZyXEL P874 (72,187 點擊/2011-05-28)
  6. 輕鬆學會彈指神功-揭露AutoHotkey絕技 (50,919 點擊/2008-04-10)
  7. iPad新手入門技巧 (49,436 點擊/2011-02-05)
  8. iPad鍵盤輸入全攻略 (42,911 點擊/2011-01-01)
  9. 分享世博台灣館主題曲『台灣的心跳聲』MV(附歌詞+下載連結+新歌詞) (40,929 點擊/2010-04-27)
  10. 調整Windows 7環境: 加回工作列的「顯示桌面」圖示 (40,856 點擊/2010-01-02)