summaryrefslogtreecommitdiff
path: root/ext/win32ole/sample/excel1.rb
blob: 7136c938a3eff244a3e6c794444077eb623be8d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'win32ole'

application = WIN32OLE.new('Excel.Application')

application.visible = TRUE
workbook = application.Workbooks.Add();
worksheet = workbook.Worksheets(1);

=begin
worksheet.Range("A1:D1").value = ["North","South","East","West"];
worksheet.Range("A2:B2").value = [5.2, 10];

worksheet.Range("C2").value = 8;
worksheet.Range("D2").value = 20;
=end

worksheet.Range("A1:B2").value = [["North","South"],
                                  [5.2, 10]];

vals = WIN32OLE_VARIANT.new([["East","West"],
                             [8, 20]],
                            WIN32OLE::VARIANT::VT_ARRAY)
worksheet.Range("C1:D2").value = vals

range = worksheet.Range("A1:D2");
range.Select
chart = workbook.Charts.Add;

workbook.saved = TRUE;

print "Now quit Excel... Please enter."
gets

application.ActiveWorkbook.Close(0);
application.Quit();