robust_excel_ole 1.38 → 1.41
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +8 -0
- data/lib/robust_excel_ole/base.rb +1 -1
- data/lib/robust_excel_ole/cygwin.rb +1 -1
- data/lib/robust_excel_ole/excel.rb +86 -56
- data/lib/robust_excel_ole/version.rb +1 -1
- data/spec/cygwin_spec.rb +5 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/data/workbook.xlsx +0 -0
- data/spec/excel_spec.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c389760bffba5b9c56ece3cd94874141095f4ea9d4d372bce263025f827087c6
|
4
|
+
data.tar.gz: 3f25cc955cf6d63a9d9ba07cb0dc8f20ce9c0fee2175e35ca4d654665c683b39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8fe1021c9e2579bb77241b629e1cf8144a5c578607a0f879dc7336b27691d8efd5638d7de89f7427519d038cdaf4e04330e03f2842072551d23e41be0f69c38
|
7
|
+
data.tar.gz: 0d879c95b01f6803f1fd8c204ff095b601a0f40b0541b88561a4d0e5b4db0f25111f0bf242195005c060988b71248e03427fe30a0bf44192c7e8ceda7fb6a532
|
data/Changelog
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
LOG_TO_STDOUT =
|
3
|
+
LOG_TO_STDOUT = true unless Object.const_defined?(:LOG_TO_STDOUT)
|
4
4
|
REO_LOG_DIR = ''.freeze unless Object.const_defined?(:REO_LOG_DIR)
|
5
5
|
REO_LOG_FILE = 'reo.log'.freeze unless Object.const_defined?(:REO_LOG_FILE)
|
6
6
|
|
@@ -47,7 +47,7 @@ module RobustExcelOle
|
|
47
47
|
|
48
48
|
# @private
|
49
49
|
def cygpath(options, path)
|
50
|
-
Open3.popen3("cygpath #{options} #{path}") { |stdin, stdout, stderr| stdout.read }[0..-2]
|
50
|
+
Open3.popen3("cygpath #{options} #{path}") { |stdin, stdout, stderr| stdout.read }[0..-2].gsub("\n", " ")
|
51
51
|
end
|
52
52
|
|
53
53
|
module_function :cygpath
|
@@ -10,52 +10,60 @@ end
|
|
10
10
|
module User32
|
11
11
|
# Extend this module to an importer
|
12
12
|
extend Fiddle::Importer
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
begin
|
14
|
+
# Load 'user32' dynamic library into this importer
|
15
|
+
dlload 'user32'
|
16
|
+
# Set C aliases to this importer for further understanding of function signatures
|
17
|
+
typealias 'HWND', 'HANDLE'
|
18
|
+
typealias 'HANDLE', 'void*'
|
19
|
+
typealias 'LPCSTR', 'const char*'
|
20
|
+
typealias 'LPCWSTR', 'const wchar_t*'
|
21
|
+
typealias 'UINT', 'unsigned int'
|
22
|
+
typealias 'ppvObject', 'void**'
|
23
|
+
typealias 'DWORD', 'unsigned long'
|
24
|
+
typealias 'LPDWORD', 'DWORD*'
|
25
|
+
typealias 'PDWORD_PTR', 'DWORD**'
|
26
|
+
typealias 'WPARAM', 'UINT*'
|
27
|
+
typealias 'LPARAM', 'INT*'
|
28
|
+
typealias 'LRESULT', 'DWORD'
|
29
|
+
# Import C functions from loaded libraries and set them as module functions
|
30
|
+
extern 'DWORD GetWindowThreadProcessId(HWND, LPDWORD)'
|
31
|
+
extern 'HWND FindWindowExA(HWND, HWND, LPCSTR, LPCSTR)'
|
32
|
+
extern 'DWORD SetForegroundWindow(HWND)'
|
33
|
+
extern 'LRESULT SendMessageTimeoutA(HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR)'
|
34
|
+
rescue Fiddle::DLError => e
|
35
|
+
trace "warning: user32.dll not found: #{e}"
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
module Oleacc
|
36
40
|
# Extend this module to an importer
|
37
41
|
extend Fiddle::Importer
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
42
|
+
begin
|
43
|
+
# Load 'oleacc' dynamic library into this importer
|
44
|
+
dlload 'oleacc'
|
45
|
+
# Set C aliases to this importer for further understanding of function signatures
|
46
|
+
typealias 'HWND', 'HANDLE'
|
47
|
+
typealias 'HANDLE', 'void*'
|
48
|
+
typealias 'ppvObject', 'void**'
|
49
|
+
typealias 'DWORD', 'unsigned long'
|
50
|
+
typealias 'HRESULT', 'long'
|
51
|
+
Guid = struct [
|
52
|
+
'unsigned long data1',
|
53
|
+
'unsigned short data2',
|
54
|
+
'unsigned short data3',
|
55
|
+
'unsigned char data4[8]'
|
56
|
+
]
|
57
|
+
# Import C functions from loaded libraries and set them as module functions
|
58
|
+
extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct guid*, ppvObject)'
|
59
|
+
#typealias 'REFIID', 'struct guid*'
|
60
|
+
#extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, REFIID, ppvObject)'
|
61
|
+
#extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct GUID*, ppvObject)'
|
62
|
+
#extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, void*, ppvObject)'
|
63
|
+
#extern 'HRESULT AccessibleObjectFromWindow(HWND, DWORD, struct GUID*, ppvObject)'
|
64
|
+
rescue Fiddle::DLError => e
|
65
|
+
trace "warning: oleacc.dll not found: #{e}"
|
66
|
+
end
|
59
67
|
end
|
60
68
|
|
61
69
|
module RobustExcelOle
|
@@ -348,10 +356,14 @@ module RobustExcelOle
|
|
348
356
|
sleep 0.1
|
349
357
|
if finishing_living_excel
|
350
358
|
if hwnd
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
359
|
+
begin
|
360
|
+
pid_puffer = ' ' * 32
|
361
|
+
User32::GetWindowThreadProcessId(hwnd, pid_puffer)
|
362
|
+
pid = pid_puffer.unpack('L')[0]
|
363
|
+
Process.kill('KILL', pid) rescue nil
|
364
|
+
rescue NoMethodError => e
|
365
|
+
# trace "#{e}"
|
366
|
+
end
|
355
367
|
end
|
356
368
|
@@hwnd2excel.delete(hwnd)
|
357
369
|
weak_xl.ole_free if weak_xl.weakref_alive?
|
@@ -414,6 +426,7 @@ module RobustExcelOle
|
|
414
426
|
# returns running Excel instances
|
415
427
|
# !!! This is work in progress
|
416
428
|
# the approach is currently restricted to visible Excel instances with at least one workbook
|
429
|
+
=begin
|
417
430
|
def self.running_excel_instances
|
418
431
|
win32ole_excel_instances = []
|
419
432
|
hwnd = 0
|
@@ -478,6 +491,8 @@ module RobustExcelOle
|
|
478
491
|
alias known_excel_instances known_running_instances # :deprecated: #
|
479
492
|
end
|
480
493
|
|
494
|
+
=end
|
495
|
+
|
481
496
|
private
|
482
497
|
|
483
498
|
# returns a Win32OLE object that represents a Excel instance to which Excel connects
|
@@ -554,15 +569,26 @@ module RobustExcelOle
|
|
554
569
|
|
555
570
|
# returns true, if the Excel instances responds to VBA methods, false otherwise
|
556
571
|
def alive?
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
572
|
+
begin
|
573
|
+
msg = 0x2008
|
574
|
+
wparam = 0
|
575
|
+
lparam = 0
|
576
|
+
flags = 0x0000 # 0x0002
|
577
|
+
duration = 5000
|
578
|
+
lpdw_result_puffer = ' ' * 32
|
579
|
+
status = User32::SendMessageTimeoutA(hwnd, msg, wparam, lparam, flags, duration, lpdw_result_puffer)
|
580
|
+
result = lpdw_result_puffer.unpack('L')[0]
|
581
|
+
status != 0
|
582
|
+
rescue NoMethodError => e
|
583
|
+
#trace "#{e}"
|
584
|
+
begin
|
585
|
+
@ole_excel.Name
|
586
|
+
true
|
587
|
+
rescue
|
588
|
+
# trace $!.message
|
589
|
+
false
|
590
|
+
end
|
591
|
+
end
|
566
592
|
end
|
567
593
|
|
568
594
|
# returns unsaved workbooks in known (not opened by user) Excel instances
|
@@ -726,8 +752,12 @@ module RobustExcelOle
|
|
726
752
|
|
727
753
|
def focus
|
728
754
|
self.visible = true
|
729
|
-
|
730
|
-
|
755
|
+
begin
|
756
|
+
status = User32::SetForegroundWindow(@ole_excel.Hwnd)
|
757
|
+
raise ExcelREOError, "could not set Excel window as foreground" if status == 0
|
758
|
+
rescue NoMethodError => e
|
759
|
+
raise ExcelREOError, "could not set Excel window as foreground because user32.dll not found"
|
760
|
+
end
|
731
761
|
end
|
732
762
|
|
733
763
|
# @private
|
data/spec/cygwin_spec.rb
CHANGED
@@ -10,6 +10,11 @@ include General
|
|
10
10
|
describe "on cygwin", :if => RUBY_PLATFORM =~ /cygwin/ do
|
11
11
|
describe ".cygpath" do
|
12
12
|
context "cygwin path is '/cygdrive/c/Users'" do
|
13
|
+
|
14
|
+
context "with white spaces" do
|
15
|
+
it { RobustExcelOle::Cygwin.cygpath('-w', '/cygdrive/c/Users of all').should eq 'C:\\Users of all' }
|
16
|
+
end
|
17
|
+
|
13
18
|
context "with '-w' options" do
|
14
19
|
it { RobustExcelOle::Cygwin.cygpath('-w', '/cygdrive/c/Users').should eq 'C:\\Users' }
|
15
20
|
end
|
data/spec/data/workbook.xls
CHANGED
Binary file
|
data/spec/data/workbook.xlsx
CHANGED
Binary file
|
data/spec/excel_spec.rb
CHANGED
@@ -1922,6 +1922,7 @@ module RobustExcelOle
|
|
1922
1922
|
|
1923
1923
|
end
|
1924
1924
|
|
1925
|
+
=begin
|
1925
1926
|
describe "known_running_instances" do
|
1926
1927
|
|
1927
1928
|
it "should return empty list" do
|
@@ -1952,7 +1953,7 @@ module RobustExcelOle
|
|
1952
1953
|
end
|
1953
1954
|
|
1954
1955
|
end
|
1955
|
-
|
1956
|
+
=end
|
1956
1957
|
context "with hwnd and hwnd2excel" do
|
1957
1958
|
|
1958
1959
|
before do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robust_excel_ole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.41'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- traths
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|