المكتبة التقنية ←

إنشاء قالب Word ببيانات SQL باستخدام APEX Office Print

English version

My LinkedIn post highlighted APEX Office Print (AOP) as a way to maintain document layouts with familiar Office templates. A small order document makes the workflow concrete. Its data query defines the values, while a Word template places those values on the page.

Define a small data contract

Start in a development application with the AOP plug-in installed and an appropriately licensed AOP service configured. AOP combines structured data and a template on its rendering server. The vendor documents its deployment options and licensing. AOP overview

This illustrative query uses synthetic values from DUAL. It returns a document filename, a data cursor containing the order header, and a nested lines cursor.

select
    'demo-order' as "filename",
    cursor(
        select
            1001 as "order_no",
            'Demo Customer' as "customer_name",
            cursor(
                select 'Planning session' as "description",
                       2 as "quantity", 75 as "unit_price"
                from dual
                union all
                select 'Review session', 1, 50 from dual
            ) as "lines"
        from dual
    ) as "data"
from dual

The quoted aliases preserve the lowercase names used by the template. Keep the query and template field names aligned. The data cursor provides the document's root values, and the nested cursor supplies the repeating records. SQL structure

Put the matching tags in Word

Create a DOCX file and add the following tags as ordinary document text. Apply Word styles to the heading and paragraphs around them.

Order {order_no}
Customer {customer_name}

{#lines}
{description} | Quantity {quantity} | Unit price {unit_price}
{/lines}

The loop repeats the enclosed content for each line. Keep tag spelling and case consistent with the SQL aliases. Once this simple paragraph version works, adapt the layout to a table using the vendor's DOCX guidance. DOCX template tags

Connect and review the output

Upload the template as an APEX Static Application File. In the AOP Dynamic Action, select that template source, enter its filename, choose SQL as the data type, and supply the query. Choose the required output format, such as PDF, then invoke the action from your print button. Attribute labels can vary with the installed plug-in version. AOP Dynamic Action settings

Check that order 1001 and both lines appear. Test a long description, an empty lines collection, and an Arabic layout before using real data. With application tables, enforce document access and row authorization in the data path. Select the destination service according to the information the document contains.

Keep the template version alongside the data contract. A heading change can stay in the template. Adding a new tag requires a corresponding value in the query and another output review.

Original LinkedIn post

النسخة العربية

بوستي على LinkedIn كان عن APEX Office Print واستخدام قوالب Office المألوفة لصيانة تصميم المستندات. مثال طلب بسيط يوضّح مسار العمل. الاستعلام يحدّد القيم، وقالب Word يوزّعها على الصفحة.

حدّد البيانات المطلوبة للمستند

ابدأ داخل تطبيق تطوير، بعد تثبيت AOP Plug-in وإعداد خدمة AOP بترخيص مناسب. الخدمة تدمج البيانات المنظمة والقالب على خادم إنشاء المستندات. يوضّح توثيق الشركة اختيارات الاستضافة والترخيص. نظرة عامة على AOP

الاستعلام التوضيحي التالي يستخدم قيمًا افتراضية من DUAL. بيرجع اسم الملف، وCursor باسم data لبيانات رأس الطلب، وCursor داخلي باسم lines للبنود.

select
    'demo-order' as "filename",
    cursor(
        select
            1001 as "order_no",
            'Demo Customer' as "customer_name",
            cursor(
                select 'Planning session' as "description",
                       2 as "quantity", 75 as "unit_price"
                from dual
                union all
                select 'Review session', 1, 50 from dual
            ) as "lines"
        from dual
    ) as "data"
from dual

علامات التنصيص حول الأسماء المستعارة تحفظ الحروف الصغيرة المستخدمة في القالب. طابق أسماء الحقول بين الاستعلام والقالب. الـCursor المسمى data يوفّر القيم الأساسية للمستند، والـCursor الداخلي يوفّر السجلات المتكررة. هيكل SQL في AOP

أضف العلامات المطابقة داخل Word

أنشئ ملف DOCX وأضف العلامات التالية كنص عادي داخل المستند. طبّق تنسيقات Word على العنوان والفقرات المحيطة بها.

طلب {order_no}
العميل {customer_name}

{#lines}
{description} | الكمية {quantity} | سعر الوحدة {unit_price}
{/lines}

الحلقة تكرّر المحتوى الموجود بداخلها لكل بند. حافظ على كتابة العلامات وحالة الحروف كما هي في أسماء SQL. بعد نجاح نسخة الفقرات البسيطة، طوّر التصميم إلى جدول بالرجوع لتوثيق قوالب DOCX. علامات قوالب Word

اربط القالب وراجع الناتج

ارفع القالب في Static Application Files داخل APEX. في AOP Dynamic Action اختار مصدر القالب ده، واكتب اسم الملف، وحدّد SQL كنوع البيانات، وأضف الاستعلام. اختار صيغة الناتج المطلوبة، مثل PDF، ثم استدعِ الإجراء من زر الطباعة. أسماء الخصائص قد تختلف حسب إصدار الـPlug-in المثبّت. إعدادات AOP Dynamic Action

تأكد من ظهور الطلب 1001 والبندين. اختبر وصفًا طويلًا، ومجموعة بنود فارغة، وتصميمًا عربيًا قبل استخدام بيانات فعلية. عند ربط جداول التطبيق، طبّق صلاحية الوصول للمستند والصفوف في مسار تجهيز البيانات. اختار الخدمة المستقبلة حسب نوع المعلومات الموجودة في المستند.

احتفظ بإصدار القالب مع تعريف بياناته. تعديل العنوان يتم داخل القالب. إضافة علامة جديدة تحتاج قيمة مقابلة في الاستعلام ومراجعة جديدة للناتج.

البوست الأصلي على LinkedIn