Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f2fd2c1
Showing
22 changed files
with
933 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
pkg/* | ||
vendor/bundle | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in wrap_excel.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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を参照してください。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.