Repository navigation
Integrations
English · 简体中文 · 繁體中文 · Español · العربية · Français · Português (Brasil) · Deutsch · हिन्दी · 日本語 · 한국어 · Русский · Bahasa Indonesia · Türkçe · Italiano · Tiếng Việt
docxi has no plugins and no built-in integrations. It's plain Ruby that returns a StringIO, so it works anywhere you can send or store a string. This page shows the usual ways to connect it. The Rails controller pattern is the one the README shows, and the test suite runs with Rails 5.2 to 8.1 loaded.
class ReportsController < ApplicationController
def show
word = Docxi::Document.new
word.document.p { |p| p.text "Report for #{Date.today}" }
send_data word.render.string,
filename: "report.docx",
type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
end
endsend_data sets Content-Disposition: attachment, so the browser downloads the file. With Bundler, docxi is loaded automatically from the Gemfile.
Large documents, or documents built from slow queries, are better made in a job:
class MonthlyReportJob < ApplicationJob
queue_as :default
def perform(path)
word = Docxi::Document.new
word.document.p { |p| p.text "Monthly report", bold: true, size: 16 }
File.binwrite(path, word.render.string)
end
endThe job writes to a path you choose. Where the file goes next, such as storage or email, is up to your app.
Any Rack application can return the bytes directly:
require "docxi"
class ReportApp
def call(env)
word = Docxi::Document.new
word.document.p { |p| p.text "Generated by a Rack app" }
headers = {
"content-type" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"content-disposition" => 'attachment; filename="report.docx"'
}
[200, headers, [word.render.string]]
end
endMount it with run ReportApp.new in config.ru. The same approach works for Sinatra, Hanami or any framework that can send a string as the response body.
docxi needs no server and no office software, so a plain Ruby script works:
require "docxi"
word = Docxi::Document.new
word.document.p { |p| p.text "Nightly export" }
File.binwrite(ARGV.fetch(0, "export.docx"), word.render.string)docxi wiki · README · Installation · Troubleshooting · Report an issue · MIT License
Start
Build documents
Help
Project
Links
Languages