Olá pessoal,
Estou tentando implementar um projeto com uma TreeControl
no Basic com base em uma vídeo aula do VBA, no entanto me esbarrei no agrupamento das contas, conforme imagem abaixo:
Segue código e planilha abaixo:
REM ***** BASIC *****
'__________________________________________________
Option Explicit
'__________________________________________________
Const FCT = "com.sun.star.sheet.FunctionAccess"
Const PCT = "com.sun.star.awt.tree.MutableTreeDataModel"
'__________________________________________________
Dim fs As Variant
Dim wb As Object
Dim ws As Object
Dim Coluna As String
Dim uLinha As Long
Dim BaseDados As Object
Dim wPlan As Object
Dim Arr()
Dim nLin As Integer
Dim Dlg As Object
Dim frmPContas As Object
Dim oPContas As Object
Dim mPContas As Object
Dim oMTD
Dim NoRaiz As Object
Dim NoPai As Object
Dim NoFilho As Object
Dim NoNeto As Object
Dim NoBisneto As Object
'__________________________________________________
Private Sub Dados
wb = ThisComponent
Set ws = wb.Sheets().getByName("Plano de Contas")
Coluna = "A:A"
uLinha = Linha (ws , Coluna)
BaseDados = ws.getCellRangeByName("A1:D" & uLinha )
Arr = BaseDados.getDataArray()
End Sub
'__________________________________________________
Private Sub FrmInitialize
DialogLibraries.loadLibrary("Standard")
Dlg = createUnoDialog(DialogLibraries.Standard.getByName("dlgPContas"))
frmPContas = dlg.Model
oPContas = Dlg.getControl("PContas")
mPContas = oPContas.Model
Call Dados
Call PlanoContas
Dlg.Execute
Dlg.Dispose
End Sub
'__________________________________________________
Sub PlanoContas
oMTD = createUnoService( PCT )
NoRaiz = oMTD.createNode( "Plano de Contas", True )
For nLin = lBound( Arr )+1 To uBound( Arr )
oMTD.setRoot ( NoRaiz )
NoPai = oMTD.createNode (ws.getCellByPosition ( 0 , nLin ).String , True )
NoRaiz.appendChild( NoPai )
NoFilho = oMTD.createNode(ws.getCellByPosition( 1 , nLin).String , True)
NoPai.appendChild( NoFilho )
NoNeto = oMTD.createNode(ws.getCellByPosition( 2 , nLin).String , True)
NoFilho.appendChild( NoNeto )
NoBisneto = oMTD.createNode(ws.getCellByPosition( 3 , nLin).String , False)
NoNeto.appendChild( NoBisneto )
mPContas.DataModel = oMTD
oPContas.expandNode ( NoRaiz ) = true
oPContas.expandNode ( NoPai ) = true
oPContas.expandNode ( NoFilho ) = true
oPContas.expandNode ( NoNeto ) = true
Next nLin
End Sub
'__________________________________________________
Private Function Linha ( ws , Range )
fs = createUnoService( FCT )
Linha = fs.callFunction( "COUNTA" , (Array(ws.getCellRangeBYname( Coluna ) )))
End Function
A pergunta é: Tem como fazer o agrupamento das contas de acordo com a imagem?
plano-de-contas-array.ods (93.2 KB)