robust_excel_ole 1.20 → 1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cbad43d74758e37eb8e8d17e0297ead9f7cda838f5a157832145d41bacb743a
4
- data.tar.gz: 80a112947a96132e8f8bb5ccccdccace4b7c1227418475aac51d6aa771b2e876
3
+ metadata.gz: d73c62c763182694dfebd8d6c08aff0c4202752cb27dd7d8b7b46f6c1960ca4d
4
+ data.tar.gz: f3381ababd070bf4f9c19a7a244d7a763d4bb97893c75b36770e27ee0b051bc5
5
5
  SHA512:
6
- metadata.gz: 4983b1d7e31e09873bf70e9903e3bdcd7a438e238283c5f2bae9198b5ed53c83fd5726f55b7e9ad4559b820dca65f2c82cb82f85091b199f4b58adfa98064c6b
7
- data.tar.gz: 6c1c920de4c68699a10e87241121a01e66884317f06ad8ce9962b049c024658b797e014ef0aaaa297287065e80d85514d384925f24412bf1175aa8d97c252865
6
+ metadata.gz: 86e25e6d15f705b8a44058050d2a6360da2581a72855ed552a8f30958a6da707fcddb18d661416b63fa721e864bc57e6ee4102ca7a4d5569182569353538e38a
7
+ data.tar.gz: 28daa6be28ba71b70ece8a387cac4e06441232e5ada825970338faaf4e0a269da1c32a471ea0d38eaa2c704f438281be7db127a8a7a257d2aa4b79d784f4547a
data/Changelog CHANGED
@@ -1,8 +1,17 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.22] 2020-10-08
4
5
 
5
- ## [1.20] 2020-14-07
6
+ ### Added
7
+ - Range#set_value
8
+
9
+ ## [1.21] 2020-05-08
10
+
11
+ ### Added
12
+ - Range#rows, columns
13
+
14
+ ## [1.20] 2020-23-07
6
15
 
7
16
  ### Changed
8
17
  - using pry in console
@@ -27,7 +27,6 @@ RobustExcelOle supports
27
27
  - availability of all VBA methods
28
28
  - availability of the Excel constants (in form if Ruby constants: Excel constant.capitalize)
29
29
  - all standard Excel file formats (.xlsx, .xls, .xlsm)
30
- - list objects
31
30
  - reopening workbooks after closing them
32
31
  - unobtrusively opening workbooks, i.e. opening and processing workbooks
33
32
  while preserving their status, e.g. saved, readonly
@@ -65,7 +64,7 @@ If you want to start the console under jruby, and if you don't want to use a ver
65
64
 
66
65
  jreo
67
66
 
68
- The call of the console will include RobustExcelOle for you.
67
+ The call of the console will include RobustExcelOle for you. The consoles require the ruby gem 'pry'. If you want to use the nice feature of filename and string completion, you may install pry-bond as well.
69
68
 
70
69
  The following examples can be used for both scripts and console. If you have started the console in the gem path, you can just put these examples.
71
70
 
@@ -318,125 +317,6 @@ and set another value to that range.
318
317
 
319
318
  For more details about reading and writing contents of cells and ranges see {README_ranges}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_ranges.rdoc]
320
319
 
321
- === List Objects
322
-
323
- === Creating list objects
324
-
325
- We can define a list object (or table) from scratch.
326
-
327
- table = ListObject.new(worksheet, "table 1", [1,1], 3,["Person","Amount"])
328
-
329
- This command creates a list object in worksheet named "table 1", with upper left corner at position [1,1] (first cell), with 3 rows and the columns "Person" and "Amount".
330
-
331
- Likewise we can get a RobustExcelOle list object with help of an existing WIN32OlE list object.
332
-
333
- ole_listobject = worksheet.ListObjects.Item("Table 1")
334
- table = ListObject.new(ole_listobject)
335
-
336
- or
337
-
338
- table = ole_listobject.to_reo
339
-
340
- Now we have a RobustExcelOle ListObject that wraps a WIN32OLE ListObject. So we can send any WIN32OLE (VBA) method to it. See
341
- https://docs.microsoft.com/en-us/office/vba/api/excel.listobject#methods.
342
-
343
- A row in this table can be accessed with help of #[], e.g.
344
-
345
- row1 = table[1]
346
-
347
- === Reading and setting values
348
-
349
- Now we can set and get the value of a cell of the table with help of methods that are underscored versions of the column names, e.g.
350
-
351
- row1.person = "John"
352
- row1.person
353
- # => "John"
354
-
355
- We can also read and set values in a whole row, e.g.
356
-
357
- table.row_values(1)
358
- # => ["John", 40]
359
-
360
- or
361
-
362
- table[1].values
363
- # => ["John", 40]
364
-
365
- and
366
-
367
- table.set_row_values(1, ["Herbert", 80])
368
- # => ["Herbert", 80]
369
-
370
- or
371
-
372
- table[1].set_values(["Herbert", 80])
373
-
374
- If the number of given values is less than the number of cells in the row, only the first values are written. The remaining values keep their value.
375
-
376
- Similarly, we can read and set the values in a whole column, e.g.
377
-
378
- table.column_values("Person")
379
- # => ["John", "Peter"]
380
-
381
- and
382
-
383
- table.set_column_values(1, ["Herbert","Paul"])
384
-
385
- The column names we can get with help of
386
-
387
- table.column_names
388
-
389
- A column can be renamed.
390
-
391
- table.rename_column("Person", "Enterprise")
392
-
393
- or
394
-
395
- table.rename_column(1, "Enterprise")
396
-
397
- === Adding and Deleting rows and columns
398
-
399
- We can add rows and columns, supplying optionally their name, the position and contents.
400
-
401
- table.add_column("column_name")
402
- table.add_column("column_name", 3)
403
- table.add_column("column_name", 3, ["John", "Paul"])
404
-
405
- table.add_row(3)
406
- table.add_row(3, ["John", 40, 2, 2004])
407
-
408
- Deleting columns and rows is done by
409
-
410
- table.delete_column("column_name")
411
- table.delete_row(3)
412
-
413
- We can delete only the contents of a column
414
-
415
- table.delete_column_values("column_name")
416
-
417
- Similarly can delete only the contents of a row.
418
-
419
- table.delete_row_values(2)
420
-
421
- or
422
-
423
- table[2].delete_values
424
-
425
- Finally we can delete empty rows and columns.
426
-
427
- table.delete_empty_rows
428
- table.delete_empty_columns
429
-
430
- === Finding values and sorting
431
-
432
- You can find all cells containing a given value, e.g.
433
-
434
- table.find_value(value)
435
- #=> [#<Cell: (5,8)>#, #<Cell: (9,6)>#]
436
-
437
- You can sort a table according to a given column and sort order, e.g.
438
-
439
- table.sort("Person", :ascending)
440
320
 
441
321
  === More things
442
322
 
data/bin/jreo CHANGED
@@ -2,23 +2,23 @@
2
2
  # -*- jruby -*-
3
3
 
4
4
  require 'pry'
5
- require 'robust_excel_ole'
5
+ require '../robust_excel_ole/lib/robust_excel_ole'
6
6
 
7
7
  include REO
8
8
  include General
9
9
 
10
- puts 'REO console started'
11
- puts
12
-
13
10
  # some pry configuration
14
11
  Pry.config.windows_console_warning = false
15
- Pry.config.history.should_save = true
16
12
  Pry.config.color = false
13
+ Pry.config.prompt_name = "REO "
14
+
15
+ #Pry.config.history_save = true
17
16
  #Pry.editor = 'notepad' # 'subl', 'vi'
18
- #Pry.config.prompt =
19
- # [
20
- # ->(_obj, _nest_level, _) { ">> " },
21
- # ->(*) { " " }
22
- # ]
23
17
 
24
- pry
18
+ hooks = Pry::Hooks.new
19
+
20
+ hooks.add_hook :when_started, :hook12 do
21
+ puts 'REO console started'
22
+ puts
23
+ end
24
+ Pry.start(nil, hooks: hooks)
data/bin/reo CHANGED
@@ -2,23 +2,23 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'pry'
5
- require 'robust_excel_ole'
5
+ require '../robust_excel_ole/lib/robust_excel_ole'
6
6
 
7
7
  include REO
8
8
  include General
9
9
 
10
- puts 'REO console started'
11
- puts
12
-
13
10
  # some pry configuration
14
11
  Pry.config.windows_console_warning = false
15
- Pry.config.history.should_save = true
16
12
  Pry.config.color = false
13
+ Pry.config.prompt_name = "REO "
14
+
15
+ #Pry.config.history_save = true
17
16
  #Pry.editor = 'notepad' # 'subl', 'vi'
18
- #Pry.config.prompt =
19
- # [
20
- # ->(_obj, _nest_level, _) { ">> " },
21
- # ->(*) { " " }
22
- # ]
23
17
 
24
- pry
18
+ hooks = Pry::Hooks.new
19
+
20
+ hooks.add_hook :when_started, :hook12 do
21
+ puts 'REO console started'
22
+ puts
23
+ end
24
+ Pry.start(nil, hooks: hooks)
@@ -42,14 +42,18 @@ or
42
42
 
43
43
  range = worksheet.range(["A1:D3"])
44
44
 
45
- You can read the values by
45
+ You can also access a range from a workbook by providing the worksheet
46
+
47
+ range = workbook(workbook.sheet(1), [1..3,1..4])
48
+
49
+ Now you can read the values by
46
50
 
47
51
  range.Value
48
52
  => [["foo", "workbook", "sheet1", nil], ["foo", nil, "foobaaa", nil], ["matz", "is", "nice", nil]]
49
53
 
50
54
  or
51
55
 
52
- range.v
56
+ range.value or range.v
53
57
  => [["foo", "workbook", "sheet1", nil], ["foo", nil, "foobaaa", nil], ["matz", "is", "nice", nil]]
54
58
 
55
59
  or as flat array
@@ -63,8 +67,20 @@ You can set values with help of range#Value or range#v, e.g.
63
67
 
64
68
  or
65
69
 
70
+ range.value = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
71
+
72
+ or
73
+
66
74
  range.v = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
67
75
 
76
+ or
77
+
78
+ range.set_value([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
79
+
80
+ You can color the range when setting the contents of a range.
81
+
82
+ range.set_value([[1,2,3,4],[5,6,7,8],[9,10,11,12]], :color => 42)
83
+
68
84
  Now we copy the range. With help of VBA methods you would do
69
85
 
70
86
  range.Copy(:destination => sheet.range([4,5]).ole_range)
@@ -194,6 +210,10 @@ or
194
210
 
195
211
  range = worksheet.range([[1]..3,2..[4]])
196
212
 
213
+ You can access a range also from a workbook by providing the respective worksheet
214
+
215
+ range = workbook(worksheet, [[1..3],2..[4]])
216
+
197
217
  You get the values of the range as flat array with help of
198
218
 
199
219
  range.values
@@ -202,6 +222,10 @@ You can access a range via its defined name with
202
222
 
203
223
  range = worksheet.range("name")
204
224
 
225
+ or
226
+
227
+ range = workbook(worksheet, "name")
228
+
205
229
  === Copying a range
206
230
 
207
231
  Let's assume, you have a source range
@@ -310,10 +334,6 @@ You can color the range when setting the contents of a range.
310
334
 
311
335
  workbook.set_namevalue_glob("name", "new_value", :color => 4)
312
336
 
313
- The method []= sets the contents of a range and colors the range via some default color.
314
-
315
- workbook["name"] = "new_value"
316
-
317
337
  Similarly, the contents of a named range can be read and modified in a worksheet
318
338
 
319
339
  worksheet = workbook.sheet(1)
@@ -97,7 +97,7 @@ The method Worksheet#values yields all cell values of the used range of the work
97
97
  worksheet.values
98
98
  => [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"], ["matz", "is", "nice"]]
99
99
 
100
- The method Worksheet#each_rowvalue provides enable to access the values of each row.
100
+ The method Worksheet#each_rowvalue enables to access the values of each row.
101
101
 
102
102
  worksheet.each_rowvalue do |row_values|
103
103
  # do something with the row_values
data/jreo.bat CHANGED
@@ -1,3 +1,3 @@
1
1
  @echo off
2
2
 
3
- jirb -f -r ./lib/robust_excel_ole -r ./lib/jreo_console.rb
3
+ jruby lib/reo_console.rb
@@ -4,18 +4,18 @@ require '../robust_excel_ole/lib/robust_excel_ole'
4
4
  include REO
5
5
  include General
6
6
 
7
- puts 'REO console started'
8
- puts
9
-
10
7
  # some pry configuration
11
8
  Pry.config.windows_console_warning = false
12
- Pry.config.history.should_save = true
13
9
  Pry.config.color = false
10
+ Pry.config.prompt_name = "REO "
11
+
12
+ #Pry.config.history_save = true
14
13
  #Pry.editor = 'notepad' # 'subl', 'vi'
15
- #Pry.config.prompt =
16
- # [
17
- # ->(_obj, _nest_level, _) { ">> " },
18
- # ->(*) { " " }
19
- # ]
20
14
 
21
- pry
15
+ hooks = Pry::Hooks.new
16
+
17
+ hooks.add_hook :when_started, :hook12 do
18
+ puts 'REO console started'
19
+ puts
20
+ end
21
+ Pry.start(nil, hooks: hooks)
@@ -18,5 +18,5 @@ require File.join(File.dirname(__FILE__), 'robust_excel_ole/list_object')
18
18
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/cygwin') if RUBY_PLATFORM =~ /cygwin/
19
19
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/version')
20
20
 
21
- include RobustExcelOle
21
+ #include RobustExcelOle
22
22
  include General
@@ -0,0 +1,63 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ LOG_TO_STDOUT: Boolean = false
4
+ REO_LOG_DIR: String
5
+ REO_LOG_FILE: String
6
+
7
+ class String
8
+
9
+ def end_with? : (suffixes: Array[String]) -> String
10
+
11
+ end
12
+
13
+ module RobustExcelOle
14
+
15
+ class VBAMethodMissingError < RuntimeError
16
+ end
17
+
18
+ class REOError < RuntimeError
19
+ end
20
+
21
+ class ExcelREOError < REOError
22
+ end
23
+
24
+ class WorkbookREOError < REOError
25
+ end
26
+
27
+ class WorksheetREOError < REOError
28
+ end
29
+
30
+ class FileREOError < REOError
31
+ end
32
+
33
+ class NamesREOError < REOError
34
+ end
35
+
36
+ class MiscREOError < REOError
37
+ end
38
+
39
+ class TypeREOError < REOError
40
+ end
41
+
42
+ # @private
43
+ class UnexpectedREOError < REOError
44
+ end
45
+
46
+ # @private
47
+ class NotImplementedREOError < REOError
48
+ end
49
+
50
+
51
+ class Base
52
+
53
+ def own_methods -> Array[Symbol]
54
+
55
+ def self.tr1: (_text1: String) -> void
56
+
57
+ def self.trace: (text: String) -> void
58
+
59
+ def self.puts_hash: (hash: Hash) -> void
60
+
61
+ end
62
+
63
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module RobustExcelOle
4
4
 
5
+ # @private
5
6
  class Bookstore < Base
6
7
 
7
8
  def initialize
@@ -31,7 +32,7 @@ module RobustExcelOle
31
32
  def fetch(filename, options = { :prefer_writable => true })
32
33
  return nil unless filename
33
34
  filename = General.absolute_path(filename)
34
- filename_key = General.canonize(filename)
35
+ filename_key = General.canonize(filename).downcase
35
36
  weakref_books = @filename2books[filename_key]
36
37
  return nil if weakref_books.nil? || weakref_books.empty?
37
38
 
@@ -69,9 +70,9 @@ module RobustExcelOle
69
70
  # stores a workbook
70
71
  # @param [Workbook] book a given book
71
72
  def store(book)
72
- filename_key = General.canonize(book.filename)
73
+ filename_key = General.canonize(book.filename).downcase
73
74
  if book.stored_filename
74
- old_filename_key = General.canonize(book.stored_filename)
75
+ old_filename_key = General.canonize(book.stored_filename).downcase
75
76
  # deletes the weak reference to the book
76
77
  @filename2books[old_filename_key].delete(book)
77
78
  end