Connecting to Excel

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
byronnash
Posts: 321
Joined: July 7th, 2004, 2:30 pm
Location: Charlotte, NC
Contact:

I had a script working at one time that interfaced Excel and Photoshop. I am trying to get some of the elements to work with AE. Below is the script lines I'm trying to use:

// Conect with Excel
var appexcel = "Excel.Application";

// Open a Excel XLS file - just type the path with double backslashes..
var wb = appexcel.Workbooks.Open("C:\\Interstitials 2004 NCTS.xls");

// Select the worksheet to work with - Asuming your data is in the first worksheet
var ws = wb.worksheets(1);

// Main loop - it reads the first 8 rows, and the first 3 columns as an example
for (row=3 ; row<36 ; row++) {
// Get the values
var firstname = ws.Cells(row, 1);
var lastname = ws.Cells(row, 2);
var number = ws.Cells(row, 3);
//After that, I would use the data to create or modify text layers.


_________________________________

The part that is giving me trouble is the wb.worksheets(1) line. AE gives me an error saying "Function wb.Worksheets is undefined" Does anyone have any idea what that means? Like I said, I had that info working with PS and also with Softimage XSI. It almost seems that AE does not use the same COM object or something.

Thanks all...
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

posting for keiko yamada:

AE does not support VB script (Photoshop CS does). So the very first line does not create an object.

Workaround for this (I've not tested this, but I think it works):
1) Export excel worksheet as tab separated text file.
2) open txt file and readln() -- use tab (\t) as a separator while storing data from text file.

-keiko


Also, you should send in a feature request for this to: aftereffects@adobe.com
Paul T
byronnash
Posts: 321
Joined: July 7th, 2004, 2:30 pm
Location: Charlotte, NC
Contact:

Are you sure that Javascript cannot access Excel? I pulled most of that code out of some other Javascript examples I was using for PS and XSI. I also used this link for guidance.

http://msdn.microsoft.com/library/defau ... object.asp

Maybe Jscript can access Excel where Javascript cannot? I will put in a feature request for this, we get a lot of data in Excel files. Thanks for getting back to me.
Darkmoon_UK
Posts: 62
Joined: September 5th, 2006, 3:45 am
Location: Chiswick, London, UK
Contact:

Please jump in to correct me if I'm wrong...

I think the problem here is that the JavaScript engine used by After Effects is a 'sand-boxed' Adobe engine and, though similar, it's certainly not the same as the one used by IE in Windows. Because of this it lacks the same ActiveX connections and many other capabilities that allow cross-talk with other Windows objects.

I've come to this conclusion having tried many methods demonstrated online, for reading Excel data into JavaScript. All seem to rest on the non-existant GetObject() method and ActiveXObject() object.

It feels cold and lonely, but its seems like our AE scripting environment is a desert island, with only a TCP connection's hope to cling to...

(Yes, the standard advice to import CSV abounds, but that doesn't mean we have to like it...).
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

The one thing I notice is that you reference "worksheet(1)"

In my VB version I simply referenced "Sheets(1)"

Maybe it is something as simple as that?

Try changing worksheet(1) to Sheets(1)
Darkmoon_UK
Posts: 62
Joined: September 5th, 2006, 3:45 am
Location: Chiswick, London, UK
Contact:

Atomic: Does your VB version rely on the GetObject() or ActiveXObject() functions. If so, these simply do not exist in AE's scripting environment. Refer to my previous post.

I just sent a feature request to Adobe over this, surely what they've done for Photoshop they could do for After Effects. It would open up a lot of possibilities for us.
Last edited by Darkmoon_UK on November 7th, 2007, 9:07 am, edited 1 time in total.
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

I guess your right, I can not connect either. Jscript is Microsoft based and After Effects Javascript seems to be proprietary.

I did find this arcticle:
http://www.creative-workflow-hacks.com/ ... r-effects/

So how does this TCP connection work?

Is that built in to After Effects Javascript?
bradshaw1965
Posts: 98
Joined: March 14th, 2006, 2:16 pm
Location: Atlanta, GA
Contact:

So how does this TCP connection work?
The Socket Object is pretty handy for doing TCP stuff. You can also filter TCP requests through callSystem();
Dale Bradshaw
Technology Director | Primal Screen
creative-workflow-hacks.com
Atlanta, GA
Darkmoon_UK
Posts: 62
Joined: September 5th, 2006, 3:45 am
Location: Chiswick, London, UK
Contact:

Well, I ran with the TCP idea and came up with a Client/Server application to improve this situation, the 'Excel to ExtendScript Bridge'.

Check it out here: http://www.aenhancers.com/viewtopic.php ... 3416#p3416
Post Reply