reading from a 2 dimensional SAFEARRAY

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

reading from a 2 dimensional SAFEARRAY

Günther Schmidt
Hi,

I've made some progress on importing data from Excel files, in
particular, finding "usedRange" came in very handy.

However this gives me an IDispatch - range object, and that in turn
gives me a (twodimensional) SAFEARRAY object.

Everything fine up to that point.

Cause I haven't figured out yet how to get deeper into that SAFEARRAY
and retrieve the "rows", so that I can split them into individual records.

How would I do that?

Günther


BTW the binary selector problem is resolved, naturaly I can't use '.'
and I reckon neither can I use ';' for that matter.


Reply | Threaded
Open this post in threaded view
|

Re: reading from a 2 dimensional SAFEARRAY

Sebastián Sastre
Hi Günther,

    I'm curios about getting data directly from excel files. Could you post
a example of it?

    thank you,

Sebastian


"Günther Schmidt" <[hidden email]> escribió en el mensaje
news:[hidden email]...

> Hi,
>
> I've made some progress on importing data from Excel files, in particular,
> finding "usedRange" came in very handy.
>
> However this gives me an IDispatch - range object, and that in turn gives
> me a (twodimensional) SAFEARRAY object.
>
> Everything fine up to that point.
>
> Cause I haven't figured out yet how to get deeper into that SAFEARRAY and
> retrieve the "rows", so that I can split them into individual records.
>
> How would I do that?
>
> Günther
>
>
> BTW the binary selector problem is resolved, naturaly I can't use '.' and
> I reckon neither can I use ';' for that matter.


Reply | Threaded
Open this post in threaded view
|

Re: reading from a 2 dimensional SAFEARRAY

Günther Schmidt
In reply to this post by Günther Schmidt
No need to answer, got it figured out:

elementAt: (Array with: .... )

Günther Schmidt schrieb:

> Hi,
>
> I've made some progress on importing data from Excel files, in
> particular, finding "usedRange" came in very handy.
>
> However this gives me an IDispatch - range object, and that in turn
> gives me a (twodimensional) SAFEARRAY object.
>
> Everything fine up to that point.
>
> Cause I haven't figured out yet how to get deeper into that SAFEARRAY
> and retrieve the "rows", so that I can split them into individual records.
>
> How would I do that?
>
> Günther
>
>
> BTW the binary selector problem is resolved, naturaly I can't use '.'
> and I reckon neither can I use ';' for that matter.


Reply | Threaded
Open this post in threaded view
|

Re: reading from a 2 dimensional SAFEARRAY

Günther Schmidt
In reply to this post by Sebastián Sastre
Dear Sebastion.

you can have the ActiveXWizard create a package on Excel for you and
then run this:

file := FileOpenDialog showModal.


excelApp1 := Excel_Application new.

workbooks := excelApp1 workbooks.

workbook := workbooks open: file lcid:0. "Don't know what lcid:0 is good
for, but required"

activeSheet := workbook activeSheet.

usedRange := activeSheet usedRange "Returns an IDispatch of the actually
used range on this sheet".

array1 := usedRange value. "Returns a 2 dimensional SAFEARRAY"

rows := array1 upperBound: 1. "Returns the upperBound of the 1st array
dimension, ie. the number of rows"

columns := array1 upperBound: 2. "Returns the upperBound of the 2nd
array dimension, ie. the number of columns"

results := OrderedCollection new.

(1 to: rows) do: [:row | | resultRow|
resultRow := OrderedCollection new.

(1 to: columns) do:[ :column | |cell | cell := array1 elementAt: (Array
with: row with: column) "Returns a VARIANT object which can be converted
into a Smalltalk 'primitive' object  by sending it #value". resultRow
add: cell].

results add: resultRow].

results inspect.



Hope it helps

Günther




Sebastián Sastre schrieb:

> Hi Günther,
>
>     I'm curios about getting data directly from excel files. Could you post
> a example of it?
>
>     thank you,
>
> Sebastian
>
>
> "Günther Schmidt" <[hidden email]> escribió en el mensaje
> news:[hidden email]...
>
>>Hi,
>>
>>I've made some progress on importing data from Excel files, in particular,
>>finding "usedRange" came in very handy.
>>
>>However this gives me an IDispatch - range object, and that in turn gives
>>me a (twodimensional) SAFEARRAY object.
>>
>>Everything fine up to that point.
>>
>>Cause I haven't figured out yet how to get deeper into that SAFEARRAY and
>>retrieve the "rows", so that I can split them into individual records.
>>
>>How would I do that?
>>
>>Günther
>>
>>
>>BTW the binary selector problem is resolved, naturaly I can't use '.' and
>>I reckon neither can I use ';' for that matter.
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: reading from a 2 dimensional SAFEARRAY

Sebastián Sastre
Dear Günther,

    It worked flawless. Very nice. I'm sure it could be useful

thank you,

Seb


"Günther Schmidt" <[hidden email]> escribió en el mensaje
news:[hidden email]...

> Dear Sebastion.
>
> you can have the ActiveXWizard create a package on Excel for you and then
> run this:
>
> file := FileOpenDialog showModal.
>
>
> excelApp1 := Excel_Application new.
>
> workbooks := excelApp1 workbooks.
>
> workbook := workbooks open: file lcid:0. "Don't know what lcid:0 is good
> for, but required"
>
> activeSheet := workbook activeSheet.
>
> usedRange := activeSheet usedRange "Returns an IDispatch of the actually
> used range on this sheet".
>
> array1 := usedRange value. "Returns a 2 dimensional SAFEARRAY"
>
> rows := array1 upperBound: 1. "Returns the upperBound of the 1st array
> dimension, ie. the number of rows"
>
> columns := array1 upperBound: 2. "Returns the upperBound of the 2nd array
> dimension, ie. the number of columns"
>
> results := OrderedCollection new.
>
> (1 to: rows) do: [:row | | resultRow|
> resultRow := OrderedCollection new.
>
> (1 to: columns) do:[ :column | |cell | cell := array1 elementAt: (Array
> with: row with: column) "Returns a VARIANT object which can be converted
> into a Smalltalk 'primitive' object  by sending it #value". resultRow add:
> cell].
>
> results add: resultRow].
>
> results inspect.
>
>
>
> Hope it helps
>
> Günther
>
>
>
>
> Sebastián Sastre schrieb:
>> Hi Günther,
>>
>>     I'm curios about getting data directly from excel files. Could you
>> post a example of it?
>>
>>     thank you,
>>
>> Sebastian
>>
>>
>> "Günther Schmidt" <[hidden email]> escribió en el mensaje
>> news:[hidden email]...
>>
>>>Hi,
>>>
>>>I've made some progress on importing data from Excel files, in
>>>particular, finding "usedRange" came in very handy.
>>>
>>>However this gives me an IDispatch - range object, and that in turn gives
>>>me a (twodimensional) SAFEARRAY object.
>>>
>>>Everything fine up to that point.
>>>
>>>Cause I haven't figured out yet how to get deeper into that SAFEARRAY and
>>>retrieve the "rows", so that I can split them into individual records.
>>>
>>>How would I do that?
>>>
>>>Günther
>>>
>>>
>>>BTW the binary selector problem is resolved, naturaly I can't use '.' and
>>>I reckon neither can I use ';' for that matter.
>>
>>


Reply | Threaded
Open this post in threaded view
|

about reading from Excel

Günther Schmidt
Dear Sebastian,

there are a few things that keep giving me trouble with Excel, and that
is when the Excel Application shuts down, it asks about whether  or not
to save the changes in the opened spreadsheets.

Do you know of a setting which will turn this prompting off?
I've seen some things like "rejectAllChanges" but that doesn't seem to work.


Günther


Sebastián Sastre schrieb:

> Dear Günther,
>
>     It worked flawless. Very nice. I'm sure it could be useful
>
> thank you,
>
> Seb
>
>
> "Günther Schmidt" <[hidden email]> escribió en el mensaje
> news:[hidden email]...
>
>>Dear Sebastion.
>>
>>you can have the ActiveXWizard create a package on Excel for you and then
>>run this:
>>
>>file := FileOpenDialog showModal.
>>
>>
>>excelApp1 := Excel_Application new.
>>
>>workbooks := excelApp1 workbooks.
>>
>>workbook := workbooks open: file lcid:0. "Don't know what lcid:0 is good
>>for, but required"
>>
>>activeSheet := workbook activeSheet.
>>
>>usedRange := activeSheet usedRange "Returns an IDispatch of the actually
>>used range on this sheet".
>>
>>array1 := usedRange value. "Returns a 2 dimensional SAFEARRAY"
>>
>>rows := array1 upperBound: 1. "Returns the upperBound of the 1st array
>>dimension, ie. the number of rows"
>>
>>columns := array1 upperBound: 2. "Returns the upperBound of the 2nd array
>>dimension, ie. the number of columns"
>>
>>results := OrderedCollection new.
>>
>>(1 to: rows) do: [:row | | resultRow|
>>resultRow := OrderedCollection new.
>>
>>(1 to: columns) do:[ :column | |cell | cell := array1 elementAt: (Array
>>with: row with: column) "Returns a VARIANT object which can be converted
>>into a Smalltalk 'primitive' object  by sending it #value". resultRow add:
>>cell].
>>
>>results add: resultRow].
>>
>>results inspect.
>>
>>
>>
>>Hope it helps
>>
>>Günther
>>
>>
>>
>>
>>Sebastián Sastre schrieb:
>>
>>>Hi Günther,
>>>
>>>    I'm curios about getting data directly from excel files. Could you
>>>post a example of it?
>>>
>>>    thank you,
>>>
>>>Sebastian
>>>
>>>
>>>"Günther Schmidt" <[hidden email]> escribió en el mensaje
>>>news:[hidden email]...
>>>
>>>
>>>>Hi,
>>>>
>>>>I've made some progress on importing data from Excel files, in
>>>>particular, finding "usedRange" came in very handy.
>>>>
>>>>However this gives me an IDispatch - range object, and that in turn gives
>>>>me a (twodimensional) SAFEARRAY object.
>>>>
>>>>Everything fine up to that point.
>>>>
>>>>Cause I haven't figured out yet how to get deeper into that SAFEARRAY and
>>>>retrieve the "rows", so that I can split them into individual records.
>>>>
>>>>How would I do that?
>>>>
>>>>Günther
>>>>
>>>>
>>>>BTW the binary selector problem is resolved, naturaly I can't use '.' and
>>>>I reckon neither can I use ';' for that matter.
>>>
>>>
>


Reply | Threaded
Open this post in threaded view
|

Re: about reading from Excel

Schwab,Wilhelm K
Günther,

> there are a few things that keep giving me trouble with Excel, and that
> is when the Excel Application shuts down, it asks about whether  or not
> to save the changes in the opened spreadsheets.
>
> Do you know of a setting which will turn this prompting off?
> I've seen some things like "rejectAllChanges" but that doesn't seem to
> work.

At least with Word, there is an optional argument to Quit() - look at my
Word Automation package (WordAutomation>>stop), and better yet, VBA for
Dummies for details.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]