excel2csv 0.0.6 → 0.0.7

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.
data/README.md CHANGED
@@ -2,15 +2,44 @@
2
2
 
3
3
  ### Installation and usage
4
4
 
5
- gem install excel2csv
6
-
5
+ ``` ruby
6
+ gem install excel2csv
7
+ ```
7
8
 
8
9
  With Gemfile
9
10
 
10
- gem 'excel2csv'
11
+ ``` ruby
12
+ gem 'excel2csv'
13
+ ```
14
+
15
+ ### Requirements
16
+
17
+ 1. Ruby > 1.9.2
18
+ 2. Java Runtime
19
+
20
+ ### Usage
21
+
22
+ ``` ruby
23
+ require 'excel2csv'
24
+
25
+ # Read csv, xls, xlsx files like with CSV#read
26
+ Excel2CSV.read "path/to/file.csv", encoding:"windows-1251:utf-8"
27
+ # by default Excel2CSV reads first worksheet
28
+ Excel2CSV.read "path/to/file.xls" # working encoding is always UTF-8
29
+ Excel2CSV.read "path/to/file.xlsx" # working encoding is always UTF-8
30
+
31
+ # Line by line reading like with CSV#foreach
32
+ Excel2CSV.foreach("path/to/file.csv", encoding:"windows-1251:utf8") {|r| puts r}
33
+ Excel2CSV.foreach("path/to/file.xls") {|r| puts r}
34
+ Excel2CSV.foreach("path/to/file.xlsx") {|r| puts r}
11
35
 
36
+ # Read non first worksheet
37
+ Excel2CSV.read "path/to/file.xls", index:1 #reads second sheet
38
+ Excel2CSV.read "path/to/file.xlsx", index:2 #reads third sheet
12
39
 
13
- require 'excel2csv'
14
40
 
15
- Excel2CSV.read "path/to/file.xls"
16
- Excel2CSV.read "path/to/file.xlsx"
41
+ # Preview first N rows in big files
42
+ Excel2CSV.read "path/to/file.xls", rows_limit: 2, preview: true
43
+ Excel2CSV.read "path/to/file.xlsx", rows_limit: 2, preview: true
44
+ Excel2CSV.read "path/to/file.csv", rows_limit: 2, preview: true
45
+ ```
@@ -1,3 +1,3 @@
1
1
  module Excel2CSV
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/excel2csv.rb CHANGED
@@ -83,8 +83,8 @@ module Excel2CSV
83
83
  module_function :convert
84
84
 
85
85
  def path_to_sheet(info, options = {})
86
+ options.delete(:encoding) # all previews are in utf-8
86
87
  if options[:preview]
87
- options.delete(:encoding) # all previews are in utf-8
88
88
  collection = info.previews
89
89
  else
90
90
  collection = info.sheets
@@ -103,13 +103,19 @@ module Excel2CSV
103
103
  total_rows = 0
104
104
  preview_rows = []
105
105
  opts = clean_options(options)
106
- CSV.foreach(path, opts) do |row|
107
- if limit && total_rows <= limit
108
- preview_rows << row
106
+
107
+ # Transcode file to utf-8, count total and gen preview
108
+
109
+ CSV.open("#{dest_folder}/1-#{total_rows}.csv", "wb") do |csv|
110
+ CSV.foreach(path, opts) do |row|
111
+ if limit && total_rows <= limit
112
+ preview_rows << row
113
+ end
114
+ total_rows += 1
115
+ csv << row
109
116
  end
110
- total_rows += 1
111
117
  end
112
- FileUtils.cp path, "#{dest_folder}/1-#{total_rows}.csv"
118
+
113
119
  if limit
114
120
  CSV.open("#{dest_folder}/1-#{limit}-of-#{total_rows}-preview.csv", "wb") do |csv|
115
121
  preview_rows.each {|row| csv << row}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel2csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-25 00:00:00.000000000 Z
12
+ date: 2011-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70220199776100 !ruby/object:Gem::Requirement
16
+ requirement: &70102599300280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - <=
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70220199776100
24
+ version_requirements: *70102599300280
25
25
  description: gem for converting Excel files to csv
26
26
  email:
27
27
  - yury.korolev@gmail.com
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  requirements: []
64
64
  rubyforge_project:
65
- rubygems_version: 1.8.9
65
+ rubygems_version: 1.8.10
66
66
  signing_key:
67
67
  specification_version: 3
68
68
  summary: extract excel worksheets to csv files