Created
August 11, 2010 20:15
-
-
Save rubiety/519650 to your computer and use it in GitHub Desktop.
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
## Concatenates a subset of columns in Excel amongst multiple sheets into one dump | |
require "rubygems" | |
require "active_support" | |
require "roo" | |
require "faster_csv" | |
COLUMNS = ["A", "B"] # Column names of whatever you want | |
[].tap do |o| | |
Excel.new("/full/path/to/file.csv").sheets.each do |sheet| | |
2.upto(sheet.last_row) do |i| | |
o << COLUMNS.map {|c| sheet.cell(i, c) } | |
end | |
end | |
end.to_csv | |
# Or this crazier way using triply-nested array mapping and depth-flattening... | |
Excel.new("/full/path/to/file.csv").sheets.map do |sheet| | |
[2..sheet.last_row].map do |i| | |
COLUMNS.map {|c| sheet.cell(i, c) } | |
end | |
end.flatten(1).to_csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment