ruby on rails - Creating a dynamic xlsx with the write_xlsx gem -
i want export part of db user .xlsx
i managed create static file , let user download it, that's not point.
the user should select filter wants , result file should created , downloaded directly through browser.
my code looks this:
controller
def download_pdf send_data generate_pdf, type: "application/xlsx" end private def generate_pdf workbook = writexlsx.new('export.xlsx') worksheet = workbook.add_worksheet worksheet.write(0, 0, 'status') worksheet.write(0, 1, 'date') worksheet.write(0, 2, 'customer') workbook end
the result file , content name of object
#<writexlsx:0x007fd9cf8aa290>
i'm not sure if write_xlsx specific or if i'm missing obvious here.
to save 'export.xlsx' disk, should use workbook#close. see generate_xlsx method below.
def generate_xlsx workbook = writexlsx.new('export.xlsx') worksheet = workbook.add_worksheet worksheet.write(0, 0, 'status') worksheet.write(0, 1, 'date') worksheet.write(0, 2, 'customer') workbook.close # <- workbook#close end
you can read documents @ http://cxn03651.github.io/write_xlsx/index.html.
enjoy!
Comments
Post a Comment