Applescript that multiplies cells in column

Brian C. dvorak at omnigroup.com
Mon Feb 24 21:11:01 PST 2003


I must be learning something. That was actually kinda easy and didn't 
make me want to die.

You have to do a little hackery to get around the fact that the 
columns' positions aren't fixed within the document. (Thanks Steve!)

> tell application "OmniOutliner"
> 	-- "Trip" column - Rich Text, no summaries
> 	-- "Hours" column - number (integer), no summaries
> 	-- "Gallons/Hour" column - number (decimalized), no summaries
> 	-- "Fuel Price" column - number (dollar amount), no summaries
> 	
> 	-- This calculates values for the "Total Expense" column, which
> 	-- should be numeric (dollar) with calculated summaries.
> 	
> 	set targetDocument to first document
> 	set columnCount to count of columns of targetDocument
> 	repeat with columnIndex from 1 to columnCount
> 		if title of column columnIndex of targetDocument is "Trip" then
> 			set tripIndex to columnIndex
> 		end if
> 		if title of column columnIndex of targetDocument is "Hours" then
> 			set hourIndex to columnIndex
> 		end if
> 		if title of column columnIndex of targetDocument is "Gal./Hour" then
> 			set consumptionIndex to columnIndex
> 		end if
> 		if title of column columnIndex of targetDocument is "$/Gal." then
> 			set priceIndex to columnIndex
> 		end if
> 		if title of column columnIndex of targetDocument is "Total Expense" 
> then
> 			set expenseIndex to columnIndex
> 		end if
> 	end repeat
> 	
> 	set theList to every row of targetDocument
> 	repeat with myRow in theList
> 		tell myRow
> 			try
> 				set hourValue to value of cell hourIndex
> 				set galsPerHourValue to value of cell consumptionIndex
> 				set priceValue to value of cell priceIndex
> 				
> 				set value of cell expenseIndex to (hourValue * galsPerHourValue * 
> priceValue)
> 				
> 			on error errormessage number errornumber
> 				display dialog errormessage buttons {"OK"} default button 1
> 			end try
> 		end tell
> 	end repeat
> 	
> end tell

  If you have any other questions or suggestions, please don't hesitate 
to contact me. When replying, please include the quoted text of this 
message. We really appreciate your help!

Sincerely,

Brian C.
Support Manager
Omni Group


On Monday, February 24, 2003, at 01:42  PM, Tricia Geib wrote:

> Hello,
> 	I am just beginning to learn Applescript, and I was wondering whether 
> anyone had already developed a script that would multiply within a 
> column (similar to the way OO already is able to add a column).
> 	For example, I am using OmniOutliner as a basic accounting program to 
> track my flying expenses, and I'd like to calculate the fuel cost of 
> flying x number of hours if I use 8 gallons per hour and fuel is > $2.50.
> 	So, I have a column for Fuel with children: hours, price per gallon, 
> gallons per hour, and a column with their values. I would like to be 
> able to multiply these and show the total cost per month based on the 
> hours flown either in the same column at the level of item: Fuel, or 
> in a different column.
> 	Obviously, this would be easy to do in Excel, but I'm sure if I had a 
> better grasp of Applescript I could work it out. Anybody already 
> develop a script to do this?
>
> Thanks!
> T. Geib
>
> _______________________________________________
> OmniOutliner-Users mailing list
> OmniOutliner-Users at omnigroup.com
> http://www.omnigroup.com/mailman/listinfo/omnioutliner-users




More information about the OmniOutliner-Users mailing list