Page 1 of 1
Access cellrange in stringitemlist
Posted: Tue May 15, 2018 1:00 pm
by tmanikanda
Hi All,
I am new to open office and even macros. I am trying to build a dialog box with list box or combo box in it. I need to load the list box with contents from a calc spreadsheet column.
oMyCombo= oDialog1.getControl("ComboBox1").getModel()
oCellRange = oSheet_tst.getCellRangeByName("I2:I7")
arg = Array("Item1", "Item2", "Item3", "Item4", "Item5")
REM Array(oCellRange) - Not working
REM Array( "Item1", "Item2", "Item3", "Item4", "Item5" ) - Working
oMyCombo.StringItemList=(arg)
In the above code if i use array of strings hardcoded it is working, but if I use oCellRange inside Array, I am getting error - Incorrect property value. Please help me in this
Re: Access cellrange in stringitemlist
Posted: Tue May 15, 2018 3:40 pm
by Zizi64
Please upload your ODF type samle file with the embedded macro code here
Re: Access cellrange in stringitemlist
Posted: Tue May 15, 2018 5:10 pm
by FJCC
You cannot assign the oCellRange to StringItemList because oCellRange is not an array of strings, it is an object describing a range of cells. One of its properties is a DataArray, which is an array of arrays of strings representing the cell contents. DataArray(i)(j) refers to the jth column of the ith row and you can refer to the entire ith row with DataArray(i). There is not compact way, I think, to refer to the entire jth column because those elements are in separate arrays. I haven't thought about array handling in Basic for a long time, so I may be wrong about that. If you store your values in a row, say I2:M2, this should work. (I put the combo box directly on my spreadsheet, not in a dialog)
Code: Select all
oDrawPages = ThisComponent.getDrawPages()
oObj1 = oDrawPages.getByIndex(0)
oObj2 = oObj1.getByIndex(0)
oControl = oObj2.getControl()
oSheet = ThisComponent.Sheets.getByIndex(0)
oCellrange = oSheet.getCellRangeByName("I2:M2")
DatArr = oCellrange.DataArray
oControl.StringItemList = DatArr(0)
Re: Access cellrange in stringitemlist
Posted: Tue May 15, 2018 7:20 pm
by Lupp
The indices of DataArray (as most indices on the technical level) are 0-based.
Another question to the Original Questioner: What is your understanding of a LIST?
That is not just the same as an array (1D or higher).
You seem to want an array eventually, but another row in your post looks a if you try to treat a CellRange as a list.
The problem with this is not just that cell contents cannot be referenced as the cells themselves (like a default property), but also that neither the CellRange nor its DataArray are lists.
What TYPE of value do you actually want to assign to a property of your ComboBox?
(If this sounds silly: I never use ComboBoxes in Calc.)
Re: Access cellrange in stringitemlist
Posted: Thu May 17, 2018 9:17 am
by tmanikanda
Hi All,
thanks all for your reply. Please find the sample sheet i am working on. The Item list will be a getting added. Also based on the indicator value i want them on the list.
Re: Access cellrange in stringitemlist
Posted: Sat May 26, 2018 7:59 am
by tmanikanda
Hi All
I am using for loop and additem to add items into the list box, but it is becoming slow when the row count increase, also i am still finding a way to filter the entries
For vi=0 To 100
vitem = oCellRange.DataArray(vi)(0)
If vitem <> "" Then
olistbox.AddItem(oCellRange.DataArray(vi)(0),vi)
End If
Next vi
I am not able to use match and index functions. Getting error
oItemRng = oSheet_Prod.getCellRangeByName("B2:B1000")
arg1 = Array(oProdRng)
oItemIdRng = oSheet_Prod.getCellRangeByName("A2:A1000")
arg2 = Array(oProdIdRng)
vtmp1 = svc.callFunction("MATCH",vproduct_name,arg1,0)
vproduct_id = svc.callFunction("INDEX",arg2,vtmp1)
Can someone help me in this
Re: Access cellrange in stringitemlist
Posted: Sat May 26, 2018 8:17 am
by Zizi64
How related the colorized variables to this task? Where you assign a value to the variable oProdRng? Please upload the full code of the Sub (or Function) with all of the dependencies. Better to upload a full sample file (again)
Code: Select all
[color=#FF0000]oItemRng[/color] = oSheet_Prod.getCellRangeByName("B2:B1000")
arg1 = Array([color=#FF0000]oProdRng[/color])
oItemIdRng = oSheet_Prod.getCellRangeByName("A2:A1000")
arg2 = Array(oProdIdRng)
vtmp1 = svc.callFunction("MATCH",vproduct_name,arg1,0)
vproduct_id = svc.callFunction("INDEX",arg2,vtmp1)
Re: Access cellrange in stringitemlist
Posted: Mon Jun 04, 2018 7:26 am
by tmanikanda
Hi Zizi64
oItemRng and oProdRng are same its my mistake while copying the code. I have attached a sample file in my previous post on May 17th. Also the for loop i have used is becoming slower when the count is more(ex. 1000)
Re: Access cellrange in stringitemlist
Posted: Mon Jun 04, 2018 4:38 pm
by hubert lambert
Hi,
You can call the TRANSPOSE() function to get the item array. Something like this:
Code: Select all
oMyCombo= oDialog1.getControl("ComboBox1")
oCellRange = oSheet_tst.getCellRangeByName("A2:C8")
s = createUnoService("com.sun.star.sheet.FunctionAccess")
data = s.callFunction("TRANSPOSE", array(oCellRange))
oDialog1.getControl("ComboBox1").addItems(data(0), 0)
oMyCombo.DropDownLineCount = ubound(data(0)) +1
Regards
Re: Access cellrange in stringitemlist
Posted: Thu Jul 12, 2018 11:41 am
by tmanikanda
Hi All
Thanks for your replies. I tried lambert suggestion. Its working for getting the whole column into the listbox, But i need to get the items only which is not yet active, can i do this? Also i am in need of new requirement. Want to select more than one item and update them, For ex. select both item 3 and 4 from list box and make them active. Need help on this
Re: Access cellrange in stringitemlist
Posted: Thu Jul 12, 2018 4:45 pm
by Lupp
@hubert lambert:
1.
Code: Select all
data = s.callFunction("TRANSPOSE", array(oCellRange))
works taking .DataArray as the "default property" of a com.sun.star.sheet.CellRange object. I hadn't expected that - and I would still prefer to write
Code: Select all
dataArray = s.callFunction("TRANSPOSE", array(oCellRange.DataArray))
The
name dataArray replacing
data there because CellRange objects also have an array property .Data which (for historical reasons?) only contains numeric data NAN for strings and blank cells.
2.
Since you seem to be familiar with the array-properties of CellRanges and with their specific way of using indices, a question OT in this thread: Do you know a way to assign such a special array to a properly dimensioned ordinary array with one statement (without any loops)?
The reverse case is Cellrange.SetDataArray() with works with 2D-arrays dimensioned in Basic.
tmanikanda wrote:But i need to get the items only which is not yet active, can i do this?
Having the one-column-arrays for item, isActive, and price you can scan isActive for active entries and create a compacted version of 'items'.
To correctly get the current price for a selected item, and to push it to the respective cell, you can generate an array giving an indirection to the original indices depending on the listbox indices for the selected item.
Sorry. Just found you wanted to allow selection of INactive items only. Simply adapt the few respective lines and add
Code: Select all
oCellRange.getCellByPosition(1, indirection(itempos)).String = "Y"
where already the new price is pushed.
=== Edit ===
Demo replaced.
See crude demo attached.
Re: Access cellrange in stringitemlist
Posted: Sat Jul 14, 2018 3:46 pm
by tmanikanda
Hi Lupp
The code you gave worked. Thanks. Just want to understand that your adding the items which are inactive to a array and using that array in additems function. Am i right.
One more thing i am looking for is to select multiple items in the listbox. getselecteditem is working where i am selecting only one item from the listbox, but getselecteditems is not working where i am selecting multiple items. Any idea on this
Re: Access cellrange in stringitemlist
Posted: Sat Jul 14, 2018 4:24 pm
by Zizi64
getselecteditem is working where i am selecting only one item from the listbox, but getselecteditems is not working where i am selecting multiple items. Any idea on this
viewtopic.php?f=20&t=94115
Re: Access cellrange in stringitemlist
Posted: Wed Aug 01, 2018 1:14 pm
by tmanikanda
Hi Zizi64
I am getting error 'Property or Method not found: Selectedvalues' in your sheet Listbox.ods when selecting any values in listbox_2
Re: Access cellrange in stringitemlist
Posted: Wed Aug 01, 2018 5:45 pm
by Zizi64
I am getting error 'Property or Method not found: Selectedvalues' in your sheet Listbox.ods when selecting any values in listbox_2
Apache OpenOffice 4.1.3 , Windows 10
It works fine in my LibreOffice 4.4.7 version, but - I just tested it now - I am getting same error message in my Apache OpenOffice winPenPack portable version.
Usually I use LibreOffice.
Re: Access cellrange in stringitemlist
Posted: Fri Aug 24, 2018 4:06 pm
by tmanikanda
i searched few links and still couldn't find how to select multiple items from listbox in openoffice. any help