welcome to reading an Excel spreadsheet
using Python for dynamo so here I have a
real simple Excel spreadsheet it's got a
few sheets and a few sheet names and
here's kind of an empty Python note that
I'll go ahead and take and I like using
visual studios because it has the
intellisense which always helped me
write so I'm going to go ahead and
import Excel from ironpython using
the.net language of dot-com and I'll go
ahead and post or you can find this also
like it so you can just copy and paste
it like myself it's kind of a long
reference it's got the excel the version
the the token key it's kind of long but
the next thing you need to do is from
Microsoft Office interrupt you need to
import Excel it after you have Excel you
need to get the system run time Interop
which will give you the current
application that's running at the moment
and you want to get the marshal which
will allow you to shut things down since
we're not going to make this visible you
need to be able to close it manually so
the first thing I'll do is from the node
itself
I'll get the path being brought in
through the dynamo node and then from
here I'll use my Excel import and I'll
import the application class and then
the visibility I'll set it to false so
we won't be able to see it that's why we
need to shut it down manually and then
if it displays an alert will set it
default so it doesn't display any any
alerts to us and then the workbook that
I'll get is what I'll send in from my
path so I'll go ahead and get the
workbook you can hard code the open path
but you can also send that in through
another Dynamo node which is very useful
and then once we have our workbook we
need our
our worksheet and then the worksheets
are in an array so the first worksheet
second worksheet third worksheet so
we'll just go ahead and grab the first
worksheet that is in our excel file and
then we can go ahead and grab a range
instead of just grabbing a single cell
we'll grab a whole array of of cells so
from our worksheet we'll get a range and
these are in strings if if you feel that
your array will change you can always
concatenate or restrain build these
these strings but I'll just go hard code
them in a 1 through a 4 and then I'll
get a second range on the on the second
line of or the second column which will
be the b1 through the B before which
will be the column right next to it
so here I'll just grab the the the range
value for my first range and then for my
second range I'll send that value to r2
and then I'll go ahead and send this out
to my next Dynamo node so that will be
the R r1 and then I'll send out the r2
and here's where or I need to use my
Marshall so I'll first make sure that
the active active workbook is is going
to be closed and if there's defaults
I'll set that default and then the next
part is is actually using the Marshall
getting hold of any run run running
instances of whatever I've got and just
do use the Marshall calm object and I'll
send in all all the objects that that
I've generated here which will be the
worksheet now I'll just copy and paste
that same code because I want to also
close my workbook and the
the very last thing I'll do is I'll send
in my application itself which is the X
II and then I'll copy and paste it into
my Dynamo script I'll select my final
path of my sheet then I want to run it
this is a previous sheet script that I
wrote there's also a video on YouTube
for this if you're interested just
Fell's missing a bracket there
tell me so we'll look for something with
a bracket path it's like it's like my
path this is it's got something up
missing the first array so we'll go
ahead and resend it and it'll take in my
script and build some sheets and for the
first column and the second column of
the first column of the sheets send
column the names so that's about it
simple as that
thank you for watching