Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
3 Views

read excel range into an array

Apologies if this has been posted before - but I had a look and could not find it.

I have AUTODICE running ok on IVF XE 2011  - but I'm trying to read a 2d range of data into a fortran array from an excel sheet.

In VB syntax this would be simple :

Dim gen_array(0 To maxrow, 0 To maxcol) As Object

.

.

With objSheet

gen_array = .Range(.Cells(nStartRow, nStartCol), .Cells(nStartRow + nrows - 1, ncols)).Value

End With

is there a relatively easy way to do this in Fortran ?

 

 

0 Kudos
3 Replies
Highlighted
Valued Contributor II
3 Views

Looking at the notes in some

Looking at the notes in some of my own code, my understanding is you can write a row  eg. B5:Z5 or a column D5:D22 but not a block of data. Thus I have a loop of writes to write a block. i can prob post some sample code later.

0 Kudos
Highlighted
New Contributor I
3 Views

It would be greatly

It would be greatly appreciated if you could post some code. I have often wanted to do this also, and have seen several discussions in this forum from years back, but none of them were very simple.

Both reading and writing are of interest.

0 Kudos
Highlighted
3 Views

I gave up trying and put the

I gave up trying and put the extraction routine into a loop for each cell..

Here's the code for future reference in the hope that someone can do better.

    ! assign the range to the array
      k0=0
      do j=jrow1, jrow2
        k0=k0+1
        k1=0
        do i=jcol1, jcol2
          k1=k1+1
          call conv_2_col(i,col1)
          call trim_blank(col1,ib0)
          call gen_conv_text_int(row1,j)
          call trim_blank(row1,ib2)
          cell1add=col1(1:ib0)//row1(1:ib2)
 ! specify the input range  (singel cell in this case - since I can only re-assign one at a time..)
          CALL VariantInit(vBSTR1)
          vBSTR1%VT = VT_BSTR
          bstr1 = ConvertStringToBSTR(cell1add)
          vBSTR1%VU%PTR_VAL = bstr1
          range = $Worksheet_GetRange(worksheet, vBSTR1, vBSTR1, status)
          CALL Check_Status(status, " Unable to get RANGE object")
          status = VariantClear(vBSTR1)
          bstr1 = 0
! get the single cell from excel and store it in the character array 
          status = AUTOGETPROPERTY (range, "VALUE", gen_array(k0,k1))
        end do
      end do  

 

0 Kudos