im try to put password in my excel file
def excel_file
test = Axlsx::Package.new do |p|
p.workbook.add_worksheet(:name => "Pie Chart") do |sheet|
sheet.add_row ["Simple Pie Chart"]
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "example 3: Pie Chart") do |chart|
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :colors => ['FF0000', '00FF00', '0000FF']
end
end
p.serialize('simple.xlsx')
end
IO.popen("secure-spreadsheet --password secret", "r+") do |io|
io.write(test)
io.close_write
io.read
end
end
in this code above it will generate excel file with name simple.xlsx in my project file. then i want to put password using secure-spreadsheet.
The "IO.popen" part of the code is. Im not sure is that right code that Im doing. the goal is get the created alxsx file then add a password.
def download_excel
respond_to do |format|
format.xlsx { send_data excel_file, type: 'application/xlsx; header=present', disposition: "attachment", filename: "output.xlsx" }
end
end
this code above will download in the browser.
here's origin of the question rails http response to Donwload excel file
here's the repo im using
https://github.com/randym/axlsx
https://github.com/ankane/secure-spreadsheet
im not using spreadsheet protection. i dont need that because it only lock the spreadsheet. what i need is a password for the entire excel file