在這次鐵人賽系列的技術最終章,使用 LibraOffice
建立巨集,使用者也可以再進一步使用 工作排程器 自動產生 daily report。
缺乏JRE
的錯誤訊息,需要到JAVA官網下載JRE執行檔REM ***** BASIC *****
Private Const service = "com.sun.star.sdb.DatabaseContext"
Private Const database = "fruit"
Sub Exercise2
ctx = CreateUnoService(service)
db = ctx.getByName(database)
conn = db.getConnection("","")
stmt = conn.createStatement()
query = "SELECT * FROM inventory"
result = stmt.executeQuery(query)
If Not IsNull(result) Then
row = 1 'assign output row position
ctr = ThisComponent.CurrentController
sheet = ctr.getActiveSheet()
While result.next
cellA = sheet.getCellByPosition(0,row)
cellB = sheet.getCellByPosition(1,row)
cellC = sheet.getCellByPosition(2,row)
cellA.String = result.getString(1)
cellB.String = result.getString(2)
cellC.String = result.getString(3)
row = row + 1
Wend
End If
End Sub
libreoffice-basic-macro-tutorial
中文版寫得很詳細的教學網站