Repository navigation
Integrations ar
English · 简体中文 · 繁體中文 · Español · العربية · Français · Português (Brasil) · Deutsch · हिन्दी · 日本語 · 한국어 · Русский · Bahasa Indonesia · Türkçe · Italiano · Tiếng Việt
ليس لمكتبة docxi إضافات ولا تكاملات مدمجة. إنها شيفرة Ruby عادية تعيد كائن StringIO، لذا تعمل في أي مكان يمكنك فيه إرسال سلسلة نصية أو تخزينها. تعرض هذه الصفحة الطرق المعتادة لربطها. نمط وحدة التحكم في Rails هو النمط الذي يعرضه ملف 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
endتضبط send_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شغّله باستخدام run ReportApp.new في config.ru. ويصلح الأسلوب نفسه مع 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