"Ruby Tuesday" <rubytuzdayz / yahoo.com> wrote in message
> Is there any good Ruby example that manipulate any Office Docoments,
> especially the Access database?

This should get you started ...

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>cd atest

C:\atest>type tst_access.rb

require 'win32ole'

MDB_FILE_NAME = "C:\\Program Files\\Microsoft
Office\\Office10\\Samples\\Northwind.mdb"

# Create the object
db=WIN32OLE.new("ADODB.Connection")

# Set parameters
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"  +
                                    "Data Source=\"#{MDB_FILE_NAME}\""

# Open connection
db.open

# Construct query string
sSQL = "select top 10 * from [Order Details]"

# Execute Query
rs = db.Execute(sSQL)

# Print first line of header
puts
n = 0
rs.fields.each do |field|
  print "%10s " % [field.name]
  n += 1
end
puts

# Print second line of header
n.times{print "%10s " % ['-'*10]}
puts

# Fetch the first record
rs.MoveFirst if !rs.eof

# Loop till no more records
while !rs.eof

  # Print each row
  rs.fields.each do |field|
    print "%10s " % [field.value]
  end
  puts

  # Fetch the next record
  rs.MoveNext

end

# Close connection
db.close

__END__

C:\atest>ruby -v tst_access.rb
ruby 1.8.1 (2004-01-27) [i386-mswin32]

   OrderID  ProductID  UnitPrice   Quantity   Discount
---------- ---------- ---------- ---------- ----------
     10248         11         14         12        0.0
     10248         42        9.8         10        0.0
     10248         72       34.8          5        0.0
     10249         14       18.6          9        0.0
     10249         51       42.4         40        0.0
     10250         41        7.7         10        0.0
     10250         51       42.4         35 0.150000005960464
     10250         65       16.8         15 0.150000005960464
     10251         22       16.8          6 0.0500000007450581
     10251         57       15.6         15 0.0500000007450581

C:\atest>