Skip to content

Instantly share code, notes, and snippets.

@ricdeez
Created December 13, 2012 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ricdeez/4280889 to your computer and use it in GitHub Desktop.
Save ricdeez/4280889 to your computer and use it in GitHub Desktop.
MS Project: List of tasks matching a pattern, sorted by one parameter
#!/usr/bin/ruby
%w( win32ole pp date ).each { |dep| require dep }
doc = 'C:\Users\rdapaz\Dropbox\Karara\Schedule\K2 Master Schedule - Delayed FAT Scenario.mpp'
mpp = WIN32OLE.new('MSProject.Application')
mpp.Visible = true
mpp.FileOpen(doc)
tasks = []
mpp.ActiveProject.Tasks.each do |tsk|
if tsk && /\(Switchroom Workshop\)/i.match(tsk.Name)
# The win32ole library already parses the datetime in the format "%F %X %z"
start = tsk.Start.strftime("%d/%m/%Y")
finish = tsk.Finish.strftime("%d/%m/%Y")
tasks << [tsk.Name, tsk.Start, tsk.Finish]
end
end
tasks.sort { |a,b| a[1] <=> b[1]}.each do |desc, start, finish|
start = start.strftime("%d/%m/%Y")
finish = finish.strftime("%d/%m/%Y")
puts [desc, start, finish].join("|")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment