Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit f2fd2c1fa01c16685c404041f918d22a12eb723a 0 parents
@tomiacannondale authored
6 .gitignore
@@ -0,0 +1,6 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+vendor/bundle
+*~
1  .rspec
@@ -0,0 +1 @@
+--format documentation
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in wrap_excel.gemspec
+gemspec
7 LICENSE
@@ -0,0 +1,7 @@
+Copyright (c) 2011 tomi
+
+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:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+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.
108 README.ja.rdoc
@@ -0,0 +1,108 @@
+= WrapExcel
+
+== 概要
+
+WrapExcelはwin32oleをラップし、rubyによるExcelオペレーションを簡単にします。
+
+== 必要なもの
+
+* ruby 1.9.2以上 (プラットフォームはwindowsです)
+
+== インストール
+
+ gem install wrap_excel
+
+== 使い方
+=== bookへのアクセス
+
+ブロックを使用する場合
+
+ WrapExcel::Book.open('./sample.xls') do |book|
+ # do something
+ end
+
+ブロックを使用しない場合
+
+ book = WrapExcel::Book.open('./sample.xls')
+ book.close
+
+オプションは以下の通りです。
+
+* read_only:: boolean default true
+* displayalerts:: boolean default false
+* visible:: boolean false
+
+=== sheetへのアクセス
+
+sheetオブジェクトへは #[] メソッドでアクセス出来ます。
+
+ sheet = book[0]
+
+シート名でのアクセス
+
+ book['Sheet1']
+
+=== 行または列へのアクセス
+
+sheetオブジェクトはenumerableをインクルードしています。#each_column or #each_row or #each メソッドが使用できます。
+
+ sheet.each do |cell|
+ # do something with cell
+ # read every row every column
+ end
+
+ sheet.each_row do |row|
+ # do something with row_range
+ end
+
+ sheet.each_column do |column_range|
+ # do something with column_range
+ end
+
+=== セルへのアクセス
+
+sheetオブジェクトからのアクセス。
+
+ sheet[0, 0] => first cell.
+
+rangeオブジェクトからのアクセス。
+
+ row_range[0] => first cell in row_range
+ column_range[1] => second cell in column_range
+
+=== ファイルの保存
+
+既存のファイルは保存可能です。
+
+ WrapExcel::Book.open('./sample.xls') do |book|
+ # do something
+ book.save
+ end
+
+もしくは
+
+ book = WrapExcel::Book.open('./sample.xls')
+ book.save
+ book.close
+
+新規ファイルの保存は出来ません。
+
+=== Want to do more things
+
+全てのWrapExcelオブジェクトはwin32oleインスタンスを含んでいます。もし、あなたが、WrapExcelライブラリが提供していない機能を使用したい場合、win32oleのメソッドが使用出来ます。
+
+== サポート
+
+問題を報告したり、機能追加の要望する場合はgithubのIssuesに登録してください。 [https://github.com/tomiacannondale/wrap_excel/issues]
+
+== 共同作業
+
+githubのpull requestをしてください。
+
+== 開発者
+
+tomi [tomiacannondale@gmail.com]
+
+== ライセンス
+
+MITライセンスです。詳細はLICENSEを参照してください。
108 README.rdoc
@@ -0,0 +1,108 @@
+= WrapExcel
+
+== Description
+
+WrapExcel is a to wrap the win32ole, and easy to use Excel operations with ruby.
+
+== Requirements
+
+* ruby 1.9.2 or higher (platform is windows)
+
+== Install
+
+ gem install wrap_excel
+
+== Usage
+=== access book
+
+Read with block.
+
+ WrapExcel::Book.open('./sample.xls') do |book|
+ # do something
+ end
+
+Read without block.
+
+ book = WrapExcel::Book.open('./sample.xls')
+ book.close
+
+Options are the following.
+
+* read_only:: boolean default true
+* displayalerts:: boolean default false
+* visible:: boolean false
+
+=== access sheet
+
+Sheet object can access with #[] method.
+
+ sheet = book[0]
+
+Access with sheet name.
+
+ book['Sheet1']
+
+=== access row or column
+
+Sheet object is included enumerable. Use #each_column or #each_row or #each method.
+
+ sheet.each do |cell|
+ # do something with cell
+ # read every row every column
+ end
+
+ sheet.each_row do |row|
+ # do something with row_range
+ end
+
+ sheet.each_column do |column_range|
+ # do something with column_range
+ end
+
+=== access cell
+
+Read from sheet object.
+
+ sheet[0, 0] => first cell.
+
+Read from range object
+
+ row_range[0] => first cell in row_range
+ column_range[1] => second cell in column_range
+
+=== write excel
+
+Can save an existing file.
+
+ WrapExcel::Book.open('./sample.xls') do |book|
+ # do something
+ book.save
+ end
+
+or
+
+ book = WrapExcel::Book.open('./sample.xls')
+ book.save
+ book.close
+
+Can not save new file.
+
+=== Want to do more things
+
+All WrapExcel object include win32ole instance. If you want to do something that not provide a function, you can use win32ole methods.
+
+== Support
+
+Report issues and feature requests to github Issues. [https://github.com/tomiacannondale/wrap_excel/issues]
+
+== Collaborate
+
+Please pull request on github.
+
+== Author
+
+tomi [tomiacannondale@gmail.com]
+
+== License
+
+MIT License. For more imformation, please see LICENSE.
9 Rakefile
@@ -0,0 +1,9 @@
+require 'bundler/gem_tasks'
+
+require "rake"
+require "rspec/core/rake_task"
+
+RSpec::Core::RakeTask.new(:spec) do |s|
+ s.rspec_opts = '-f d'
+end
+task :default => :spec
49 lib/wrap_excel.rb
@@ -0,0 +1,49 @@
+require "win32ole"
+require File.join(File.dirname(__FILE__), 'wrap_excel/book')
+require File.join(File.dirname(__FILE__), 'wrap_excel/sheet')
+require File.join(File.dirname(__FILE__), 'wrap_excel/cell')
+require File.join(File.dirname(__FILE__), 'wrap_excel/range')
+require "wrap_excel/version"
+
+module WrapExcel
+
+ module Cygwin
+ require 'Win32API'
+
+ @conv_to_full_posix_path =
+ Win32API.new('cygwin1.dll', 'cygwin_conv_to_full_posix_path', 'PP', 'I')
+ @conv_to_posix_path =
+ Win32API.new('cygwin1.dll', 'cygwin_conv_to_posix_path', 'PP', 'I')
+ @conv_to_full_win32_path =
+ Win32API.new('cygwin1.dll', 'cygwin_conv_to_full_win32_path', 'PP', 'I')
+ @conv_to_win32_path =
+ Win32API.new('cygwin1.dll', 'cygwin_conv_to_win32_path', 'PP', 'I')
+
+ def cygpath(options, path)
+ absolute = shortname = false
+ func = nil
+ options.delete(" \t-").chars {|opt|
+ case opt
+ when ?u
+ func = [@conv_to_full_posix_path, @conv_to_posix_path]
+ when ?w
+ func = [@conv_to_full_win32_path, @conv_to_win32_path]
+ when ?a
+ absolute = true
+ when ?s
+ shortname = true
+ end
+ }
+ raise "first argument must contain -u or -w" if func.nil?
+ func = absolute ? func[0] : func[1]
+ buf = "\0" * 300
+ if func.Call(path, buf) == -1
+ raise "cannot convert path name"
+ end
+ buf.delete!("\0")
+ buf
+ end
+ module_function :cygpath
+ end
+
+end
55 lib/wrap_excel/book.rb
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+module WrapExcel
+
+ class Book
+ attr_reader :book
+
+ def initialize(file, options={ }, &block)
+ options = {
+ :read_only => true,
+ :displayalerts => false,
+ :visible => false
+ }.merge(options)
+ file = WrapExcel::Cygwin.cygpath('-w', file) if RUBY_PLATFORM =~ /cygwin/
+ file = WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file)
+ @winapp = WIN32OLE.new('Excel.Application')
+ @winapp.DisplayAlerts = options[:displayalerts]
+ @winapp.Visible = options[:visible]
+ @book = @winapp.Workbooks.Open(file,{ 'ReadOnly' => options[:read_only] })
+
+ if block
+ begin
+ yield self
+ ensure
+ close
+ end
+ end
+
+ @book
+ end
+
+ def close
+ @winapp.Workbooks.Close
+ @winapp.Quit
+ end
+
+ def save
+ @book.save
+ end
+
+ def [] sheet
+ sheet += 1 if sheet.is_a? Numeric
+ WrapExcel::Sheet.new(@book.Worksheets.Item(sheet))
+ end
+
+ def each
+ @book.Worksheets.each do |sheet|
+ yield WrapExcel::Sheet.new(sheet)
+ end
+ end
+
+ def self.open(file, options={ }, &block)
+ new(file, options, &block)
+ end
+ end
+end
19 lib/wrap_excel/cell.rb
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+
+module WrapExcel
+ class Cell
+ attr_reader :cell
+
+ def initialize(win32_cell)
+ if win32_cell.MergeCells
+ @cell = win32_cell.MergeArea.Item(1,1)
+ else
+ @cell = win32_cell
+ end
+ end
+
+ def method_missing(id, *args)
+ @cell.send(id, *args)
+ end
+ end
+end
34 lib/wrap_excel/range.rb
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+module WrapExcel
+ class Range
+ def initialize(win32_range)
+ @range = win32_range
+ end
+
+ def each
+ @range.each do |row_or_column|
+ yield WrapExcel::Cell.new(row_or_column)
+ end
+ end
+
+ def values(range = nil)
+ if range
+ min = range.min + 1
+ max = range.max + 1
+ result = @range.Range(@range.Cells.Item(min), @range.Cells(max)).value
+ result.is_a?(Array) ? result[0] : [result]
+ else
+ @range.Cells.value.flatten
+ end
+ end
+
+ def [] index
+ @cells ||= []
+ @cells[index + 1] ||= WrapExcel::Cell.new(@range.Cells.Item(index + 1))
+ end
+
+ def method_missing(id, *args)
+ @range.send(id, *args)
+ end
+ end
+end
65 lib/wrap_excel/sheet.rb
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+module WrapExcel
+ class Sheet
+ attr_reader :sheet
+ include Enumerable
+
+ def initialize(win32_worksheet)
+ @sheet = win32_worksheet
+ end
+
+ def name
+ @sheet.Name
+ end
+
+ def name= (new_name)
+ @sheet.Name = new_name
+ end
+
+ def [] y, x
+ yx = "#{y+1}_#{x+1}"
+ @cells ||= { }
+ @cells[yx] ||= WrapExcel::Cell.new(@sheet.Cells.Item(y+1, x+1))
+ end
+
+ def []= (y, x, value)
+ @sheet.Cells.Item(y+1, x+1).Value = value
+ end
+
+ def each
+ @sheet.UsedRange.Rows.each do |row_range|
+ row_range.Cells.each do |cell|
+ yield WrapExcel::Cell.new(cell)
+ end
+ end
+ end
+
+ def each_row(offset = 0)
+ offset += 1
+ @sheet.UsedRange.Rows.each do |row_range|
+ next if row_range.row < offset
+ yield WrapExcel::Range.new(row_range)
+ end
+ end
+
+ def each_row_with_index(offset = 0)
+ each_row(offset) do |row_range|
+ yield WrapExcel::Range.new(row_range), (row_range.row - 1 - offset)
+ end
+ end
+
+ def each_column(offset = 0)
+ offset += 1
+ @sheet.UsedRange.Columns.each do |column_range|
+ next if column_range.column < offset
+ yield WrapExcel::Range.new(column_range)
+ end
+ end
+
+ def each_column_with_index(offset = 0)
+ each_column(offset) do |column_range|
+ yield WrapExcel::Range.new(column_range), (column_range.column - 1 - offset)
+ end
+ end
+ end
+end
3  lib/wrap_excel/version.rb
@@ -0,0 +1,3 @@
+module WrapExcel
+ VERSION = "0.0.3"
+end
79 spec/book_spec.rb
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+
+require File.join(File.dirname(__FILE__), './spec_helper')
+
+describe WrapExcel::Book do
+ before do
+ @dir = create_tmpdir
+ @simple_file = @dir + '/simple.xls'
+ end
+
+ after do
+ rm_tmp(@dir)
+ end
+
+ describe ".open" do
+ context "exist file" do
+ it "simple file with default" do
+ expect {
+ book = WrapExcel::Book.open(@simple_file)
+ book.close
+ }.to_not raise_error
+ end
+
+ it "simple file with writable" do
+ expect {
+ book = WrapExcel::Book.open(@simple_file, :read_only => false)
+ book.close
+ }.to_not raise_error
+ end
+
+ it "simple file with visible = true" do
+ expect {
+ book = WrapExcel::Book.open(@simple_file, :visible => true)
+ book.close
+ }.to_not raise_error
+ end
+
+ context "with block" do
+ it 'block parameter should be instance of WrapExcel::Book' do
+ WrapExcel::Book.open(@simple_file) do |book|
+ book.should be_is_a WrapExcel::Book
+ end
+ end
+ end
+ end
+ end
+
+ describe 'access sheet' do
+ before do
+ @book = WrapExcel::Book.open(@simple_file)
+ end
+
+ after do
+ @book.close
+ end
+
+ it 'with sheet name' do
+ @book['Sheet1'].should be_kind_of WrapExcel::Sheet
+ end
+
+ it 'with integer' do
+ @book[0].should be_kind_of WrapExcel::Sheet
+ end
+
+ it 'with block' do
+ @book.each do |sheet|
+ sheet.should be_kind_of WrapExcel::Sheet
+ end
+ end
+
+ context 'open with block' do
+ it {
+ WrapExcel::Book.open(@simple_file) do |book|
+ book['Sheet1'].should be_is_a WrapExcel::Sheet
+ end
+ }
+ end
+ end
+end
59 spec/cell_spec.rb
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+require File.join(File.dirname(__FILE__), './spec_helper')
+
+describe WrapExcel::Cell do
+ before do
+ @dir = create_tmpdir
+ end
+
+ after do
+ rm_tmp(@dir)
+ end
+
+ context "open simple.xls" do
+ before do
+ @book = WrapExcel::Book.open(@dir + '/simple.xls')
+ @sheet = @book[1]
+ @cell = @sheet[0, 0]
+ end
+
+ after do
+ @book.close
+ end
+
+ describe "#value" do
+ it "get cell's value" do
+ @cell.value.should eq 'simple'
+ end
+ end
+
+ describe "#value=" do
+ it "change cell data to 'fooooo'" do
+ @cell.value = 'fooooo'
+ @cell.value.should eq 'fooooo'
+ end
+ end
+ end
+
+ context "open merge_cells.xls" do
+ before do
+ @book = WrapExcel::Book.open(@dir + '/merge_cells.xls')
+ @sheet = @book[0]
+ end
+
+ after do
+ @book.close
+ end
+
+ it "merged cell get same value" do
+ @sheet[0, 0].value.should eq 'merged cell'
+ @sheet[0, 1].value.should eq 'merged cell'
+ end
+
+ it "set merged cell" do
+ @sheet[1, 0].value = "set merge cell"
+ @sheet[1, 0].value.should eq "set merge cell"
+ @sheet[1, 1].value.should eq "set merge cell"
+ end
+ end
+end
42 spec/cygwin_spec.rb
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+require File.join(File.dirname(__FILE__), './spec_helper')
+
+describe WrapExcel::Cygwin, :if => RUBY_PLATFORM =~ /cygwin/ do
+ describe ".cygpath" do
+ context "cygwin path is '/cygdrive/c/Users'" do
+ context "with '-w' options" do
+ it { WrapExcel::Cygwin.cygpath('-w', '/cygdrive/c/Users').should eq 'C:\\Users' }
+ end
+
+ context "with '-wa' options" do
+ it { WrapExcel::Cygwin.cygpath('-wa', '/cygdrive/c/Users').should eq 'C:\\Users' }
+ end
+
+ context "with '-ws' options" do
+ it { WrapExcel::Cygwin.cygpath('-ws', '/cygdrive/c/Users').should eq 'C:\\Users' }
+ end
+ end
+
+ context "windows path is 'C:\\Users'" do
+ context "with '-u option" do
+ it { WrapExcel::Cygwin.cygpath('-u', 'C:\\Users').should eq '/cygdrive/c/Users'}
+ end
+ end
+
+ context "cygwin path is './'" do
+ context "with '-u' options" do
+ it { WrapExcel::Cygwin.cygpath('-u', './').should eq './' }
+ end
+
+ context "with '-ua' options" do
+ it { WrapExcel::Cygwin.cygpath('-ua', './').should eq File.expand_path('./') + '/' }
+ end
+
+ context "with '-us' options" do
+ it { WrapExcel::Cygwin.cygpath('-us', './').should eq './' }
+ end
+ end
+
+ end
+
+end
BIN  spec/data/merge_cells.xls
Binary file not shown
BIN  spec/data/simple.xls
Binary file not shown
69 spec/range_spec.rb
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+require File.join(File.dirname(__FILE__), './spec_helper')
+
+describe WrapExcel::Range do
+ before do
+ @dir = create_tmpdir
+ @book = WrapExcel::Book.open(@dir + '/simple.xls')
+ @sheet = @book[1]
+ @range = WrapExcel::Range.new(@sheet.sheet.UsedRange.Rows(1))
+ end
+
+ after do
+ @book.close
+ rm_tmp(@dir)
+ end
+
+ describe "#each" do
+ it "items is WrapExcel::Cell" do
+ @range.each do |cell|
+ cell.should be_kind_of WrapExcel::Cell
+ end
+ end
+ end
+
+ describe "#values" do
+ context "with (0..2)" do
+ it { @range.values(0..2).should eq ['simple', 'file', 'sheet2'] }
+ end
+
+ context "with (1..2)" do
+ it { @range.values(1..2).should eq ['file', 'sheet2'] }
+ end
+
+ context "with (2..2)" do
+ it { @range.values(2..2).should eq ['sheet2'] }
+ end
+
+ context "with no arguments" do
+ it { @range.values.should eq ['simple', 'file', 'sheet2'] }
+ end
+
+ context "when instance is column range" do
+ before do
+ @sheet = @book[0]
+ @range = WrapExcel::Range.new(@sheet.sheet.UsedRange.Columns(1))
+ end
+ it { @range.values.should eq ['simple', 'foo', 'matz'] }
+ end
+ end
+
+ describe "#[]" do
+ context "access [0]" do
+ it { @range[0].should be_kind_of WrapExcel::Cell }
+ it { @range[0].value.should eq 'simple' }
+ end
+
+ context "access [2]" do
+ it { @range[2].value.should eq 'sheet2' }
+ end
+
+ context "access [0] and [1] and [2]" do
+ it "should get every values" do
+ @range[0].value.should eq 'simple'
+ @range[1].value.should eq 'file'
+ @range[2].value.should eq 'sheet2'
+ end
+ end
+ end
+end
173 spec/sheet_spec.rb
@@ -0,0 +1,173 @@
+# -*- coding: utf-8 -*-
+require File.join(File.dirname(__FILE__), './spec_helper')
+
+describe WrapExcel::Sheet do
+ before do
+ @dir = create_tmpdir
+ @book = WrapExcel::Book.open(@dir + '/simple.xls')
+ @sheet = @book[0]
+ end
+
+ after do
+ @book.close
+ rm_tmp(@dir)
+ end
+
+ describe "access sheet name" do
+ describe "#name" do
+ it 'get sheet1 name' do
+ @sheet.name.should eq 'Sheet1'
+ end
+ end
+
+ describe "#name=" do
+ it 'change sheet1 name to foo' do
+ @sheet.name = 'foo'
+ @sheet.name.should eq 'foo'
+ end
+ end
+ end
+
+ describe 'access cell' do
+ describe "#[]" do
+ context "access [0,0]" do
+ it { @sheet[0, 0].should be_kind_of WrapExcel::Cell }
+ it { @sheet[0, 0].value.should eq 'simple' }
+ end
+
+ context "access [0, 0], [0, 1], [2, 0]" do
+ it "should get every values" do
+ @sheet[0, 0].value.should eq 'simple'
+ @sheet[0, 1].value.should eq 'workbook'
+ @sheet[2, 0].value.should eq 'matz'
+ end
+ end
+ end
+
+ it "change a cell to 'foo'" do
+ @sheet[0, 0] = 'foo'
+ @sheet[0, 0].value.should eq 'foo'
+ end
+
+ describe '#each' do
+ it "should sort line in order of column" do
+ @sheet.each_with_index do |cell, i|
+ case i
+ when 0
+ cell.value.should eq 'simple'
+ when 1
+ cell.value.should eq 'workbook'
+ when 2
+ cell.value.should eq 'sheet1'
+ when 3
+ cell.value.should eq 'foo'
+ when 4
+ cell.value.should be_nil
+ when 5
+ cell.value.should eq 'foobaaa'
+ end
+ end
+ end
+ end
+
+ describe "#each_row" do
+ it "items should WrapExcel::Range" do
+ @sheet.each_row do |rows|
+ rows.should be_kind_of WrapExcel::Range
+ end
+ end
+
+ context "with argument 1" do
+ it 'should read from second row' do
+ @sheet.each_row(1) do |rows|
+ case rows.row
+ when 2
+ rows.values.should eq ['foo', nil, 'foobaaa']
+ when 3
+ rows.values.should eq ['matz', 'is', 'nice']
+ end
+ end
+ end
+ end
+ end
+
+ describe "#each_row_with_index" do
+ it "should read with index" do
+ @sheet.each_row_with_index do |rows, idx|
+ case idx
+ when 0
+ rows.values.should eq ['simple', 'workbook', 'sheet1']
+ when 1
+ rows.values.should eq ['foo', nil, 'foobaaa']
+ when 2
+ rows.values.should eq ['matz', 'is', 'nice']
+ end
+ end
+ end
+
+ context "with argument 1" do
+ it "should read from second row, index is started 0" do
+ @sheet.each_row_with_index(1) do |rows, idx|
+ case idx
+ when 0
+ rows.values.should eq ['foo', nil, 'foobaaa']
+ when 1
+ rows.values.should eq ['matz', 'is', 'nice']
+ end
+ end
+ end
+ end
+
+ end
+
+ describe "#each_column" do
+ it "items should WrapExcel::Range" do
+ @sheet.each_column do |columns|
+ columns.should be_kind_of WrapExcel::Range
+ end
+ end
+
+ context "with argument 1" do
+ it "should read from second column" do
+ @sheet.each_column(1) do |columns|
+ case columns.column
+ when 2
+ columns.values.should eq ['workbook', nil, 'is']
+ when 3
+ columns.values.should eq ['sheet1', 'foobaaa', 'nice']
+ end
+ end
+ end
+ end
+ end
+
+ describe "#each_column_with_index" do
+ it "should read with index" do
+ @sheet.each_column_with_index do |columns, idx|
+ case idx
+ when 0
+ columns.values.should eq ['simple', 'foo', 'matz']
+ when 1
+ columns.values.should eq ['workbook', nil, 'is']
+ when 2
+ columns.values.should eq ['sheet1', 'foobaaa', 'nice']
+ end
+ end
+ end
+
+ context "with argument 1" do
+ it "should read from second column, index is started 0" do
+ @sheet.each_column_with_index(1) do |column_range, idx|
+ case idx
+ when 0
+ column_range.values.should eq ['workbook', nil, 'is']
+ when 1
+ column_range.values.should eq ['sheet1', 'foobaaa', 'nice']
+ end
+ end
+ end
+ end
+ end
+
+ end
+end
15 spec/spec_helper.rb
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+require "rspec"
+require 'tmpdir'
+require "fileutils"
+require File.join(File.dirname(__FILE__), '../lib/wrap_excel')
+
+def create_tmpdir
+ tmpdir = Dir.mktmpdir
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), 'data'), tmpdir)
+ tmpdir + '/data'
+end
+
+def rm_tmp(tmpdir)
+ FileUtils.remove_entry_secure(File.dirname(tmpdir))
+end
28 wrap_excel.gemspec
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "wrap_excel/version"
+
+Gem::Specification.new do |s|
+ s.name = "wrap_excel"
+ s.version = WrapExcel::VERSION
+ s.authors = ["tomi"]
+ s.email = ["tomiacannondale@gmail.com"]
+ s.homepage = ""
+ s.summary = "WrapExcel is a wrapper library that specializes in the operation of Excel win32ole."
+ s.description = "WrapExcel is to wrap the win32ole, and easy to use Excel operations with ruby. Detailed description please see the README."
+
+ s.rubyforge_project = "wrap_excel"
+
+ s.files = `git ls-files`.split("\n")
+ s.rdoc_options += [
+ '--main', 'README.rdoc',
+ '--charset', 'utf-8'
+ ]
+ s.extra_rdoc_files = ['README.rdoc', 'README.ja.rdoc', 'LICENSE']
+
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+ s.add_development_dependency "rake", '>= 0.9.2'
+ s.add_development_dependency "rspec", '>= 2.6.0'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.