我想使用 Rails 和 randym / axlsx 将 Excel 文件保存到保管箱。
我可以创建一个 Axlsx::Package 对象,我什至可以将它序列化,所以将它保存到我在开发环境中的磁盘中。
但我想使用 futuresimple/dropbox-api 将它上传到 Dropbox。
它能有多难?
def save_in_dropbox(project)
Dropbox::API::Config.app_key = ENV['DROPBOX_APP_KEY']
Dropbox::API::Config.app_secret = ENV['DROPBOX_APP_SECRET']
Dropbox::API::Config.mode = ENV['DROPBOX_ACCESS_TYPE']
dropbox_client = Dropbox::API::Client.new(:token => ENV['DROPBOX_CLIENT_TOKEN'], :secret => ENV['DROPBOX_CLIENT_SECRET'])
logger.info "#{dropbox_client.account}"
# create Excel file
p = Axlsx::Package.new
p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
sheet.add_row ["First Column", "Second", "Third"]
sheet.add_row [1, 2, 3]
end
p.use_shared_strings = true
# Next line causes Error: undefined method `length' for true:TrueClass
# because p.serialize('file.xlsx')) is true
# but I don't want to save to my disk, on heroku I couldn't
# I want to save to my dropbox
dropbox_client.upload("#{ENV['DROPBOX_ROOT_PATH']}/file.xlsx", p.serialize('file.xlsx'))
#p.serialize('c:\file.xlsx') # that saves it to my development env disk :-(
#uploaded_file = dropbox_client.upload "#{ENV['DROPBOX_ROOT_PATH']}/file.txt", "#{1.second.ago.to_s}\n\r#{project.title}" # Upload to Dropbox works fine
end