Created
April 2, 2012 11:40
-
-
Save kohgpat/2282876 to your computer and use it in GitHub Desktop.
Ruby spreadsheet example
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
1 require 'spreadsheet' | |
# Open workbooks | |
current_workbook = Spreadsheet.open('jan.xls') | |
total_workbook = Spreadsheet.open('output.xls') | |
# Process xls | |
# Iterate through workbook spreadsheets | |
current_workbook.worksheets.each_with_index do |current_spreadsheet, spreadsheet_index| | |
# Open current sheet on total xls | |
total_sheet = total_workbook.worksheet(spreadsheet_index) | |
row_blacklist = [0, 1, 7] | |
col_blacklist = [0, 3] | |
current_spreadsheet.each_with_index do |row, row_idx| | |
row.each_with_index do |value, col_idx| | |
if row_blacklist.include?(row_idx) | |
next | |
end | |
if col_blacklist.include?(col_idx) | |
next | |
end | |
if value.class.to_s != 'Spreadsheet::Formula' | |
total_sheet.row(row_idx)[col_idx] = total_sheet.row(row_idx)[col_idx].to_i + value.to_i | |
end | |
end | |
end | |
total_workbook.write('output2.xls') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment