Design script write to Excel

I wish to write a for loop that performs calculations in excel for given inputs and then gives me a list of all the solutions. I think that I need to add a reference here but I’m not sure where. Any help would be greatly appreciated. Thanks,

a=[Imperative]
{
b = 1…5;
c=0;
d={};
e=0;
t7=p;

for (i in b)
{
x = i;
t8 = DSOffice.Excel.WriteToFile(t7, “Design”, 11, 1, x, false);
d[e] = t8[5][1];

e = e+1;
}

return = d;
};

One solution is to create one node that will save all the data to Excel and create another one that will read data from Excel and then make changes to model.

Otherwise you still need to save all the data to Excel and then read it again.

I think that it would be much easier to make your calculations using Python or Code Blocks.

I am not entirely sure what you are trying to achieve.

Generally speaking, I would recommend using Python or Code Blocks.
However, I might be able to provide some assistance in regards to your current implementation.

Your current code is overwriting the data you send to Excel at each iteration, is this intentional?

If you are running the same version of Dynamo as I am, I think your Excel call should be “Excel.WriteToFile(t7,“Design”,11,1,x,false);” instead of “DSOffice.Excel.WriteToFile(t7,“Design”,11,1,x,false);”
See attached image

I think that your variable t8 is a list of lists containing only one value, which is why you get “null” when you return your “d” variable.
I hope it helps!

Capture

1 Like

Why not just perform the calculations directly in Dynamo?

I am using a company spreadsheet that has all the equations built in. It would be more time consuming to retype the equations into Dynamo.

It works, thanks