Page 1 of 2

How to extract array from array browser

Posted: Mon Mar 21, 2016 12:59 am
by Janko
Dear Roger,

I have an array browser with 38 visabel rows and 15 visable columns. Array can be bigger or smaller than 38x 15. User can filter out some columns or some rows to obtain tailored table. I want to offer an option to export this, last designed table to .xslx, so it is neccesary to extract data that could be displayed. This table could be bigger or smaller than what is visable on screen.

I've tried with oBrowse:columnCount() to determine number of displayabe columns, but I could not find proper function to extract number of displayable rows.

At the end: where to extract data from? I'd prefer to do it from oBrowse:column object, but I am not sure this is good idea.

Can you help me with a hint?

Best regards
JAnko

Re: How to extract array from array browser

Posted: Mon Mar 21, 2016 4:14 am
by Zdeno Bielik
Hi,

try look into variable oBrowse:DataSource, if it contains, what you want/need.
Or try export only needed columns in MyExport routine.

HTH,
Zdeno

Code: Select all

@ nRow, nCol DCPUSHBUTTON CAPTION 'Export' ... ;
           ACTION {|| MyExport( oBrowse ) } ...


****************
Function MyExport( oBrowse )
*****************

Local aSource := oBrowse:DataSource
Local i, nRows := Len( oBrowse:DataSource ), nCols := oBrowse:ColCount
Local aExport := {}

wtf oBrowse, aSource, nRows, nCols

For i := 1 To nRows
*     If "any conditions..."
    AAdd( aExport, aSource[i] )
*     EndIf
Next

wtf aExport

*  and save array aSource or aExport like XLS...

Return ( NIL )

*

Re: How to extract array from array browser

Posted: Mon Mar 21, 2016 8:42 am
by Janko
Zdeno,

thanks for your answer. I have available data source. It is original array, which is bein browsed. But user can change ordinal position of column, can delete a column, can reveal column(s)..... And of course can filter rows, can calculate indexes, averages ...... and the final design is shown, but can be bigger or smaller than screen itself. So, I normaly loose the trail of all moves and filters.

I think that it should be possible to retrive data fo each column from column object.

Your solution is not good for me.

Maybe someone has different idea?

Best regards
JAnko

Re: How to extract array from array browser

Posted: Mon Mar 21, 2016 9:48 am
by Janko
I found the solution:

each column object contains oBrowse:GetColumn(i):arrayPointer which points to data array column.

I have to discover efects of FILTER clause in array browse.


Best regards
JAnko

Re: How to extract array from array browser

Posted: Tue Mar 22, 2016 6:26 am
by Tom

Code: Select all

FOR n := 1 TO oBrowse:RowCount
  FOR i := 1 TO oBrowse:ColCount
    ? oBrowse:GetColumn(i):DataArea:GetCell(n) 
  NEXT
NEXT
To be honest, this won't work good, since it shows all data from row 1 to the number of rows you see on the screen. You must find the number of the first row on the screen. oColumn:DataArea:CellFromPos(<aPos>) will give you the row number for the cell at "aPos". If aPos is the position of the first record in this column, you will get the right number.

Re: How to extract array from array browser

Posted: Tue Mar 22, 2016 10:32 am
by Janko
Tom,

I did it in this way:

Code: Select all


LOCAL i,j , nmaxrow, nmaxcol , arr 
Local aCol:=array(obr:ColCount)

nMaxCol:=obr:Colcount
nMaxRow:= len(obr:GetColumn(1):dataArea:cargo[8]   )
nPointer:= obr:getColumn(1):arrayPointer
arr:=array(nMaxRow, nMaxCol)

// obr:=oBrowse
nMaxCol:=obr:Colcount
nMaxRow:= len(obr:GetColumn(1):dataArea:cargo[8]   )
arr:=array(nMaxRow, nMaxCol)

for i:=1 to obr:ColCount
 aCol[i]:=obr:GetColumn(i):arrayPointer           // aCol is array of numbers that point to dataSource row numbers 
next i
 
for i:=1 to nMaxcol
	for j:= 1 to nMaxRow
		 arr[j,i]:= obr:DataSource[j,aCol[i]
	next j
next i
dc_arrayview(arr)
          
But using FILTER clause in oBrowse, which filters out certain rows has no influence to DataSource array.

What I would like to find out is where in column object are written displayable data (without those that are eliminated with FILTER)?

Any hint appreciated.

Best regards
JAnko

Re: How to extract array from array browser

Posted: Tue Mar 22, 2016 10:40 am
by rdonnay
What I would like to find out is where in column object are written displayable data (without those that are eliminated with FILTER)?
Please clarify what it is that you want. I don't understand.

Re: How to extract array from array browser

Posted: Wed Mar 23, 2016 12:51 am
by Janko
Roger,

I have an array of data dim 120 rows and 40 columns. Display can show 38 rows and 15 columns. rest of the array can be scrolled in and out.
User can select some columns and delete them with :delColumn().

As well DCBROWSE option allows FILTER clause that eliminates from view certain rows. So, final displayable array can contain 50 rows and 20 columns.
My intention is to export to .xlsx this final (displayable) array.

I can find links among displayed columns and datasource array using aCol:=obr:GetColumn(i):arrayPointer.
But I do not know which rows were filtered using FILTER clause in oBrowse.

I hope I was clear enough.

Best regards
JAnko

Re: How to extract array from array browser

Posted: Wed Mar 23, 2016 11:52 am
by rdonnay
Show me what your FILTER clause looks like.

Also, what method do you intend to use to export to XLS?

If you are using DC_Array2Excel(), then it would be best to create a new array from the browse array.

Re: How to extract array from array browser

Posted: Wed Mar 23, 2016 12:33 pm
by rdonnay
I think this is what you want. Here is a sample program:

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL GetList[0], aDir, i, oBrowse

DC_ChDir('C:\windows\system32')

aDir := Directory()

@ 0,0 DCBROWSE oBrowse DATA aDir SIZE 100,20 ;
      FILTER {|a|a[2]>100000}

FOR i := 1 TO 10
  DCBROWSECOL ELEMENT i HEADER Alltrim(Str(i)) WIDTH 10 PARENT oBrowse
NEXT

@ 21,0 DCPUSHBUTTON CAPTION 'Export' SIZE 10 ;
   ACTION {||ExportData(oBrowse)}

DCREAD GUI FIT TITLE 'Array Export Test'

RETURN nil

* -----------

STATIC FUNCTION ExportData(oBrowse)

LOCAL aData := {}, i, lDone := .f.

oBrowse:lockUpdate(.t.)

oBrowse:hitBottomBlock := {||lDone := .t.}

oBrowse:goTop()
oBrowse:forceStable()

DO WHILE !lDone

  AAdd(aData,Array(oBrowse:colCount))
  FOR i:= 1 TO oBrowse:colCount
    ATail(aData)[i] := Eval(oBrowse:getColumn(i):dataLink)
  NEXT

  oBrowse:down()
  oBrowse:forceStable()

ENDDO

oBrowse:goTop()
oBrowse:forceStable()
oBrowse:lockUpdate(.f.)

wtf aData

RETURN nil