class SpreadsheetToJson::JsonToSheet
This is a class to load JSON file to spreadsheet
Attributes
spreadsheet[R]
Public Class Methods
new(spreadsheet)
click to toggle source
# File lib/spreadsheet_to_json/json_to_sheet.rb, line 8 def initialize(spreadsheet) @spreadsheet = spreadsheet end
Public Instance Methods
convert_json_to_sheet(json_file_path, sheet_name)
click to toggle source
Load json to sheet
# File lib/spreadsheet_to_json/json_to_sheet.rb, line 13 def convert_json_to_sheet(json_file_path, sheet_name) arrays = json_to_hasharray(File.read(json_file_path)) if arrays.count <= 0 puts "the json file is empty" exit end worksheet = spreadsheet.get_sheet_by_name(sheet_name) worksheet.list.keys = arrays[0].keys arrays.each do |each| worksheet.list.push(each) end worksheet.save end
Private Instance Methods
json_to_hasharray(json_content)
click to toggle source
# File lib/spreadsheet_to_json/json_to_sheet.rb, line 28 def json_to_hasharray(json_content) JSON.parse(json_content) end