Advertisement
ba5tz

CRUD OpenOffice

Aug 12th, 2019
2,452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. REM  *****  BASIC  *****
  2.  
  3.  
  4. Dim oDialog1 as object
  5.  
  6. Sub StartDialog1()
  7.     MySheet = ThisComponent.Sheets("Sheet1")
  8.     basiclibraries.loadlibrary("Tools")
  9.     oDialog1 = loadDialog("Standard","Dialog1")
  10.     TB4 = oDialog1.Getcontrol("TextField4")
  11.     oRange = UsedRange(MySheet)
  12.     TB4.text = LastRow(oRange) + 1
  13.     oDialog1.Execute()
  14. end sub
  15.  
  16. Sub Simpan()
  17.     Dim MySheet
  18.     Dim Pesan as Integer
  19.     REM melalui Active Sheet
  20.     'MySheet = thiscomponent.currentcontroller.getactivesheet()
  21.    
  22.     'Melalui Sheet Name
  23.     MySheet = ThisComponent.Sheets("Sheet1")
  24.    
  25.     TB1 = oDialog1.Getcontrol("TextField1")
  26.     TB2 = oDialog1.Getcontrol("TextField2")
  27.     TB3 = oDialog1.Getcontrol("TextField3")
  28.     TB4 = oDialog1.Getcontrol("TextField4")
  29.     'msgbox oT1.text
  30.    
  31.     oRange = UsedRange(MySheet)
  32.     TB4.text = LastRow(oRange) + 1
  33.    
  34.     Rem dengan RangeName, jika pake Cells xSheet.getCellByPosition(0,0)
  35.     mysheet.getcellrangebyname("A" & TB4.text + 1).setString(TB4.text)
  36.     mysheet.getcellrangebyname("B" & TB4.text + 1).setstring(TB1.text)
  37.     mysheet.getcellrangebyname("C" & TB4.text + 1).setstring(TB2.text)
  38.     mysheet.getcellrangebyname("D" & TB4.text + 1).setstring(TB3.text)
  39.    
  40.     Pesan = msgbox ("Berhasil disimpan", 64+0,"Pesan")
  41.    
  42.     tb1.text = ""
  43.     tb2.text = ""
  44.     tb3.text = ""
  45. end sub
  46.  
  47. Sub Main
  48. mysheet = thiscomponent.currentcontroller.getactivesheet()
  49. cellA1 = mysheet.getcellrangebyname("A1")
  50. cellA1.setstring("Hello world")
  51. msgbox("Process completed")
  52. End Sub
  53.  
  54.  
  55. Function UsedRange(oSheet As Variant) As Variant
  56. Dim oCursor As Variant
  57.     oCursor = oSheet.createCursor()
  58.     oCursor.gotoEndOfUsedArea(False)
  59.     oCursor.gotoStartOfUsedArea(True)
  60.     UsedRange = oCursor
  61. End Function
  62.  
  63. Function LastRow(oRange As Variant) As Long
  64.     LastRow = oRange.getRangeAddress().EndRow
  65. End Function
  66.  
  67. Sub Find
  68.     MySheet = ThisComponent.Sheets("Sheet1")
  69.     sAns =  oDialog1.Getcontrol("TextField4").text
  70.  
  71.     If sAns = "" then End 'Blank entry or Cancel clicked.
  72.    
  73.     oDoc = ThisComponent
  74.     oCell = oDoc.CurrentSelection 'Get active sheet index.
  75.     index = oCell.CellAddress.Sheet
  76.     oSheet = oDoc.getSheets.getByIndex(Index)'Get active sheet.
  77.     FandR = oSheet.createSearchDescriptor 'Set up find and replace.
  78.     FandR.setSearchString(sAns)
  79.         'FandR.SearchWords = true 'Entire cell must match.
  80.     oCell = oSheet.findFirst(FandR)
  81.         If not isNull(oCell) then
  82.             oDialog1.Getcontrol("TextField1").text = mysheet.getcellrangebyname("B" & oCell.CellAddress.Row).string
  83.             oDialog1.Getcontrol("TextField2").text = mysheet.getcellrangebyname("C" & oCell.CellAddress.Row).string
  84.             oDialog1.Getcontrol("TextField3").text = mysheet.getcellrangebyname("D" & oCell.CellAddress.Row).string
  85.         Else MsgBox "Not Found!"
  86.         EndIf
  87. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement