[Solved] Populate listbox multicolumn from range

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
patel
Posts: 36
Joined: Tue Jun 19, 2012 2:48 pm

[Solved] Populate listbox multicolumn from range

Post by patel »

Hi all, this is my code, I don't know how populate the grid, can you help me ?

Code: Select all

sub listboxmulti
Sheet = ThisComponent.Sheets(0)
c = Sheet.createCursor
c.gotoEndOfUsedArea(false)
LastRow = c.RangeAddress.EndRow + 1
CellRange1 = Sheet.getCellRangeByName("A2:E" & LastRow)

DialogLibraries.LoadLibrary("Standard")
Dlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
Dlg.Title = "Trasferimento Prodotti"
dlgmodel = dlg.getModel()
     
      ' create new grid control
      gridmodel = dlgmodel.createInstance("com.sun.star.awt.grid.UnoControlGridModel")
      with gridmodel
        .PositionX = 10
        .PositionY = 30
        .Width = 150
        .Height = 100
      end with
     
      ' add columns
      columnmodel = gridmodel.ColumnModel
      col = columnmodel.createColumn()
      col.Title = "LastName"
      columnmodel.addColumn(col)
      col = columnmodel.createColumn()
      col.Title = "FirstName"
      columnmodel.addColumn(col)
      col = columnmodel.createColumn()
      col.Title = "Cod"
      columnmodel.addColumn(col)
      col = columnmodel.createColumn()
      col.Title = "Description"
      columnmodel.addColumn(col)      
      col = columnmodel.createColumn()
      col.Title = "Q.ty"
      columnmodel.addColumn(col)      
     
      ' insert grid control to the dialog
      dlgmodel.insertByName("grid", gridmodel)
     
      ' fill the grid with data
      datamodel = gridmodel.GridDataModel

      Dati = CellRange1.GetDataArray
      svc = createUnoService("com.sun.star.sheet.FunctionAccess")
      Dati1 =  svc.callFunction("TRANSPOSE", Array(Dati))
      datamodel.StringItemList = Dati1 ' <<<<<<<<<<<<< ERROR   method not found StringItemList
      dlg.execute()
      dlg.dispose()

End Sub
Attachments
ListboxMulti.ods
(19.41 KiB) Downloaded 197 times
Last edited by RoryOF on Mon Jun 12, 2017 6:04 pm, edited 2 times in total.
Reason: Added green tick [RoryOF, Moderator]
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
patel
Posts: 36
Joined: Tue Jun 19, 2012 2:48 pm

Re: Populate listbox multicolumn from range

Post by patel »

Solved

Code: Select all

sub listboxmulti
Sheet = ThisComponent.Sheets(0)
c = Sheet.createCursor
c.gotoEndOfUsedArea(false)
LastRow = c.RangeAddress.EndRow + 1
CellRange1 = Sheet.getCellRangeByName("A2:E" & LastRow)

DialogLibraries.LoadLibrary("Standard")
Dlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
Dlg.Title = "Trasferimento Prodotti"
dlgmodel = dlg.getModel()
     
      ' create new grid control
      gridmodel = dlgmodel.createInstance("com.sun.star.awt.grid.UnoControlGridModel")
      with gridmodel
        .PositionX = 10
        .PositionY = 30
        .Width = 150
        .Height = 100
      end with
     
      ' add columns
      columnmodel = gridmodel.ColumnModel
      col = columnmodel.createColumn()
      col.Title = "LastName"
      columnmodel.addColumn(col)
      col = columnmodel.createColumn()
      col.Title = "FirstName"
      columnmodel.addColumn(col)
      col = columnmodel.createColumn()
      col.Title = "Cod"
      columnmodel.addColumn(col)
      col = columnmodel.createColumn()
      col.Title = "Description"
      columnmodel.addColumn(col)     
      col = columnmodel.createColumn()
      col.Title = "Q.ty"
      columnmodel.addColumn(col)     
     
      ' insert grid control to the dialog
      dlgmodel.insertByName("grid", gridmodel)
     
      ' fill the grid with data
      datamodel = gridmodel.GridDataModel
      Dati = CellRange1.GetDataArray '<<<<<< 
      for i= 0 to Ubound(Dati) '<<<<<< 
         datamodel.addRow("", Dati(i)) '<<<<<< 
      next '<<<<<< 

      dlg.execute()
      dlg.dispose()

End Sub
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
Post Reply