Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Data conversion array->Object for excel 18 Jan 2022 11:37 #21149

  • ecos


  • Posts: 28
  • Hi all,
    in VO we could assign a 2-dimensional array to excel.range.value. x# does not like that.
    I found a solution to make it work:

    // aData is a 2-dimensional array
    nDimX := ALen(aData[1])
    nDimY := ALen(aData)

    cOL := "A1"
    cUR:= CHR(64+nDimX)+ntrim(nDimY)

    oRange := (Microsoft.Office.Interop.Excel.Range)oWorksheet:Range[ cOL, cUR]
    oData := OBJECT[,]{nDimY,nDimX}
    FOR nY := 1 UPTO nDimY
    FOR nX := 1 UPTO nDimX
    oData[nY,nX] := aData[nY][nX]
    NEXT
    NEXT
    oRange:Value := oData

    Is there a faster (better) way to convert the array to an Object[,] ?

    TIA
    Karl

    Please Log in or Create an account to join the conversation.

    Data conversion array->Object for excel 19 Jan 2022 08:44 #21156

    • robert
    • robert's Avatar


  • Posts: 2834
  • Karl,

    ecos wrote: Hi all,
    Is there a faster (better) way to convert the array to an Object[,] ?

    Not that I know of.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Data conversion array->Object for excel 19 Jan 2022 08:47 #21157

    • ecos


  • Posts: 28
  • meanwhile I saw that you do the same in _ArrayToObjectArray(). So I was not completely wrong...

    Please Log in or Create an account to join the conversation.

    Data conversion array->Object for excel 19 Jan 2022 08:59 #21158

    • robert
    • robert's Avatar


  • Posts: 2834
  • Karl,
    We do have an implicit converter in the array class to convert an array to to object[].
    I am not sure if this handles multi dimensional arrays exactly as you expect:
    FUNCTION Start AS VOID
        LOCAL a AS ARRAY
        LOCAL o AS OBJECT[]
        a := ArrayNew(10)
        AFill(a, 42)       
        o := a
        FOREACH VAR x IN o
            ? x
        NEXT
        WAIT
    RETURN
    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Data conversion array->Object for excel 19 Jan 2022 09:30 #21160

    • ecos


  • Posts: 28
  • Robert,
    that is what I tried first, but thus oRange:Value := o crashes.
    Anyway I only asked to learn how to do things better. Everything works fine now so no need to change anything.

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1