preload
Jan 08

One project that I’m currently working on calls for taking tasks out of a MS Project document and moving them to a Powerpoint presentation with pretty formatting. Maybe I’ll blog about the whole thing later.  Here’s a quick program I wrote to dump out all the tasks from a test project in a somewhat formatted output to verify I could actually get the tasks:

#!C:\ruby\bin\ruby.exe

require 'exo/iswindows'

if !RUBY_PLATFORM.isWindows?
   puts "This program only runs under Windows!"
   exit
 end

require 'win32ole'

def fmtMSProjDate(msdate)
   yr = msdate[/^(\d\d\d\d)\/\d\d/, 1]
   mth = msdate[/^\d\d\d\d\/(\d\d)\/\d\d/, 1]
   day = msdate[/^\d\d\d\d\/\d\d\/(\d\d) /, 1]
   return "#{mth}/#{day}/#{yr}"
end

def getAbsolutePathName(file)
   fso = WIN32OLE.new('Scripting.FileSystemObject')               ## VBA File System commands
   return fso.GetAbsolutePathName(file)
end

if !ARGV[0][/\:/]
  file = "#{Dir.pwd}/#{ARGV[0]}"
else
  file = ARGV[0]
end

app = WIN32OLE.new('MSProject.Application')
app.FileOpen(getAbsolutePathName(file))
pj = app.ActiveProject
#app.Visible = true

puts "\nProject: #{pj.Title.ljust(60)}" + fmtMSProjDate(pj.Start.to_s) + "  " + fmtMSProjDate(pj.Finish.to_s) + "\n\n"

pj.Tasks.each do |t|
   puts t.ID.to_s.rjust(5) + " " + "| "*t.OutlineLevel + t.Name.ljust(63-(t.OutlineLevel*2)) + fmtMSProjDate(t.Start.to_s) + "  " + fmtMSProjDate(t.Finish.to_s)
end

app.Quit

Here’s my test run:
Continue reading »

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with: