Excel 2004 scripting

Hi All,

I know how to write script for quark. But I am new to Excel 2004 applescripting.

I have the following task with me.

I have an excel sheet that contains 3 columns.
First column (A) contains hierarchy level number.
Second column (B) contains xml tag.
Third column (C) contains quark stylesheet names.

For examples:
A B C
0 chapter
CHAP_NUM
1 title CHAP_TTL
1 section[@role=‘fm’]
2 objectiveset
3 supertitle CF_OBJSET_SUPTTL
3 para
CF_OBJSET
3 objective
CF_OBJ

If I select the C-column cell containing “CF_OBJ”, it should go through the hierarchy levels (say 3-2-1-0) and I should get the answer as
“chapter\ section[@role=‘fm’]\objectiveset\objective”.

I don’t know whether it is possible with applescript. Please help me.

Thanks,
Krishnan

The first question is how do you know what is before your selected item in the hierarchy? In your example you select an item in column C, CF_OBJ, and get the text from column C for the last item in your list. Then you need to fill in the items before it based off of the number in column A. For the third item it is fairly easy because there is only one level 2 in your table, so it is objectiveset from column B. Now to get the second item how are you distinguishing between the two item 1’s (section[@role=‘fm’] and title) listed in your table? If there is no clear way to determine this from the data then I don’t know if you can do what you want.

That said the a start to your task is:

tell application "Microsoft Excel"
	set CurrentRow to first row index of selection
	set currentColum to first column index of selection
	set MyCounter to value of range ("A" & CurrentRow)
	set MyHierarchy to {value of range ("B" & CurrentRow)}
end tell
return MyHierarchy

This will get the row value of the selection and copy the level to MyCounter, so you can track how many levels to add before the selected level in the hierarchy, and then the name of the xml tag to MyHierarchy. You should be able to repeat through the Excel document to fill in the xml tags once you have a way of distinguishing the ones that you need in the particular level of your hierarchy.