2010年1月22日 星期五

學習記錄:OpenOffice Basic (11) (增加中)

 
一向以來,我是用一個主檔案,以Macro (VBA) 彙集其它同事輸入的資料。方法很簡單,同事們定時輸入資料,我按照 sheet1 儲存格排好的順序,逐一開啟檔案,讀入後關閉,再打開下一個。

以下的程式碼很早找到,只是我一直想用利用 Ooo Basic 兼容 VBA 的特點,儘可能源用已開發的 VBA 碼,減少重寫的幅度,但三天的上網扒文及測試,似乎達不到我的目的。


Sub Main

sFile2 = "C:\Documents and Settings\Administrator\桌面\no2.ods" ' Windows
'C:\Documents and Settings\Administrator\桌面\no2.ods
'sFile = "/home/danny/Desktop/MyCalc.sxc" ' Linux
sURL2 = ConvertToURL(sFile2)
oDoc2 = StarDesktop.loadComponentFromURL(sURL2, "_blank", 0, Array())

sFile1 = "C:\Documents and Settings\Administrator\桌面\no1.ods" ' Windows
'sFile = "/home/danny/Desktop/MyCalc.sxc" ' Linux
sURL1 = ConvertToURL(sFile1)
oDoc1 = StarDesktop.loadComponentFromURL(sURL1, "_blank", 0, Array())

oSheet = oDoc1.sheets (0)
oCell = oSheet.getCellByPosition (0,0)
oCell.String = now 'This function returns the current date and time

REM ##### 將焦點放回第一個開啟的 man_test_oo1.ods
oDoc2.CurrentController.Frame.ContainerWindow.toFront()
oDoc2.CurrentController.Frame.Activate()


oSheet = oDoc2.sheets (0)
oCell = oSheet.getCellByPosition (0,0)
oCell.String = "我是中國人" 'This function returns the current date and time

End Sub

  
  

沒有留言: