Skip to content

Instantly share code, notes, and snippets.

@ytnk531
Created March 2, 2019 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytnk531/eee2cb278f1b36d1caff4c999e0672c7 to your computer and use it in GitHub Desktop.
Save ytnk531/eee2cb278f1b36d1caff4c999e0672c7 to your computer and use it in GitHub Desktop.
class ExcelsController < ApplicationController
def show
end
def create
file = params[:file]
# ファイルを開く
workbook = RubyXL::Parser.parse file.path
# 編集する
workbook[0].add_cell 0, 0, 'changed'
# 編集したファイルを送る
send_data workbook.stream.string, type: file.content_type, filename: 'modified.xlsx'
end
end
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root to: "excels#show"
resource :excel, only: [:show, :create]
end
<%= form_tag({action: :create}, multipart: true) do %>
<div>
<%= file_field_tag :file %>
</div>
<div>
<%= submit_tag "Send" %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment