Repository navigation
Integrations hi
English · 简体中文 · 繁體中文 · Español · العربية · Français · Português (Brasil) · Deutsch · हिन्दी · 日本語 · 한국어 · Русский · Bahasa Indonesia · Türkçe · Italiano · Tiếng Việt
docxi में कोई प्लगइन या बिल्ट-इन इंटीग्रेशन नहीं है। यह साधारण Ruby है जो एक StringIO लौटाती है, इसलिए यह हर उस जगह काम करता है जहां आप कोई स्ट्रिंग भेज या स्टोर कर सकते हैं। यह पेज इसे जोड़ने के आम तरीके दिखाता है। Rails controller वाला तरीका वही है जो README में दिखाया गया है, और टेस्ट सूट Rails 5.2 से 8.1 लोड करके चलता है।
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 Content-Disposition: attachment सेट करता है, इसलिए ब्राउज़र फ़ाइल डाउनलोड कर लेता है। Bundler के साथ docxi, Gemfile से अपने-आप लोड हो जाता है।
बड़े डॉक्यूमेंट, या धीमी क्वेरी से बनने वाले डॉक्यूमेंट, जॉब में बनाना बेहतर है:
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
endजॉब आपके चुने हुए पाथ पर लिखता है। फ़ाइल आगे कहां जाएगी, जैसे स्टोरेज या ईमेल, यह आपका ऐप तय करता है।
कोई भी Rack ऐप्लिकेशन बाइट सीधे लौटा सकता है:
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
endइसे config.ru में run ReportApp.new से माउंट करें। यही तरीका Sinatra, Hanami या किसी भी ऐसे फ़्रेमवर्क के साथ काम करता है जो रिस्पॉन्स बॉडी के रूप में स्ट्रिंग भेज सकता है।
docxi को न सर्वर चाहिए और न ऑफ़िस सॉफ़्टवेयर, इसलिए एक साधारण Ruby स्क्रिप्ट काफ़ी है:
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