robust_excel_ole 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,791 @@
1
+ = RobustExcelOle
2
+
3
+ This ruby gem automates modifying, reading and writing Excel files.
4
+ It supports simultaneously running Excel instances and user interactions.
5
+ RobustExcelOle deals with various cases of Excel and user behaviour,
6
+ and implements workarounds for some Excel bugs.
7
+ The gem provides convenient methods for common tasks, and facilitates referenced libraries.
8
+ It supports Excel 2010 and Excel 2007.
9
+
10
+ RobustExcelOle works by sending VBA methods via Win32OLE.
11
+ Moreover, it implements a management system and keeps track of Excel files and Excel instances.
12
+
13
+ == Requirements
14
+
15
+ * Ruby 1.8.6 or higher
16
+
17
+ == Install
18
+
19
+ gem install robust_excel_ole
20
+
21
+ == Usage
22
+
23
+ include RobustExcelOle
24
+
25
+ === Opening a workbook.
26
+
27
+ Example:
28
+
29
+ book = Book.open('workbook.xls')
30
+
31
+ You can also open a workbook with a block.
32
+ The semantics is similar to, e.g., +File.open+.
33
+
34
+ Book.open('workbook.xls') do |book|
35
+ # do something
36
+ end
37
+
38
+ Options are the following:
39
+
40
+ +:default+:: if the workbook was already open, then use the properties of this workbook.
41
+ otherwise use the properties stated in +:default+
42
+
43
+ +:force+:: no matter whether the workbook was open before, use the properties stated in +:force+
44
+
45
+ +:excel+ and +:visible+ are options stated in +:default+ and +:force+
46
+
47
+ +:excel+:: specifies the Excel instance.
48
+ +:visible+:: makes the workbook visible or invisible
49
+
50
+ +:if_unsaved+:: specify behaviour if the workbook was unsaved (default: +new_excel+)
51
+ +:if_obstructed+:: specify behaviour if the workbook is blocked by another book (default: +new_excel+)
52
+ +:read_only+:: open in read-only mode (default: +false+)
53
+ +:check_compatibility:: check compatibility when saving
54
+ +:calculation+:: forces the calculation mode to be manual (:manual) or automatic (:automatic)
55
+ +:if_absent+:: specify behaviour if the workbook with the given file name does not exist if the workbook does not exist (default: +create+)
56
+
57
+ Here are some details:
58
+
59
+ The option +:excel+ :
60
+
61
+ Valid values are : +:current+ (or +:active+ or +:reuse+), +:new+, or a given Excel instance (default: +:current).
62
+
63
+ The option +:if_unsaved+ :
64
+
65
+ If a workbook contains unsaved changes and a new workbook with the same file name shall be opened, then
66
+
67
+ +:raise+:: Raise an exeption. Don't open the workbook.
68
+ +:accept+:: Let the unsaved workbook open.
69
+ +:forget+:: Discard any changes and reopen the workbook.
70
+ +:new_excel+:: Open the new workbook in a new Excel instance
71
+ +:alert+:: Give control to Excel.
72
+
73
+ The option +:if_obstructed+ :
74
+
75
+ If a workbook is open and a new workbook with same name and a different path is open, then
76
+
77
+ +:raise+:: Raise an exception. Don't open the workbook.
78
+ +:forget+:: Close the old workbook, open the new workbook.
79
+ +:save+:: Save the old workbook, close it, open the new workbook
80
+ +:close_if_saved+:: Close the old workbook and open the new workbook, if the old workbook is saved, otherwise raise an exception.
81
+ +:new_excel+:: Open the new workbook in a new Excel instance.
82
+
83
+ The option +:if_absent :
84
+
85
+ If the Excel file does not exists, then
86
+
87
+ +:create+:: Create a new Excel file
88
+ +:raise+:: Raise an exception.
89
+
90
+ Here are a few examples:
91
+
92
+ If you want to open a workbook that was not opened before, or reopen a workbook that was open in an Excel instance that is now closed, in the current (active) Excel instance, then use
93
+
94
+ Book.open('workbook.xls', :default => {:excel => :current})
95
+
96
+ or
97
+
98
+ Book.open('workbook.xls')
99
+
100
+ In case you want to open such a workbook in a new Excel instance, then use
101
+
102
+ Book.open('workbook.xls', :default => {:excel => :new})
103
+
104
+ If you want to open a workbook in a new Excel instance, no matter if it was opened before, you can write
105
+
106
+ Book.open('workbook.xls', :force => {:excel => :new})
107
+
108
+ You can also specify an Excel instance
109
+
110
+ excel1 = Excel.create
111
+ # something
112
+ Book.open('workbook.xls', :force => {:excel => excel1})
113
+
114
+ If you want to open the workbook and make its window visible, then use
115
+
116
+ book = Book.open('workbook.xls', :force => {:visible => true})
117
+
118
+ You can combine options, e.g.
119
+
120
+ Book.open('workbook.xls', :force => {:excel => :new, :visible => true})
121
+
122
+ You can use some abbreviations, e.g. in this case
123
+
124
+ Book.open('workbook.xls', :f => {:e => :new, :v => true})
125
+
126
+ If a workbook contains unsaved changes and a workbook with the same filename shall be opened, then the option +:if_unsaved+ manages this conflict. For example, if the workbook with the unsaved changes shall remain open, you can use
127
+
128
+ book = Book.open('workbook.xls', :if_unsaved => :accept)
129
+
130
+ If a workbook is open and a workbook with the same name but in different path shall be opened, i.e. the first workbook blocks opening the other workbook, then the option +:if_obstructed+ handles this situation, e.g.
131
+
132
+ book = Book.open('path/workbook.xls', :if_obstructed => :forget)
133
+
134
+ Remarks:
135
+
136
+ Opening linked workbooks for EXCEL 2007 is supported
137
+
138
+ Doing updating links seems to be dependent on calculation mode: updates happen, if the calcultion mode is automatic, and does not happen, if calculation mode is manual.
139
+
140
+ === Closing a workbook.
141
+
142
+ Simple close.
143
+
144
+ book.close
145
+
146
+ There is one option: +:if_unsaved+ . It can have one of the following values:
147
+
148
+ +:raise+ (default), +:save+, +:forget+, +:alert+
149
+
150
+ The option specifies: If the workbook is unsaved, then
151
+
152
+ +:save+:: Save the workbook before closing it.
153
+ +:raise+:: Raise an exception. Don't close the workbook.
154
+ +:forget+:: Close the workbook.
155
+ +:alert+:: Give control to Excel.
156
+
157
+ === Reopening a workbook.
158
+
159
+ A special feature of robust_excel_ole is that it allows to reopen workbooks after closing them.
160
+
161
+ book = Book.open('workbook.xls')
162
+ book.close
163
+ book.reopen
164
+
165
+ The closed workbook is now alive again, i.e. is open and responds to Excel methods.
166
+
167
+ This feature is a result of providing identity transparence and storing the file name.
168
+
169
+ === The Book objects and transperence identity
170
+
171
+ An Excel file (or workbook) is represented by a Book object. A Book object is defined by the full name of the workbook and the Excel instance in which it is opened. RobustExcelOle aims to ensure identity transperency.
172
+ Identity transparence means that the same Book objects refer to the same Excel files, and vice versa.
173
+ In other words, a Book objects is a proxy of an Excel file.
174
+
175
+ === Promoting a workbook to a Book object
176
+
177
+ A Book object can be created when giving an Excel workbook.
178
+
179
+ book = Book.new(win32ole_workbook)
180
+
181
+
182
+ === Saving a workbook.
183
+
184
+ Simple save.
185
+
186
+ book.save
187
+
188
+ If you want to save a workbook with a file name, then use
189
+
190
+ book.save_as('another_workbook.xls')
191
+
192
+ The options are the following:
193
+
194
+ +:if_exists+:: +:raise+ (default), +:overwrite+, +:alert+
195
+ +:if_obstruced+:: +:raise (default), +:forget+, +:save+, +close_if_saved
196
+
197
+ The option +:if_exists+ :
198
+
199
+ If a workbook with the file name already exists, then
200
+
201
+ +:raise+:: Raise an exeption. Don't write the file.
202
+ +:overwrite+:: Delete the existing file and write the file. If the workbook is open in an Excel instance, then raise an exception.
203
+ +:alert+:: Give the control to Excel.
204
+
205
+ Examples:
206
+
207
+ If you want to save a workbook and overwrite the file if it exists before, then use
208
+
209
+ book.save_as('another_workbook.xls', :if_exists => :overwrite)
210
+
211
+ If a workbook blocks the workbook that should be saved, then the former one can be saved and closed before.
212
+
213
+ book = Book.open('workbook.xls')
214
+ book2 = Book.open('another_workbook.xls')
215
+ book2.save_as('dir/workbook.xls', :if_exists => :overwrite, :if_obstructed => :save)
216
+
217
+ === Unobtrusively modifying a workbook
218
+
219
+ The method +unobtrusively+ enables the user to read or modify a workbook, no matter if it is open in some Excel instance, if it is saved or unsaved, and if it is writable or not. When opening a workbook unobtrusively, its status remains unchanged. This status includes, whether the workbook is opened or closed, saved or unsaved, readonly or writable.
220
+
221
+ One option chooses the Excel instance in which a closed workbook is opened. The option +:current+ (or +:active+, or +:reuse) (default) indicates that the closed workbook is opened in the Excel instance of the workbook, if it exists, or that another Excel instance is reused. The option +:hidden+ provokes that the closed workbook is opened in a separate Excel instance that is not visible and has no DisplayAlerts. Any following closed workbook would be opened in this Excel instance as well when using this option. Moreover, an Excel instance can be given directly where to open the closed workbook.
222
+
223
+ Options are the following:
224
+
225
+ +:current+ (or +:active, or +:reuse+:): (default) : open a closed workbook in the Excel instance where it was opened most recently, if such an Excel instance exists, otherwise open it in the current (first opened) Excel instance
226
+ +:hidden+:: : open a closed workbook in one separate Excel instance that is not visible and has no displayalerts
227
+ <excel-instance> : open a closed workbooks in the given Excel instance
228
+
229
+ +:read_only+:: Open the workbook unobtrusively for reading only (default: false)
230
+ +:readonly_excel+:: if the workbook is opened only as ReadOnly and shall be modified, then
231
+ true: close it and open it as writable in the excel instance where it was open so far
232
+ false (default) open it as writable in another running excel instance, if it exists,
233
+ otherwise open in a new excel instance
234
+ +:keep_open+:: let the workbook open after unobtrusively opening (default: false)
235
+ +:visible+:: make the window of the workbook visible (default: false)
236
+ +:check_compatibility+:: checks compatibility when saving
237
+
238
+ Book.unobtrusively('workbook.xls') do |book|
239
+ # some modification
240
+ sheet = book[0]
241
+ sheet[1,1] = "c"
242
+ end
243
+
244
+ The methods +for_reading+ and +for_modifying+ indicate unobtrusively reading or modifying.
245
+
246
+ Book.for_modifying('workbook.xls') do |book|
247
+ # some modification
248
+ sheet = book[0]
249
+ sheet[1,1] = "c"
250
+ end
251
+
252
+ === Retaining the saved-status
253
+
254
+ This method ensures keeping the save status of the workbook
255
+
256
+ book = Book.open('workbook.xls')
257
+ book.retain_saved do
258
+ # some reading or modifying
259
+ end
260
+
261
+ === Checking whether the workbook is alive.
262
+
263
+ This method finds out whether the Excel workbook that is referenced by the Book object responds to methods.
264
+
265
+ if book.alive? then sheet = book[0] end
266
+
267
+ === Getting and setting the contents of a range in a workbook.
268
+
269
+ You can get the contents of a range with
270
+
271
+ book["name"]
272
+ => "value"
273
+
274
+ or
275
+
276
+ book.nameval("name")
277
+ => "value"
278
+
279
+ You can set the contents of a range with
280
+
281
+ book["name"] = "value"
282
+
283
+ or
284
+
285
+ book.set_nameval("name") = "value"
286
+
287
+ === Bringing a workbook to the focus.
288
+
289
+ If you want to make the workbook visible and available for keyboard inputs, use
290
+
291
+ book.focus
292
+
293
+ === Making the window of the workbook visible
294
+
295
+ You can make the window of the workbook invisible or visible
296
+
297
+ book.visible = false
298
+ book.visible = true
299
+
300
+ === Making an Excel visible or invisible, and enable and disable DisplayAlerts.
301
+
302
+ You can make an Excel visible
303
+
304
+ book.excel.visible = true
305
+
306
+ and enable DisplayAlerts
307
+
308
+ book.excel.displayalerts = true
309
+
310
+
311
+ === Accessing a worksheet.
312
+
313
+ You can access a worksheet by giving the number
314
+
315
+ sheet = book.sheet(1)
316
+
317
+ or its name
318
+
319
+ sheet = book.sheet('Sheet1')
320
+
321
+ You can get the first and last worksheet with
322
+
323
+ sheet = book.first_sheet
324
+
325
+ and
326
+
327
+ sheet = book.last_sheet
328
+
329
+ You can access all sheet objects by using the methods Book#each.
330
+
331
+ book.each do |sheet|
332
+ # do something with sheet
333
+ end
334
+
335
+ === Accessing cells, rows and columns.
336
+
337
+ A sheet object is enumerable. Use the methods Sheet#each_column, Sheet#each_row or Sheet#each.
338
+
339
+ sheet.each do |cell|
340
+ # do something with cell
341
+ # read every row every column
342
+ end
343
+
344
+ sheet.each_row do |row|
345
+ # do something with row
346
+ end
347
+
348
+ sheet.each_column do |column|
349
+ # do something with column
350
+ end
351
+
352
+ === Accessing a cell.
353
+
354
+ You can read a cell from a sheet object
355
+
356
+ sheet[1, 1] => first cell (first row, first column).
357
+
358
+ or a range object
359
+
360
+ row_range[1] => first cell in row_range
361
+ column_range[2] => second cell in column_range
362
+
363
+ Methods to a cell are just delegated. For example you can read and write the value of a cell
364
+
365
+ cell = sheet[1,1]
366
+ cell.Value => value of the cell.
367
+ sheet[1,1] = "new_value"
368
+
369
+ === Accessing a range of a row or column.
370
+
371
+ You access a range of a row by giving the number of the row, and optionally, the range of the cell numbers.
372
+
373
+ sheet.row_range(1) => first row
374
+ sheet.row_range(1, 1..3 ) => first three cells of the first row
375
+
376
+ Simarly you can access a range of a column.
377
+
378
+ sheet.col_range(3) => third column
379
+ sheet.col_range(3, 1..2) => first two cells of the third column
380
+
381
+ === Naming a cell
382
+
383
+ You can (re-) name a cell range.
384
+
385
+ book.set_name(1,1,"name")
386
+
387
+ === Getting and setting the contents of a named range in a worksheet
388
+
389
+ You get the value of a range by
390
+
391
+ sheet[name]
392
+
393
+ or
394
+
395
+ sheet.nameval(name)
396
+
397
+ You set the value if a range using
398
+
399
+ book[name] = value
400
+
401
+ or
402
+
403
+ book.set_nameval(name,value)
404
+
405
+ === Getting and setting the contents of a named range in a Worksheet directly
406
+
407
+ You get the value of a range with
408
+
409
+ sheet.rangeval(name)
410
+
411
+ and set the value of a range.
412
+
413
+ book.set_rangeval(name,value)
414
+
415
+ === Adding and copying a worksheet.
416
+
417
+ You can add (append) an empty worksheet using
418
+
419
+ book.add_empty_sheet
420
+
421
+ Additionally you can name it.
422
+
423
+ book.add_empty_sheet(:as => 'sheet_name')
424
+
425
+ You can specify the position of the added empty worksheet.
426
+
427
+ book.add_empty_sheet(:as => 'new_name', :before => another_sheet)
428
+
429
+ You can copy a worksheet and add it.
430
+
431
+ book.copy_sheet sheet
432
+
433
+ Additionally you can specify a name and a position.
434
+
435
+ book.copy_sheet(sheet, :as => 'new_name', :after => another_sheet)
436
+
437
+ If you want to copy a worksheet, if a sheet is given, and add an empty worksheet, if no worksheet is given, then use
438
+
439
+ book.add_or_copy_sheet
440
+
441
+ book.add_or_copy_sheet(sheet, :as => 'new_name', :after => another_sheet)
442
+
443
+ === Creating and reusing an Excel instance.
444
+
445
+ If you want to start a new Excel, use
446
+
447
+ excel1 = Excel.create
448
+
449
+ or
450
+
451
+ excel1 = Excel.new(:reuse => false)
452
+
453
+ In case you want to reuse an already running Excel instance, write
454
+
455
+ excel2 = Excel.current
456
+
457
+ or
458
+
459
+ excel2 = Excel.new(:reuse => true)
460
+
461
+ Options are +:reuse+ (+true+, +false+), +:visible+ (+true+, +false+), +:displayalerts+ (+true+, +false+, +:if_visible+), +:calculation+ (+:manual+, +:automatic+, +nil+) and +:screenupdating+ (+true+, +false+).
462
+
463
+ The option +:calculation+ specifies, whether the calculation mode is being forced to be manual (:manual), automatic (+:automatic+) or is not being forced (+nil+).
464
+
465
+ You can also promote an Excel instance represented as WIN32OLE object to an Excel object.
466
+
467
+ excel = Excel.new(win32ole_object)
468
+
469
+ === Making a Excel visible or invisible
470
+
471
+ You can create a new Excel instance and make it visible.
472
+
473
+ excel1 = Excel.create(:visible => true)
474
+
475
+ or
476
+
477
+ excel1 = Excel.new(:reuse => false, :visible => true)
478
+
479
+ or
480
+
481
+ excel1 = Excel.create
482
+ excel1.visible = true
483
+
484
+
485
+ === Enabling or disabling DisplayAlerts
486
+
487
+ You can enable DisplayAlerts with, e.g.
488
+
489
+ excel1 = Excel.new(:reuse => true, :displayalerts => true)
490
+
491
+ or
492
+
493
+ excel1 = Excel.current
494
+ excel1.displayalerts = true
495
+
496
+ and turn DisplayAlerts off with
497
+
498
+ excel1.displayalerts = false
499
+
500
+ You can turn off and off DisplayAlerts in a block.
501
+
502
+ excel = Excel.create
503
+ excel.with_displayalerts false do
504
+ # do something
505
+ end
506
+
507
+ === Making all workbooks visible or invisible
508
+
509
+ excel1.workbooks_visible true
510
+
511
+ excel1.workbooks_visible false
512
+
513
+ === Bringing an Excel instance to the foreground
514
+
515
+ excel1.focus
516
+
517
+ === Closing an Excel
518
+
519
+ excel = Excel.current
520
+ excel.close
521
+
522
+ The method +close has the option +:if_unsaved+ with the values +:raise+, +:save+, +:forget+ and +:alert+.
523
+
524
+ For example, if you want to close an Excel instance and save unsaved workbooks, use
525
+
526
+ excel.close(:if_unsaved => :save)
527
+
528
+ === Closing all Excel instances
529
+
530
+ Excel.close_all
531
+
532
+ This method has the option +:if_unsaved+ as described above. For example, if you want to close all Excel instances containing saved workbooks and raise an error for Excel instances with unsaved workbooks, use
533
+
534
+ Excel.close_all(:if_unsaved => :raise)
535
+
536
+ === Terminating all Excel processes
537
+
538
+ Excel.kill_all
539
+
540
+ This method kills all Excel instances no matter whether they contain unsaved workbooks.
541
+
542
+ === Recreating an Excel instance
543
+
544
+ Closed Excel instances can also be reopened. This includes reopening all workbooks that were open in that Excel instance.
545
+
546
+ excel.close
547
+ excel.recreate
548
+
549
+ The options are :reopen_workbooks, :visible and :displayalerts.
550
+
551
+ excel.recreate(:reopen_workbooks => true, :visible => true, :displayalerts => true)
552
+
553
+ === Providing Excel instances
554
+
555
+ Providing all Excel instances (opened via RobustExcelOle) as objects of the class Excel
556
+
557
+ Excel.excel_processes
558
+
559
+ === Setting Calculation mode.
560
+
561
+ You can set the calculation mode of an Excel instance to manual or automatic.
562
+
563
+ excel.calculation = :manual
564
+
565
+ You can do it in a block:
566
+
567
+ excel = Excel.create
568
+ book = Book.open('workbook.xls')
569
+ excel.with_calculation(:manual) do
570
+ # do something
571
+ end
572
+
573
+ === Getting and setting the contents of a named range in an Excel application
574
+
575
+ excel = Excel.create
576
+ book = Book.open('another_workbook.xls')
577
+
578
+ You can get the value of a range by using
579
+
580
+ excel[name]
581
+
582
+ or
583
+
584
+ excel.nameval(name)
585
+
586
+ and set the value of a range by using
587
+
588
+ excel[name] = value
589
+
590
+ or
591
+
592
+ excel.set_nameval(name,value)
593
+
594
+ === Getting and setting the contents of a named range in an Excel application directly
595
+
596
+ You can get the value of a range
597
+
598
+ excel.rangeval(name)
599
+
600
+ and set the value of a range.
601
+
602
+ excel.set_rangeval(name,value)
603
+
604
+
605
+ === Examples
606
+
607
+ === Example 1
608
+
609
+ We open a workbook.
610
+
611
+ book = Book.open('workbook.xls')
612
+
613
+ Then we access a sheet via its name.
614
+
615
+ sheet = book.sheet('Sheet1')
616
+
617
+ Now we can modify the first cell.
618
+
619
+ sheet[1,1] = "new"
620
+
621
+ Then we save the workbook.
622
+
623
+ book.save
624
+
625
+ We can also save the workbook with a different name, and overwrite if a file with this name already exists.
626
+
627
+ book.save_as('different_workbook.xls', :if_exists => :overwrite)
628
+
629
+ Finally we close the workbook.
630
+
631
+ book.close
632
+
633
+ === Example 2
634
+
635
+ We open a workbook.
636
+
637
+ book = Book.open('workbook.xls')
638
+
639
+ open it also in a new Excel instance and make it visible.
640
+
641
+ new_book = Book.open('workbook.xls', :force => {:excel => :new}, :visible => true)
642
+
643
+ and open another workbook in a the first Excel instance.
644
+
645
+ another_book = Book.open('another_workbook.xls', :force => {:excel => book.excel})
646
+
647
+ Then we close the workbooks.
648
+
649
+ book.close
650
+ new_book.close
651
+ another_book.close
652
+
653
+ We reopen the first workbook.
654
+
655
+ reopened_book = book.reopen
656
+
657
+ The writable workbook is being prefered.
658
+
659
+ reopened_book === book
660
+ => true
661
+
662
+ We want to open yet another workbook. Since the workbook was not open before, reopening the workbook fails and the :default-excel option applies. According to :default => {:excel => :new} a new Excel is created, and the workbook is opened there.
663
+
664
+ different_book = Book.open('different.xls', :default => {:excel => :new})
665
+
666
+
667
+ === Example 3
668
+
669
+ We open a workbook.
670
+
671
+ book = Book.open('workbook.xls')
672
+
673
+ We want to add a copy of the first sheet and insert it after the second sheet.
674
+
675
+ book.add_sheet(book.sheet(1), :as => 'Sheet1_copy', :after => book.sheet(2))
676
+
677
+ Then we open a new workbook with the same name in a new Excel, and leave the workbook that contains unsaved changes in the old Excel.
678
+
679
+ new_book = Book.open('workbook.xls', :if_unsaved => :new_excel)
680
+
681
+ We acccess the first sheet and change the first cell.
682
+
683
+ sheet = new_book.sheet(1)
684
+ sheet[1,1] = "another"
685
+
686
+ Then we open a workbook with the same name in the running Excel while discarding the workbook that contained unsaved changes.
687
+
688
+ third_book = Book.open('workbook.xls', :if_unsaved => :forget)
689
+
690
+ Now we add a sheet.
691
+
692
+ third_book.add_sheet
693
+
694
+ and close the workbook without saving it.
695
+
696
+ third_book.close(:if_unsaved => :forget)
697
+
698
+ We close the first workbook and save it before.
699
+
700
+ book.close(:if_unsaved => :save)
701
+
702
+ === Example 4
703
+
704
+ We open a workbook.
705
+
706
+ book1 = Book.open('workbook.xls')
707
+
708
+ Then we open a workbook with the same name in a different path, while closing the workbook opened before.
709
+
710
+ book2 = Book.open('more/workbook.xls', :if_obstructed => :forget)
711
+
712
+ We change its first cell.
713
+
714
+ sheet = book2.sheet(1)
715
+ sheet[1,1] = "new"
716
+
717
+ Now we open a workbook with the same name again in a different path. while saving and closing the other workbook.
718
+
719
+ book3 = Book.open('workbook.xls', :if_obstructed => :save)
720
+
721
+ Then we open a workbook with the same name in a different path.
722
+ The other workbook will be closed, because it does not contain unsaved changes.
723
+
724
+ book4 = Book.open('more/workbook.xls', :if_obstructed => :close_if_unsaved)
725
+
726
+
727
+ Finally we close this workbook.
728
+
729
+ book4.close
730
+
731
+
732
+ === Example 5
733
+
734
+ We open a workbook
735
+
736
+ book = Book.open('workbook.xls')
737
+
738
+ and print its first cell.
739
+
740
+ sheet = book.sheet(1)
741
+ p "1st cell: #{sheet[1,1].Value}"
742
+
743
+ Then we unobtrusively modify the workbook.
744
+
745
+ Book.unobtrusively('workbook.xls') do |book|
746
+ sheet = book.sheet(1)
747
+ sheet[1,1] = 'simple'
748
+ end
749
+
750
+ The workbook is modified, but its status is unchanged.
751
+
752
+ === More details
753
+
754
+ link: Readme_detail.rdoc
755
+
756
+ === Development
757
+
758
+ RobustExcelOle started as a simple fork from tomiacannondale's wrap_excel adapted to Ruby 1.8.6.
759
+ The functionality of wrap_excel is optimised and extended by a lot of new features.
760
+ Most notable extensions include:
761
+ * workbooks can be opened in already running Excel instances (instead of opening a new Excel whenever a book is opened)
762
+ * a workbook management system stores all workbooks that have been open. This workbook store is being used, e.g., for reopening a workbook that has been closed before. It provides transparency identity, i.e., equal Excel workbooks correspond to equal Book objects of RobustExcelOle.
763
+
764
+ Some features in RobustExcelOle that are not compatible with wrap_excel:
765
+ * +open+ uses by default a running Excel instance instead of creating a new one,
766
+ and opens a workbook by default in writable mode instead of read_only
767
+ * +close+ closes the workbook instead of closing all workbooks and the Excel instance.
768
+ * +save_as+ instead of +save+.
769
+ * position of cells and number of sheets are based on 1 instead of 0
770
+
771
+
772
+ === Want to do more things
773
+
774
+ If you want to do something that not provide a function, you can use win32ole methods.
775
+
776
+ == Support
777
+
778
+ This is work in progress. Please contact us and to report issues and feature requests to github Issues.
779
+ https://github.com/Thomas008/robust_excel_ole/issues
780
+
781
+ == Collaborate
782
+
783
+ Please pull request on github.
784
+
785
+ == Author
786
+
787
+ thomas mailto:Thomas.Raths@gmx.net
788
+
789
+ == License
790
+
791
+ MIT License. For more imformation, please see LICENSE.