Repository navigation
Getting Started ar
Hammad Maqbool edited this page Oct 29, 2026
·
1 revision
English · 简体中文 · 繁體中文 · Español · العربية · Français · Português (Brasil) · Deutsch · हिन्दी · 日本語 · 한국어 · Русский · Bahasa Indonesia · Türkçe · Italiano · Tiếng Việt
يأخذك هذا الدليل من مجلد فارغ إلى ملف .docx منسّق. يفترض الدليل أنك تعرف أساسيات Ruby، ولا تحتاج إلى Rails أو Microsoft Word.
gem install docxiفي مشروع يحتوي على Gemfile، أضف gem "docxi", "~> 0.1" وشغّل bundle install بدلًا من ذلك. تجد التفاصيل في صفحة التثبيت.
احفظ ما يلي في ملف باسم hello.rb:
require "docxi"
word = Docxi::Document.new
document = word.document
document.p(align: "center") do |p|
p.text "Hello, Word", size: 24, bold: true
end
File.binwrite("hello.docx", word.render.string)شغّل ruby hello.rb (أو bundle exec ruby hello.rb في مشروع يستخدم Bundler) ثم افتح hello.docx.
- ينشئ
Docxi::Document.newمستندًا فارغًا بهوامش الصفحة الافتراضية. - يمثّل
word.documentمتن المستند، وكل ما تضيفه يمر عبره. - يضيف
document.pفقرة. الخيارات التي تمررها إلىp، مثلalign:، تنطبق على الفقرة وعلى النص الذي بداخلها. - يضيف
p.textمقطعًا نصيًا (run). وحدةsize:هي النقطة. - يبني
word.renderحزمة.docxويعيد كائنStringIO، وتحتوي قيمته.stringعلى بايتات الملف.
require "docxi"
word = Docxi::Document.new
document = word.document
document.p { |p| p.text "Quarterly summary", size: 16, bold: true }
document.p do |p|
p.text "Revenue grew ", space: true
p.text "12%", bold: true, color: "007A33"
p.text " compared with last quarter.", space: true
end
document.p(ul: true) { |p| p.text "New customers: 48" }
document.p(ul: true) { |p| p.text "Customers lost: 3" }
document.table(columns_width: [200, 100]) do |table|
table.tr(fill: "D9D9D9", bold: true) do |tr|
tr.tc { |tc| tc.text "Region" }
tr.tc { |tc| tc.text "Sales" }
end
table.tr do |tr|
tr.tc { |tc| tc.text "North" }
tr.tc { |tc| tc.text "$41,000", align: "right" }
end
end
File.binwrite("summary.docx", word.render.string)أمران يجب الانتباه إليهما:
- يحافظ الخيار
space: trueعلى المسافة في بداية المقطع أو نهايته. من دونه يحذف Word المسافة فتلتصق الكلمات ببعضها. - الخيارات المحددة على
trتنطبق على كل خلية في ذلك الصف، ولذلك يظهر صف العناوين كله مظللًا وبخط غامق.
- أمثلة الاستخدام: وصفات كاملة للتقارير والفواتير والخطابات
- الميزات: كل خيارات الفقرات والنصوص والجداول والصور ورؤوس الصفحات وتذييلاتها
- التكامل: إرسال المستند من وحدة تحكم في Rails
- أفضل الممارسات: تجنّب المفاجآت الشائعة قبل حدوثها
docxi wiki · README · Installation · Troubleshooting · Report an issue · MIT License
Start
Build documents
Help
Project
Links
Languages