ぼちぼちとStarBasicでのマクロを勉強していますが、なかなか進みません。とりあえず、覚え書きとしてコード断片をメモしておきます。
option explicit
REM ***** BASIC *****
'2つめのシートのb1セルの値を取得、表示の後、別の値をセットする
Sub Main
dim odoc as object
dim orange as object
oDoc = thiscomponent
orange = oDoc.sheets(1).getcellrangebyname("b1")
print orange.value
oRange.value=1234
End Sub
option explicit
REM ***** BASIC *****
'表4というシートのb1セルの値を取得、表示の後、別の値をセットする
Sub Main
dim odoc as object
dim orange as object
oDoc = thiscomponent
orange = oDoc.sheets.getbyname("表4").getcellrangebyname("b1")
print orange.value
oRange.value=1234
End Sub
option explicit REM ***** BASIC ***** '1枚目のシートの名を"test"に設定し、b2セルの値が0であったら12にセットする Sub Main dim oDocument as object dim oSheet as object dim oCell as object oDocument = ThisComponent oSheet=oDocument.Sheets.GetbyIndex(0) oSheet.name="test" oCell=oSheet.GetCellByPosition(1,1) 'B2 if oCell.value=0 then oCell.value=12 endif End Sub
option explicit
REM ***** BASIC *****
'購入リストというシートのA2:E21というセル範囲を第1列で昇順ソート(タイトル行なし)
dim odoc as object
dim osheet as object
dim orange as object
dim asortfield(0) as new com.sun.star.util.SortField
dim xsort as object
dim asortdesc(1) as new com.sun.star.beans.PropertyValue
oDoc = thiscomponent
osheet = oDoc.sheets.getbyname("購入リスト")
oRange = osheet.getcellrangebyname("A2:E21")
asortfield(0).Field=0
asortfield(0).SortAscending=false
asortdesc(0).Name="SortFields"
asortdesc(0).Value=asortfield()
asortdesc(1).Name="ContainsHeader"
asortdesc(1).Value=false
xsort=createSortDescriptor(asortdesc())
oRange.sort(xsort)