wrap_excel 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ vendor/bundle
6
+ *~
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in wrap_excel.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 tomi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.ja.rdoc ADDED
@@ -0,0 +1,108 @@
1
+ = WrapExcel
2
+
3
+ == 概要
4
+
5
+ WrapExcelはwin32oleをラップし、rubyによるExcelオペレーションを簡単にします。
6
+
7
+ == 必要なもの
8
+
9
+ * ruby 1.9.2以上 (プラットフォームはwindowsです)
10
+
11
+ == インストール
12
+
13
+ gem install wrap_excel
14
+
15
+ == 使い方
16
+ === bookへのアクセス
17
+
18
+ ブロックを使用する場合
19
+
20
+ WrapExcel::Book.open('./sample.xls') do |book|
21
+ # do something
22
+ end
23
+
24
+ ブロックを使用しない場合
25
+
26
+ book = WrapExcel::Book.open('./sample.xls')
27
+ book.close
28
+
29
+ オプションは以下の通りです。
30
+
31
+ * read_only:: boolean default true
32
+ * displayalerts:: boolean default false
33
+ * visible:: boolean false
34
+
35
+ === sheetへのアクセス
36
+
37
+ sheetオブジェクトへは #[] メソッドでアクセス出来ます。
38
+
39
+ sheet = book[0]
40
+
41
+ シート名でのアクセス
42
+
43
+ book['Sheet1']
44
+
45
+ === 行または列へのアクセス
46
+
47
+ sheetオブジェクトはenumerableをインクルードしています。#each_column or #each_row or #each メソッドが使用できます。
48
+
49
+ sheet.each do |cell|
50
+ # do something with cell
51
+ # read every row every column
52
+ end
53
+
54
+ sheet.each_row do |row|
55
+ # do something with row_range
56
+ end
57
+
58
+ sheet.each_column do |column_range|
59
+ # do something with column_range
60
+ end
61
+
62
+ === セルへのアクセス
63
+
64
+ sheetオブジェクトからのアクセス。
65
+
66
+ sheet[0, 0] => first cell.
67
+
68
+ rangeオブジェクトからのアクセス。
69
+
70
+ row_range[0] => first cell in row_range
71
+ column_range[1] => second cell in column_range
72
+
73
+ === ファイルの保存
74
+
75
+ 既存のファイルは保存可能です。
76
+
77
+ WrapExcel::Book.open('./sample.xls') do |book|
78
+ # do something
79
+ book.save
80
+ end
81
+
82
+ もしくは
83
+
84
+ book = WrapExcel::Book.open('./sample.xls')
85
+ book.save
86
+ book.close
87
+
88
+ 新規ファイルの保存は出来ません。
89
+
90
+ === Want to do more things
91
+
92
+ 全てのWrapExcelオブジェクトはwin32oleインスタンスを含んでいます。もし、あなたが、WrapExcelライブラリが提供していない機能を使用したい場合、win32oleのメソッドが使用出来ます。
93
+
94
+ == サポート
95
+
96
+ 問題を報告したり、機能追加の要望する場合はgithubのIssuesに登録してください。 [https://github.com/tomiacannondale/wrap_excel/issues]
97
+
98
+ == 共同作業
99
+
100
+ githubのpull requestをしてください。
101
+
102
+ == 開発者
103
+
104
+ tomi [tomiacannondale@gmail.com]
105
+
106
+ == ライセンス
107
+
108
+ MITライセンスです。詳細はLICENSEを参照してください。
data/README.rdoc ADDED
@@ -0,0 +1,108 @@
1
+ = WrapExcel
2
+
3
+ == Description
4
+
5
+ WrapExcel is a to wrap the win32ole, and easy to use Excel operations with ruby.
6
+
7
+ == Requirements
8
+
9
+ * ruby 1.9.2 or higher (platform is windows)
10
+
11
+ == Install
12
+
13
+ gem install wrap_excel
14
+
15
+ == Usage
16
+ === access book
17
+
18
+ Read with block.
19
+
20
+ WrapExcel::Book.open('./sample.xls') do |book|
21
+ # do something
22
+ end
23
+
24
+ Read without block.
25
+
26
+ book = WrapExcel::Book.open('./sample.xls')
27
+ book.close
28
+
29
+ Options are the following.
30
+
31
+ * read_only:: boolean default true
32
+ * displayalerts:: boolean default false
33
+ * visible:: boolean false
34
+
35
+ === access sheet
36
+
37
+ Sheet object can access with #[] method.
38
+
39
+ sheet = book[0]
40
+
41
+ Access with sheet name.
42
+
43
+ book['Sheet1']
44
+
45
+ === access row or column
46
+
47
+ Sheet object is included enumerable. Use #each_column or #each_row or #each method.
48
+
49
+ sheet.each do |cell|
50
+ # do something with cell
51
+ # read every row every column
52
+ end
53
+
54
+ sheet.each_row do |row|
55
+ # do something with row_range
56
+ end
57
+
58
+ sheet.each_column do |column_range|
59
+ # do something with column_range
60
+ end
61
+
62
+ === access cell
63
+
64
+ Read from sheet object.
65
+
66
+ sheet[0, 0] => first cell.
67
+
68
+ Read from range object
69
+
70
+ row_range[0] => first cell in row_range
71
+ column_range[1] => second cell in column_range
72
+
73
+ === write excel
74
+
75
+ Can save an existing file.
76
+
77
+ WrapExcel::Book.open('./sample.xls') do |book|
78
+ # do something
79
+ book.save
80
+ end
81
+
82
+ or
83
+
84
+ book = WrapExcel::Book.open('./sample.xls')
85
+ book.save
86
+ book.close
87
+
88
+ Can not save new file.
89
+
90
+ === Want to do more things
91
+
92
+ All WrapExcel object include win32ole instance. If you want to do something that not provide a function, you can use win32ole methods.
93
+
94
+ == Support
95
+
96
+ Report issues and feature requests to github Issues. [https://github.com/tomiacannondale/wrap_excel/issues]
97
+
98
+ == Collaborate
99
+
100
+ Please pull request on github.
101
+
102
+ == Author
103
+
104
+ tomi [tomiacannondale@gmail.com]
105
+
106
+ == License
107
+
108
+ MIT License. For more imformation, please see LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require "rake"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |s|
7
+ s.rspec_opts = '-f d'
8
+ end
9
+ task :default => :spec
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ module WrapExcel
3
+
4
+ class Book
5
+ attr_reader :book
6
+
7
+ def initialize(file, options={ }, &block)
8
+ options = {
9
+ :read_only => true,
10
+ :displayalerts => false,
11
+ :visible => false
12
+ }.merge(options)
13
+ file = WrapExcel::Cygwin.cygpath('-w', file) if RUBY_PLATFORM =~ /cygwin/
14
+ file = WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file)
15
+ @winapp = WIN32OLE.new('Excel.Application')
16
+ @winapp.DisplayAlerts = options[:displayalerts]
17
+ @winapp.Visible = options[:visible]
18
+ @book = @winapp.Workbooks.Open(file,{ 'ReadOnly' => options[:read_only] })
19
+
20
+ if block
21
+ begin
22
+ yield self
23
+ ensure
24
+ close
25
+ end
26
+ end
27
+
28
+ @book
29
+ end
30
+
31
+ def close
32
+ @winapp.Workbooks.Close
33
+ @winapp.Quit
34
+ end
35
+
36
+ def save
37
+ @book.save
38
+ end
39
+
40
+ def [] sheet
41
+ sheet += 1 if sheet.is_a? Numeric
42
+ WrapExcel::Sheet.new(@book.Worksheets.Item(sheet))
43
+ end
44
+
45
+ def each
46
+ @book.Worksheets.each do |sheet|
47
+ yield WrapExcel::Sheet.new(sheet)
48
+ end
49
+ end
50
+
51
+ def self.open(file, options={ }, &block)
52
+ new(file, options, &block)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module WrapExcel
4
+ class Cell
5
+ attr_reader :cell
6
+
7
+ def initialize(win32_cell)
8
+ if win32_cell.MergeCells
9
+ @cell = win32_cell.MergeArea.Item(1,1)
10
+ else
11
+ @cell = win32_cell
12
+ end
13
+ end
14
+
15
+ def method_missing(id, *args)
16
+ @cell.send(id, *args)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ module WrapExcel
3
+ class Range
4
+ def initialize(win32_range)
5
+ @range = win32_range
6
+ end
7
+
8
+ def each
9
+ @range.each do |row_or_column|
10
+ yield WrapExcel::Cell.new(row_or_column)
11
+ end
12
+ end
13
+
14
+ def values(range = nil)
15
+ if range
16
+ min = range.min + 1
17
+ max = range.max + 1
18
+ result = @range.Range(@range.Cells.Item(min), @range.Cells(max)).value
19
+ result.is_a?(Array) ? result[0] : [result]
20
+ else
21
+ @range.Cells.value.flatten
22
+ end
23
+ end
24
+
25
+ def [] index
26
+ @cells ||= []
27
+ @cells[index + 1] ||= WrapExcel::Cell.new(@range.Cells.Item(index + 1))
28
+ end
29
+
30
+ def method_missing(id, *args)
31
+ @range.send(id, *args)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+ module WrapExcel
3
+ class Sheet
4
+ attr_reader :sheet
5
+ include Enumerable
6
+
7
+ def initialize(win32_worksheet)
8
+ @sheet = win32_worksheet
9
+ end
10
+
11
+ def name
12
+ @sheet.Name
13
+ end
14
+
15
+ def name= (new_name)
16
+ @sheet.Name = new_name
17
+ end
18
+
19
+ def [] y, x
20
+ yx = "#{y+1}_#{x+1}"
21
+ @cells ||= { }
22
+ @cells[yx] ||= WrapExcel::Cell.new(@sheet.Cells.Item(y+1, x+1))
23
+ end
24
+
25
+ def []= (y, x, value)
26
+ @sheet.Cells.Item(y+1, x+1).Value = value
27
+ end
28
+
29
+ def each
30
+ @sheet.UsedRange.Rows.each do |row_range|
31
+ row_range.Cells.each do |cell|
32
+ yield WrapExcel::Cell.new(cell)
33
+ end
34
+ end
35
+ end
36
+
37
+ def each_row(offset = 0)
38
+ offset += 1
39
+ @sheet.UsedRange.Rows.each do |row_range|
40
+ next if row_range.row < offset
41
+ yield WrapExcel::Range.new(row_range)
42
+ end
43
+ end
44
+
45
+ def each_row_with_index(offset = 0)
46
+ each_row(offset) do |row_range|
47
+ yield WrapExcel::Range.new(row_range), (row_range.row - 1 - offset)
48
+ end
49
+ end
50
+
51
+ def each_column(offset = 0)
52
+ offset += 1
53
+ @sheet.UsedRange.Columns.each do |column_range|
54
+ next if column_range.column < offset
55
+ yield WrapExcel::Range.new(column_range)
56
+ end
57
+ end
58
+
59
+ def each_column_with_index(offset = 0)
60
+ each_column(offset) do |column_range|
61
+ yield WrapExcel::Range.new(column_range), (column_range.column - 1 - offset)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module WrapExcel
2
+ VERSION = "0.0.5"
3
+ end
data/lib/wrap_excel.rb ADDED
@@ -0,0 +1,49 @@
1
+ require "win32ole"
2
+ require File.join(File.dirname(__FILE__), 'wrap_excel/book')
3
+ require File.join(File.dirname(__FILE__), 'wrap_excel/sheet')
4
+ require File.join(File.dirname(__FILE__), 'wrap_excel/cell')
5
+ require File.join(File.dirname(__FILE__), 'wrap_excel/range')
6
+ require "wrap_excel/version"
7
+
8
+ module WrapExcel
9
+
10
+ module Cygwin
11
+ require 'Win32API'
12
+
13
+ @conv_to_full_posix_path =
14
+ Win32API.new('cygwin1.dll', 'cygwin_conv_to_full_posix_path', 'PP', 'I')
15
+ @conv_to_posix_path =
16
+ Win32API.new('cygwin1.dll', 'cygwin_conv_to_posix_path', 'PP', 'I')
17
+ @conv_to_full_win32_path =
18
+ Win32API.new('cygwin1.dll', 'cygwin_conv_to_full_win32_path', 'PP', 'I')
19
+ @conv_to_win32_path =
20
+ Win32API.new('cygwin1.dll', 'cygwin_conv_to_win32_path', 'PP', 'I')
21
+
22
+ def cygpath(options, path)
23
+ absolute = shortname = false
24
+ func = nil
25
+ options.delete(" \t-").chars {|opt|
26
+ case opt
27
+ when ?u
28
+ func = [@conv_to_full_posix_path, @conv_to_posix_path]
29
+ when ?w
30
+ func = [@conv_to_full_win32_path, @conv_to_win32_path]
31
+ when ?a
32
+ absolute = true
33
+ when ?s
34
+ shortname = true
35
+ end
36
+ }
37
+ raise "first argument must contain -u or -w" if func.nil?
38
+ func = absolute ? func[0] : func[1]
39
+ buf = "\0" * 300
40
+ if func.Call(path, buf) == -1
41
+ raise "cannot convert path name"
42
+ end
43
+ buf.delete!("\0")
44
+ buf
45
+ end
46
+ module_function :cygpath
47
+ end
48
+
49
+ end
data/spec/book_spec.rb ADDED
@@ -0,0 +1,79 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), './spec_helper')
4
+
5
+ describe WrapExcel::Book do
6
+ before do
7
+ @dir = create_tmpdir
8
+ @simple_file = @dir + '/simple.xls'
9
+ end
10
+
11
+ after do
12
+ rm_tmp(@dir)
13
+ end
14
+
15
+ describe ".open" do
16
+ context "exist file" do
17
+ it "simple file with default" do
18
+ expect {
19
+ book = WrapExcel::Book.open(@simple_file)
20
+ book.close
21
+ }.to_not raise_error
22
+ end
23
+
24
+ it "simple file with writable" do
25
+ expect {
26
+ book = WrapExcel::Book.open(@simple_file, :read_only => false)
27
+ book.close
28
+ }.to_not raise_error
29
+ end
30
+
31
+ it "simple file with visible = true" do
32
+ expect {
33
+ book = WrapExcel::Book.open(@simple_file, :visible => true)
34
+ book.close
35
+ }.to_not raise_error
36
+ end
37
+
38
+ context "with block" do
39
+ it 'block parameter should be instance of WrapExcel::Book' do
40
+ WrapExcel::Book.open(@simple_file) do |book|
41
+ book.should be_is_a WrapExcel::Book
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ describe 'access sheet' do
49
+ before do
50
+ @book = WrapExcel::Book.open(@simple_file)
51
+ end
52
+
53
+ after do
54
+ @book.close
55
+ end
56
+
57
+ it 'with sheet name' do
58
+ @book['Sheet1'].should be_kind_of WrapExcel::Sheet
59
+ end
60
+
61
+ it 'with integer' do
62
+ @book[0].should be_kind_of WrapExcel::Sheet
63
+ end
64
+
65
+ it 'with block' do
66
+ @book.each do |sheet|
67
+ sheet.should be_kind_of WrapExcel::Sheet
68
+ end
69
+ end
70
+
71
+ context 'open with block' do
72
+ it {
73
+ WrapExcel::Book.open(@simple_file) do |book|
74
+ book['Sheet1'].should be_is_a WrapExcel::Sheet
75
+ end
76
+ }
77
+ end
78
+ end
79
+ end
data/spec/cell_spec.rb ADDED
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), './spec_helper')
3
+
4
+ describe WrapExcel::Cell do
5
+ before do
6
+ @dir = create_tmpdir
7
+ end
8
+
9
+ after do
10
+ rm_tmp(@dir)
11
+ end
12
+
13
+ context "open simple.xls" do
14
+ before do
15
+ @book = WrapExcel::Book.open(@dir + '/simple.xls')
16
+ @sheet = @book[1]
17
+ @cell = @sheet[0, 0]
18
+ end
19
+
20
+ after do
21
+ @book.close
22
+ end
23
+
24
+ describe "#value" do
25
+ it "get cell's value" do
26
+ @cell.value.should eq 'simple'
27
+ end
28
+ end
29
+
30
+ describe "#value=" do
31
+ it "change cell data to 'fooooo'" do
32
+ @cell.value = 'fooooo'
33
+ @cell.value.should eq 'fooooo'
34
+ end
35
+ end
36
+ end
37
+
38
+ context "open merge_cells.xls" do
39
+ before do
40
+ @book = WrapExcel::Book.open(@dir + '/merge_cells.xls')
41
+ @sheet = @book[0]
42
+ end
43
+
44
+ after do
45
+ @book.close
46
+ end
47
+
48
+ it "merged cell get same value" do
49
+ @sheet[0, 0].value.should eq 'merged cell'
50
+ @sheet[0, 1].value.should eq 'merged cell'
51
+ end
52
+
53
+ it "set merged cell" do
54
+ @sheet[1, 0].value = "set merge cell"
55
+ @sheet[1, 0].value.should eq "set merge cell"
56
+ @sheet[1, 1].value.should eq "set merge cell"
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), './spec_helper')
3
+
4
+ describe WrapExcel::Cygwin, :if => RUBY_PLATFORM =~ /cygwin/ do
5
+ describe ".cygpath" do
6
+ context "cygwin path is '/cygdrive/c/Users'" do
7
+ context "with '-w' options" do
8
+ it { WrapExcel::Cygwin.cygpath('-w', '/cygdrive/c/Users').should eq 'C:\\Users' }
9
+ end
10
+
11
+ context "with '-wa' options" do
12
+ it { WrapExcel::Cygwin.cygpath('-wa', '/cygdrive/c/Users').should eq 'C:\\Users' }
13
+ end
14
+
15
+ context "with '-ws' options" do
16
+ it { WrapExcel::Cygwin.cygpath('-ws', '/cygdrive/c/Users').should eq 'C:\\Users' }
17
+ end
18
+ end
19
+
20
+ context "windows path is 'C:\\Users'" do
21
+ context "with '-u option" do
22
+ it { WrapExcel::Cygwin.cygpath('-u', 'C:\\Users').should eq '/cygdrive/c/Users'}
23
+ end
24
+ end
25
+
26
+ context "cygwin path is './'" do
27
+ context "with '-u' options" do
28
+ it { WrapExcel::Cygwin.cygpath('-u', './').should eq './' }
29
+ end
30
+
31
+ context "with '-ua' options" do
32
+ it { WrapExcel::Cygwin.cygpath('-ua', './').should eq File.expand_path('./') + '/' }
33
+ end
34
+
35
+ context "with '-us' options" do
36
+ it { WrapExcel::Cygwin.cygpath('-us', './').should eq './' }
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
Binary file
Binary file
@@ -0,0 +1,69 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), './spec_helper')
3
+
4
+ describe WrapExcel::Range do
5
+ before do
6
+ @dir = create_tmpdir
7
+ @book = WrapExcel::Book.open(@dir + '/simple.xls')
8
+ @sheet = @book[1]
9
+ @range = WrapExcel::Range.new(@sheet.sheet.UsedRange.Rows(1))
10
+ end
11
+
12
+ after do
13
+ @book.close
14
+ rm_tmp(@dir)
15
+ end
16
+
17
+ describe "#each" do
18
+ it "items is WrapExcel::Cell" do
19
+ @range.each do |cell|
20
+ cell.should be_kind_of WrapExcel::Cell
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "#values" do
26
+ context "with (0..2)" do
27
+ it { @range.values(0..2).should eq ['simple', 'file', 'sheet2'] }
28
+ end
29
+
30
+ context "with (1..2)" do
31
+ it { @range.values(1..2).should eq ['file', 'sheet2'] }
32
+ end
33
+
34
+ context "with (2..2)" do
35
+ it { @range.values(2..2).should eq ['sheet2'] }
36
+ end
37
+
38
+ context "with no arguments" do
39
+ it { @range.values.should eq ['simple', 'file', 'sheet2'] }
40
+ end
41
+
42
+ context "when instance is column range" do
43
+ before do
44
+ @sheet = @book[0]
45
+ @range = WrapExcel::Range.new(@sheet.sheet.UsedRange.Columns(1))
46
+ end
47
+ it { @range.values.should eq ['simple', 'foo', 'matz'] }
48
+ end
49
+ end
50
+
51
+ describe "#[]" do
52
+ context "access [0]" do
53
+ it { @range[0].should be_kind_of WrapExcel::Cell }
54
+ it { @range[0].value.should eq 'simple' }
55
+ end
56
+
57
+ context "access [2]" do
58
+ it { @range[2].value.should eq 'sheet2' }
59
+ end
60
+
61
+ context "access [0] and [1] and [2]" do
62
+ it "should get every values" do
63
+ @range[0].value.should eq 'simple'
64
+ @range[1].value.should eq 'file'
65
+ @range[2].value.should eq 'sheet2'
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,173 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), './spec_helper')
3
+
4
+ describe WrapExcel::Sheet do
5
+ before do
6
+ @dir = create_tmpdir
7
+ @book = WrapExcel::Book.open(@dir + '/simple.xls')
8
+ @sheet = @book[0]
9
+ end
10
+
11
+ after do
12
+ @book.close
13
+ rm_tmp(@dir)
14
+ end
15
+
16
+ describe "access sheet name" do
17
+ describe "#name" do
18
+ it 'get sheet1 name' do
19
+ @sheet.name.should eq 'Sheet1'
20
+ end
21
+ end
22
+
23
+ describe "#name=" do
24
+ it 'change sheet1 name to foo' do
25
+ @sheet.name = 'foo'
26
+ @sheet.name.should eq 'foo'
27
+ end
28
+ end
29
+ end
30
+
31
+ describe 'access cell' do
32
+ describe "#[]" do
33
+ context "access [0,0]" do
34
+ it { @sheet[0, 0].should be_kind_of WrapExcel::Cell }
35
+ it { @sheet[0, 0].value.should eq 'simple' }
36
+ end
37
+
38
+ context "access [0, 0], [0, 1], [2, 0]" do
39
+ it "should get every values" do
40
+ @sheet[0, 0].value.should eq 'simple'
41
+ @sheet[0, 1].value.should eq 'workbook'
42
+ @sheet[2, 0].value.should eq 'matz'
43
+ end
44
+ end
45
+ end
46
+
47
+ it "change a cell to 'foo'" do
48
+ @sheet[0, 0] = 'foo'
49
+ @sheet[0, 0].value.should eq 'foo'
50
+ end
51
+
52
+ describe '#each' do
53
+ it "should sort line in order of column" do
54
+ @sheet.each_with_index do |cell, i|
55
+ case i
56
+ when 0
57
+ cell.value.should eq 'simple'
58
+ when 1
59
+ cell.value.should eq 'workbook'
60
+ when 2
61
+ cell.value.should eq 'sheet1'
62
+ when 3
63
+ cell.value.should eq 'foo'
64
+ when 4
65
+ cell.value.should be_nil
66
+ when 5
67
+ cell.value.should eq 'foobaaa'
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "#each_row" do
74
+ it "items should WrapExcel::Range" do
75
+ @sheet.each_row do |rows|
76
+ rows.should be_kind_of WrapExcel::Range
77
+ end
78
+ end
79
+
80
+ context "with argument 1" do
81
+ it 'should read from second row' do
82
+ @sheet.each_row(1) do |rows|
83
+ case rows.row
84
+ when 2
85
+ rows.values.should eq ['foo', nil, 'foobaaa']
86
+ when 3
87
+ rows.values.should eq ['matz', 'is', 'nice']
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ describe "#each_row_with_index" do
95
+ it "should read with index" do
96
+ @sheet.each_row_with_index do |rows, idx|
97
+ case idx
98
+ when 0
99
+ rows.values.should eq ['simple', 'workbook', 'sheet1']
100
+ when 1
101
+ rows.values.should eq ['foo', nil, 'foobaaa']
102
+ when 2
103
+ rows.values.should eq ['matz', 'is', 'nice']
104
+ end
105
+ end
106
+ end
107
+
108
+ context "with argument 1" do
109
+ it "should read from second row, index is started 0" do
110
+ @sheet.each_row_with_index(1) do |rows, idx|
111
+ case idx
112
+ when 0
113
+ rows.values.should eq ['foo', nil, 'foobaaa']
114
+ when 1
115
+ rows.values.should eq ['matz', 'is', 'nice']
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ end
122
+
123
+ describe "#each_column" do
124
+ it "items should WrapExcel::Range" do
125
+ @sheet.each_column do |columns|
126
+ columns.should be_kind_of WrapExcel::Range
127
+ end
128
+ end
129
+
130
+ context "with argument 1" do
131
+ it "should read from second column" do
132
+ @sheet.each_column(1) do |columns|
133
+ case columns.column
134
+ when 2
135
+ columns.values.should eq ['workbook', nil, 'is']
136
+ when 3
137
+ columns.values.should eq ['sheet1', 'foobaaa', 'nice']
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+ describe "#each_column_with_index" do
145
+ it "should read with index" do
146
+ @sheet.each_column_with_index do |columns, idx|
147
+ case idx
148
+ when 0
149
+ columns.values.should eq ['simple', 'foo', 'matz']
150
+ when 1
151
+ columns.values.should eq ['workbook', nil, 'is']
152
+ when 2
153
+ columns.values.should eq ['sheet1', 'foobaaa', 'nice']
154
+ end
155
+ end
156
+ end
157
+
158
+ context "with argument 1" do
159
+ it "should read from second column, index is started 0" do
160
+ @sheet.each_column_with_index(1) do |column_range, idx|
161
+ case idx
162
+ when 0
163
+ column_range.values.should eq ['workbook', nil, 'is']
164
+ when 1
165
+ column_range.values.should eq ['sheet1', 'foobaaa', 'nice']
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ end
173
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "rspec"
3
+ require 'tmpdir'
4
+ require "fileutils"
5
+ require File.join(File.dirname(__FILE__), '../lib/wrap_excel')
6
+
7
+ def create_tmpdir
8
+ tmpdir = Dir.mktmpdir
9
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), 'data'), tmpdir)
10
+ tmpdir + '/data'
11
+ end
12
+
13
+ def rm_tmp(tmpdir)
14
+ FileUtils.remove_entry_secure(File.dirname(tmpdir))
15
+ end
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "wrap_excel/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "wrap_excel"
7
+ s.version = WrapExcel::VERSION
8
+ s.authors = ["tomi"]
9
+ s.email = ["tomiacannondale@gmail.com"]
10
+ s.homepage = "https://github.com/tomiacannondale/wrap_excel"
11
+ s.summary = "WrapExcel is a wrapper library that specializes in the operation of Excel win32ole."
12
+ s.description = "WrapExcel is to wrap the win32ole, and easy to use Excel operations with ruby. Detailed description please see the README."
13
+
14
+ s.rubyforge_project = "wrap_excel"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.rdoc_options += [
18
+ '--main', 'README.rdoc',
19
+ '--charset', 'utf-8'
20
+ ]
21
+ s.extra_rdoc_files = ['README.rdoc', 'README.ja.rdoc', 'LICENSE']
22
+
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ s.add_development_dependency "rake", '>= 0.9.2'
27
+ s.add_development_dependency "rspec", '>= 2.6.0'
28
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wrap_excel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tomi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-08 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70322277204940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70322277204940
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70322277204440 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.6.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70322277204440
36
+ description: WrapExcel is to wrap the win32ole, and easy to use Excel operations with
37
+ ruby. Detailed description please see the README.
38
+ email:
39
+ - tomiacannondale@gmail.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files:
43
+ - README.rdoc
44
+ - README.ja.rdoc
45
+ - LICENSE
46
+ files:
47
+ - .gitignore
48
+ - .rspec
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.ja.rdoc
52
+ - README.rdoc
53
+ - Rakefile
54
+ - lib/wrap_excel.rb
55
+ - lib/wrap_excel/book.rb
56
+ - lib/wrap_excel/cell.rb
57
+ - lib/wrap_excel/range.rb
58
+ - lib/wrap_excel/sheet.rb
59
+ - lib/wrap_excel/version.rb
60
+ - spec/book_spec.rb
61
+ - spec/cell_spec.rb
62
+ - spec/cygwin_spec.rb
63
+ - spec/data/merge_cells.xls
64
+ - spec/data/simple.xls
65
+ - spec/range_spec.rb
66
+ - spec/sheet_spec.rb
67
+ - spec/spec_helper.rb
68
+ - wrap_excel.gemspec
69
+ homepage: https://github.com/tomiacannondale/wrap_excel
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --main
74
+ - README.rdoc
75
+ - --charset
76
+ - utf-8
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project: wrap_excel
93
+ rubygems_version: 1.8.10
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: WrapExcel is a wrapper library that specializes in the operation of Excel
97
+ win32ole.
98
+ test_files:
99
+ - spec/book_spec.rb
100
+ - spec/cell_spec.rb
101
+ - spec/cygwin_spec.rb
102
+ - spec/data/merge_cells.xls
103
+ - spec/data/simple.xls
104
+ - spec/range_spec.rb
105
+ - spec/sheet_spec.rb
106
+ - spec/spec_helper.rb