كيفية تطبيق المنطق المخصص على المناطق غير المدمجة
هناك بعض المواقف التي لا تكون فيها إزالة المناطق غير المدمجة تماما من المستند أثناء Mail Merge مرغوبة أو تؤدي إلى ظهور المستند غير مكتمل. يمكن أن يحدث هذا عندما يتم عرض عدم وجود بيانات الإدخال للمستخدم في شكل رسالة بدلا من إزالة المنطقة بالكامل.
هناك أيضا أوقات لا تكون فيها إزالة المنطقة غير المستخدمة من تلقاء نفسها كافية، على سبيل المثال، إذا كانت المنطقة مسبوقة بعنوان أو كانت المنطقة مضمنة في جدول. إذا كانت هذه المنطقة غير مستخدمة، فسيظل العنوان والجدول بعد إزالة المنطقة التي ستبدو في غير مكانها في المستند.
توفر هذه المقالة حلا لتحديد كيفية التعامل مع المناطق غير المستخدمة في المستند يدويا. يتم توفير الرمز الأساسي لهذه الوظيفة ويمكن إعادة استخدامه بسهولة في مشروع آخر.
يتم تعريف المنطق الذي سيتم تطبيقه على كل منطقة داخل فئة تنفذ IFieldMergingCallback واجهة. بنفس الطريقة، يمكن إعداد معالج Mail Merge للتحكم في كيفية دمج كل حقل، ويمكن إعداد هذا المعالج لتنفيذ إجراءات في كل حقل في منطقة غير مستخدمة أو في المنطقة ككل. ضمن هذا المعالج، يمكنك تعيين التعليمات البرمجية لتغيير نص منطقة أو إزالة العقد أو الصفوف والخلايا الفارغة وما إلى ذلك.
في هذه العينة، سنستخدم المستند المعروض أدناه. يحتوي على مناطق متداخلة ومنطقة موجودة داخل جدول.
كدليل توضيحي سريع، يمكننا تنفيذ قاعدة بيانات عينة على نموذج المستند مع تمكين علامة MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS. ستقوم هذه الخاصية تلقائيا بإزالة المناطق غير المدمجة من المستند أثناء mail merge.
يتضمن مصدر البيانات سجلين لمنطقة StoreDetails ولكن عن قصد يحتوي على أي بيانات لمناطق ContactDetails الفرعية لأحد السجلات. علاوة على ذلك، لا تحتوي المنطقة Suppliers على أي صفوف بيانات أيضا. سيؤدي هذا إلى بقاء المناطق غير المستخدمة في المستند. النتيجة بعد دمج المستند مع مصدر البيانات هذا أدناه.
كما هو مذكور في الصورة، يمكنك أن ترى أن منطقة ContactDetails للسجل الثاني و Suppliers تمت إزالتها تلقائيا بواسطة محرك Mail Merge حيث لا تحتوي على بيانات. ومع ذلك، هناك بعض المشكلات التي تجعل مستند الإخراج هذا يبدو غير مكتمل:
- لا تزال المنطقة ContactDetails تترك فقرة تحتوي على نص “تفاصيل الاتصال”.
- في نفس الحالة، لا يوجد ما يشير إلى عدم وجود أرقام هواتف، فقط مساحة فارغة قد تؤدي إلى الارتباك.
- يظل الجدول والعنوان المتعلقان بالمنطقة Suppliers أيضا بعد إزالة المنطقة الموجودة داخل الجدول.
توضح التقنية المتوفرة في هذه المقالة كيفية تطبيق المنطق المخصص على كل منطقة غير مدمجة لتجنب هذه المشكلات.
الحل
لتطبيق المنطق يدويا على كل منطقة غير مستخدمة في المستند، نستفيد من الميزات المتوفرة بالفعل في Aspose.Words.
يوفر المحرك Mail Merge خاصية لإزالة المناطق غير المستخدمة من خلال علامة MailMergeCleanupOptions.RemoveUnusedRegions. يمكن تعطيل هذا بحيث يتم ترك هذه المناطق دون مساس خلال mail merge. يتيح لنا ذلك ترك المناطق غير المدمجة في المستند والتعامل معها يدويا بأنفسنا بدلا من ذلك.
يمكننا بعد ذلك الاستفادة من خاصية MailMerge.FieldMergingCallback كوسيلة لتطبيق منطقنا المخصص على هذه المناطق غير المدمجة خلال Mail Merge من خلال استخدام فئة معالج تنفيذ واجهة IFieldMergingCallback.
هذا الرمز داخل فئة المعالج هو الفئة الوحيدة التي ستحتاج إلى تعديلها للتحكم في المنطق المطبق على المناطق غير المدمجة. يمكن إعادة استخدام الكود الآخر في هذه العينة دون تعديل في أي مشروع.
يوضح هذا المشروع عينة هذه التقنية. يتضمن الخطوات التالية:
- نفذ Mail Merge على المستند باستخدام مصدر البيانات الخاص بك. تم تعطيل علامة MailMergeCleanupOptions.RemoveUnusedRegions في الوقت الحالي نريد أن تظل المناطق حتى نتمكن من التعامل معها يدويا. سيتم ترك أي مناطق بدون بيانات غير مدمجة في المستند.
- استدعاء طريقة ExecuteCustomLogicOnEmptyRegions. يتم توفير هذه الطريقة في هذه العينة. يقوم بتنفيذ الإجراءات التي تسمح باستدعاء المعالج المحدد لكل منطقة غير مدمجة. هذه الطريقة قابلة لإعادة الاستخدام ويمكن نسخها دون تغيير إلى أي مشروع يتطلب ذلك (جنبا إلى جنب مع أي أساليب تابعة).تنفذ هذه الطريقة الخطوات التالية:
- تعيين المعالج المحدد من قبل المستخدم إلى الخاصية MailMerge.FieldMergingCallback.
- يستدعي طريقة CreateDataSourceFromDocumentRegions التي تقبل أسماء المناطق Document و ArrayList التي تحتوي على المستخدم. ستقوم هذه الطريقة بإنشاء مصدر بيانات وهمي يحتوي على جداول لكل منطقة غير مدمجة في المستند.
- ينفذ Mail Merge على المستند باستخدام مصدر البيانات الوهمي. عندما يتم تنفيذ Mail Merge باستخدام مصدر البيانات هذا، فإنه يسمح باستدعاء المعالج المحدد من قبل المستخدم لكل منطقة إلغاء دمج والمنطق المخصص المطبق
الرمز
تم العثور على تنفيذ طريقة ExecuteCustomLogicOnEmptyRegions أدناه. تقبل هذه الطريقة عدة معلمات:
- الكائن Document الذي يحتوي على مناطق غير مدمجة يتم التعامل معها بواسطة المعالج الذي تم تمريره.
- فئة المعالج التي تحدد المنطق لتطبيقه على المناطق غير المدمجة. يجب على هذا المعالج تنفيذ IFieldMergingCallback واجهة.
- من خلال استخدام الحمل الزائد المناسب، يمكن للطريقة أيضا قبول معلمة ثالثة – قائمة بأسماء المناطق كسلاسل. إذا تم تحديد ذلك، فسيتم التعامل يدويا مع أسماء المناطق المتبقية في المستند المحدد في القائمة فقط. لن يتم استدعاء المناطق الأخرى التي تمت مواجهتها بواسطة المعالج وإزالتها تلقائيا. عندما يتم تحديد الحمل الزائد مع معلمتين فقط، يتم تضمين كل منطقة متبقية في المستند بالطريقة التي سيتم التعامل معها يدويا.
مثال
يوضح كيفية تنفيذ المنطق المخصص في المناطق غير المستخدمة باستخدام المعالج المحدد.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
/** | |
* Applies logic defined in the passed handler class to all unused regions | |
* in the document. This allows to manually control how unused regions are | |
* handled in the document. | |
* | |
* @param doc The document containing unused regions. | |
* @param handler The handler which implements the IFieldMergingCallback | |
* interface and defines the logic to be applied to each unmerged | |
* region. | |
*/ | |
public static void executeCustomLogicOnEmptyRegions(Document doc, IFieldMergingCallback handler) throws Exception { | |
executeCustomLogicOnEmptyRegions(doc, handler, null); // Pass null to handle all regions found in the document. | |
} | |
/** | |
* Applies logic defined in the passed handler class to specific unused | |
* regions in the document as defined in regionsList. This allows to | |
* manually control how unused regions are handled in the document. | |
* | |
* @param doc The document containing unused regions. | |
* @param handler The handler which implements the IFieldMergingCallback | |
* interface and defines the logic to be applied to each unmerged | |
* region. | |
* @param regionsList A list of strings corresponding to the region names that are | |
* to be handled by the supplied handler class. Other regions | |
* encountered will not be handled and are removed automatically. | |
*/ | |
public static void executeCustomLogicOnEmptyRegions(Document doc, IFieldMergingCallback handler, ArrayList regionsList) throws Exception { | |
// Certain regions can be skipped from applying logic to by not adding the table name inside the CreateEmptyDataSource method. | |
// Enable this cleanup option so any regions which are not handled by the user's logic are removed automatically. | |
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS); | |
// Set the user's handler which is called for each unmerged region. | |
doc.getMailMerge().setFieldMergingCallback(handler); | |
// Execute mail merge using the dummy dataset. The dummy data source contains the table names of | |
// each unmerged region in the document (excluding ones that the user may have specified to be skipped). This will allow the handler | |
// to be called for each field in the unmerged regions. | |
doc.getMailMerge().executeWithRegions(createDataSourceFromDocumentRegions(doc, regionsList)); | |
} | |
/** | |
* A helper method that creates an empty Java disconnected ResultSet with | |
* the specified columns. | |
*/ | |
private static ResultSet createCachedRowSet(String[] columnNames) throws Exception { | |
RowSetMetaDataImpl metaData = new RowSetMetaDataImpl(); | |
metaData.setColumnCount(columnNames.length); | |
for (int i = 0; i < columnNames.length; i++) { | |
metaData.setColumnName(i + 1, columnNames[i]); | |
metaData.setColumnType(i + 1, java.sql.Types.VARCHAR); | |
} | |
CachedRowSet rowSet = RowSetProvider.newFactory().createCachedRowSet(); | |
; | |
rowSet.setMetaData(metaData); | |
return rowSet; | |
} | |
/** | |
* A helper method that adds a new row with the specified values to a | |
* disconnected ResultSet. | |
*/ | |
private static void addRow(ResultSet resultSet, String[] values) throws Exception { | |
resultSet.moveToInsertRow(); | |
for (int i = 0; i < values.length; i++) | |
resultSet.updateString(i + 1, values[i]); | |
resultSet.insertRow(); | |
// This "dance" is needed to add rows to the end of the result set properly. | |
// If I do something else then rows are either added at the front or the result | |
// set throws an exception about a deleted row during mail merge. | |
resultSet.moveToCurrentRow(); | |
resultSet.last(); | |
} |
مثال
يحدد الطريقة المستخدمة للتعامل مع المناطق غير المدمجة يدويا.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
/** | |
* Returns a DataSet object containing a DataTable for the unmerged regions | |
* in the specified document. If regionsList is null all regions found | |
* within the document are included. If an ArrayList instance is present the | |
* only the regions specified in the list that are found in the document are | |
* added. | |
*/ | |
private static DataSet createDataSourceFromDocumentRegions(Document doc, ArrayList regionsList) throws Exception { | |
final String TABLE_START_MARKER = "TableStart:"; | |
DataSet dataSet = new DataSet(); | |
String tableName = null; | |
for (String fieldName : doc.getMailMerge().getFieldNames()) { | |
if (fieldName.contains(TABLE_START_MARKER)) { | |
tableName = fieldName.substring(TABLE_START_MARKER.length()); | |
} else if (tableName != null) { | |
// Only add the table as a new DataTable if it doesn't already exists in the DataSet. | |
if (dataSet.getTables().get(tableName) == null) { | |
ResultSet resultSet = createCachedRowSet(new String[]{fieldName}); | |
// We only need to add the first field for the handler to be called for the fields in the region. | |
if (regionsList == null || regionsList.contains(tableName)) { | |
addRow(resultSet, new String[]{"FirstField"}); | |
} | |
dataSet.getTables().add(new DataTable(resultSet, tableName)); | |
} | |
tableName = null; | |
} | |
} | |
return dataSet; | |
} |
تتضمن هذه الطريقة العثور على جميع المناطق غير المدمجة في المستند. يتم تحقيق ذلك باستخدام طريقة MailMerge.GetFieldNames. تقوم هذه الطريقة بإرجاع كافة حقول الدمج في المستند، بما في ذلك علامات بداية المنطقة ونهايتها (ممثلة بحقول الدمج بالبادئة TableStart أو TableEnd).
عند مواجهة حقل دمج TableStart
، تتم إضافة هذا كـ DataTable جديد إلى DataSet. نظرا لأن المنطقة قد تظهر أكثر من مرة (على سبيل المثال لأنها منطقة متداخلة حيث تم دمج المنطقة الأصلية مع سجلات متعددة)، يتم إنشاء الجدول وإضافته فقط إذا لم يكن موجودا بالفعل في DataSet.
عند العثور على بداية منطقة مناسبة وإضافتها إلى قاعدة البيانات، تتم إضافة الحقل التالي (الذي يتوافق مع الحقل الأول في المنطقة) إلى DataTable. يجب إضافة الحقل الأول فقط لكل حقل في المنطقة ليتم دمجه وتمريره إلى المعالج.
قمنا أيضا بتعيين قيمة الحقل للحقل الأول على “FirstField” لتسهيل تطبيق المنطق على الحقول الأولى أو الحقول الأخرى في المنطقة. من خلال تضمين هذا، فهذا يعني أنه ليس من الضروري ترميز اسم الحقل الأول أو تنفيذ رمز إضافي للتحقق مما إذا كان الحقل الحالي هو الأول في رمز المعالج.
يوضح الرمز أدناه كيفية عمل هذا النظام. يتم إعادة دمج المستند الموضح في بداية هذه المقالة بنفس مصدر البيانات ولكن هذه المرة، يتم التعامل مع المناطق غير المستخدمة بواسطة رمز مخصص.
مثال
يوضح كيفية التعامل مع المناطق غير المدمجة بعد Mail Merge برمز محدد من قبل المستخدم.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open the document. | |
Document doc = new Document(dataDir + "TestFile.doc"); | |
// Create a data source which has some data missing. | |
// This will result in some regions that are merged and some that remain after executing mail merge. | |
DataSet data = getDataSource(); | |
// Make sure that we have not set the removal of any unused regions as we will handle them manually. | |
// We achieve this by removing the RemoveUnusedRegions flag from the cleanup options by using the AND and NOT bitwise operators. | |
doc.getMailMerge().setCleanupOptions(doc.getMailMerge().getCleanupOptions() & ~MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS); | |
// Execute mail merge. Some regions will be merged with data, others left unmerged. | |
doc.getMailMerge().executeWithRegions(data); | |
// The regions which contained data now would of been merged. Any regions which had no data and were | |
// not merged will still remain in the document. | |
Document mergedDoc = doc.deepClone(); //ExSkip | |
// Apply logic to each unused region left in the document using the logic set out in the handler. | |
// The handler class must implement the IFieldMergingCallback interface. | |
executeCustomLogicOnEmptyRegions(doc, new EmptyRegionsHandler()); | |
// Save the output document to disk. | |
doc.save(dataDir + "TestFile.CustomLogicEmptyRegions1 Out.doc"); |
ينفذ الكود عمليات مختلفة بناء على اسم المنطقة المسترجعة باستخدام FieldMergingArgs.TableName خاصية. لاحظ أنه بناء على المستند والمناطق الخاصة بك، يمكنك ترميز المعالج لتشغيل المنطق الذي يعتمد على كل منطقة أو رمز ينطبق على كل منطقة غير مدمجة في المستند أو مزيج من الاثنين معا.
يتضمن منطق منطقة ContactDetails تغيير نص كل حقل في منطقة ContactDetails برسالة مناسبة تفيد بعدم وجود بيانات. تتم مطابقة أسماء كل حقل داخل المعالج باستخدام خاصية FieldMergingArgs.FieldName.
يتم تطبيق عملية مماثلة على المنطقة Suppliers مع إضافة رمز إضافي للتعامل مع الجدول الذي يحتوي على المنطقة. سيتحقق الرمز مما إذا كانت المنطقة مضمنة في جدول (حيث ربما تمت إزالتها بالفعل). إذا كان الأمر كذلك، فسيؤدي ذلك إلى إزالة الجدول بأكمله من المستند بالإضافة إلى الفقرة التي تسبقه طالما تم تنسيقه بنمط عنوان على سبيل المثال “Heading 1”.
مثال
يوضح كيفية تعريف المنطق المخصص في معالج ينفذ IFieldMergingCallback الذي يتم تنفيذه للمناطق غير المدمجة في المستند.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
public static class EmptyRegionsHandler implements IFieldMergingCallback { | |
/** | |
* Called for each field belonging to an unmerged region in the | |
* document. | |
*/ | |
public void fieldMerging(FieldMergingArgs args) throws Exception { | |
// Change the text of each field of the ContactDetails region individually. | |
if ("ContactDetails".equals(args.getTableName())) { | |
// Set the text of the field based off the field name. | |
if ("Name".equals(args.getFieldName())) | |
args.setText("(No details found)"); | |
else if ("Number".equals(args.getFieldName())) | |
args.setText("(N/A)"); | |
} | |
// Remove the entire table of the Suppliers region. Also check if the previous paragraph | |
// before the table is a heading paragraph and if so remove that too. | |
if ("Suppliers".equals(args.getTableName())) { | |
Table table = (Table) args.getField().getStart().getAncestor(NodeType.TABLE); | |
// Check if the table has been removed from the document already. | |
if (table.getParentNode() != null) { | |
// Try to find the paragraph which precedes the table before the table is removed from the document. | |
if (table.getPreviousSibling() != null && table.getPreviousSibling().getNodeType() == NodeType.PARAGRAPH) { | |
Paragraph previousPara = (Paragraph) table.getPreviousSibling(); | |
if (isHeadingParagraph(previousPara)) | |
previousPara.remove(); | |
} | |
table.remove(); | |
} | |
} | |
} | |
/** | |
* Returns true if the paragraph uses any Heading style e.g Heading 1 to | |
* Heading 9 | |
*/ | |
private boolean isHeadingParagraph(Paragraph para) throws Exception { | |
return (para.getParagraphFormat().getStyleIdentifier() >= StyleIdentifier.HEADING_1 && para.getParagraphFormat().getStyleIdentifier() <= StyleIdentifier.HEADING_9); | |
} | |
public void imageFieldMerging(ImageFieldMergingArgs args) throws Exception { | |
// Do Nothing | |
} | |
} |
تظهر نتيجة الكود أعلاه أدناه. يتم استبدال الحقول غير المدمجة داخل المنطقة الأولى بنص إعلامي وتسمح إزالة الجدول والعنوان للمستند بأن يبدو مكتملا.
يمكن أيضا تشغيل الرمز الذي يزيل الجدول الأصل على كل منطقة غير مستخدمة بدلا من منطقة معينة فقط عن طريق إزالة التحقق من اسم الجدول. في هذه الحالة، إذا لم يتم دمج أي منطقة داخل جدول مع أي بيانات، فسيتم إزالة كل من المنطقة وجدول الحاوية تلقائيا أيضا.
يمكننا إدراج رمز مختلف في المعالج للتحكم في كيفية التعامل مع المناطق غير المدمجة. سيؤدي استخدام الكود أدناه في المعالج بدلا من ذلك إلى تغيير النص في الفقرة الأولى من المنطقة إلى رسالة مفيدة أثناء إزالة أي فقرات لاحقة في المنطقة. تتم إزالة هذه الفقرات الأخرى لأنها ستبقى في المنطقة بعد دمج رسالتنا.
يتم دمج النص البديل في الحقل الأول عن طريق تعيين النص المحدد في الخاصية FieldMergingArgs.Text. يتم دمج النص من هذه الخاصية في الحقل بواسطة محرك Mail Merge.
يطبق الرمز هذا على الحقل الأول فقط في المنطقة عن طريق التحقق من FieldMergingArgs.FieldValue خاصية. يتم تمييز قيمة الحقل للحقل الأول في المنطقة بـ" FirstField". هذا يجعل هذا النوع من المنطق أسهل في التنفيذ على العديد من المناطق حيث لا يلزم وجود رمز إضافي.
مثال
يوضح كيفية استبدال منطقة غير مستخدمة برسالة وإزالة فقرات إضافية.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Store the parent paragraph of the current field for easy access. | |
Paragraph parentParagraph = args.getField().getStart().getParentParagraph(); | |
// Define the logic to be used when the ContactDetails region is encountered. | |
// The region is removed and replaced with a single line of text stating that there are no records. | |
if ("ContactDetails".equals(args.getTableName())) { | |
// Called for the first field encountered in a region. This can be used to execute logic on the first field | |
// in the region without needing to hard code the field name. Often the base logic is applied to the first field and | |
// different logic for other fields. The rest of the fields in the region will have a null FieldValue. | |
if ("FirstField".equals(args.getFieldValue())) { | |
FindReplaceOptions opts = new FindReplaceOptions(); | |
opts.setMatchCase(false); | |
opts.setFindWholeWordsOnly(false); | |
// Remove the "Name:" tag from the start of the paragraph | |
parentParagraph.getRange().replace("Name:", "", opts); | |
// Set the text of the first field to display a message stating that there are no records. | |
args.setText("No records to display"); | |
} else { | |
// We have already inserted our message in the paragraph belonging to the first field. The other paragraphs in the region | |
// will still remain so we want to remove these. A check is added to ensure that the paragraph has not already been removed. | |
// which may happen if more than one field is included in a paragraph. | |
if (parentParagraph.getParentNode() != null) | |
parentParagraph.remove(); | |
} | |
} |
يظهر المستند الناتج بعد تنفيذ الكود أعلاه أدناه. يتم استبدال المنطقة غير المستخدمة برسالة تفيد بعدم وجود سجلات لعرضها.
كمثال آخر، يمكننا إدراج الرمز أدناه بدلا من الرمز الذي يتعامل في الأصل مع SuppliersRegion. سيؤدي هذا إلى عرض رسالة داخل الجدول ودمج الخلايا بدلا من إزالة الجدول من المستند. نظرا لأن المنطقة موجودة داخل جدول به خلايا متعددة، يبدو من الأجمل دمج خلايا الجدول معا وتركيز الرسالة.
مثال
يوضح كيفية دمج جميع الخلايا الأصلية لمنطقة غير مستخدمة وعرض رسالة داخل الجدول.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Replace the unused region in the table with a "no records" message and merge all cells into one. | |
if ("Suppliers".equals(args.getTableName())) { | |
if ("FirstField".equals(args.getFieldValue())) { | |
// We will use the first paragraph to display our message. Make it centered within the table. The other fields in other cells | |
// within the table will be merged and won't be displayed so we don't need to do anything else with them. | |
parentParagraph.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER); | |
args.setText("No records to display"); | |
} | |
// Merge the cells of the table together. | |
Cell cell = (Cell) parentParagraph.getAncestor(NodeType.CELL); | |
if (cell != null) { | |
if (cell.isFirstCell()) | |
cell.getCellFormat().setHorizontalMerge(CellMerge.FIRST); // If this cell is the first cell in the table then the merge is started using "CellMerge.First". | |
else | |
cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS); // Otherwise the merge is continued using "CellMerge.Previous". | |
} | |
} |
يظهر المستند الناتج بعد تنفيذ الكود أعلاه أدناه.
أخيرا، يمكننا استدعاء طريقة ExecuteCustomLogicOnEmptyRegions وتحديد أسماء الجداول التي يجب معالجتها ضمن طريقة المعالج الخاصة بنا، مع تحديد الآخرين المراد إزالتهم تلقائيا.
مثال
يوضح كيفية تحديد المنطقة ContactDetails
فقط التي سيتم التعامل معها من خلال فئة المعالج.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
ArrayList<String> regions = new ArrayList<String>(); | |
regions.add("ContactDetails"); | |
executeCustomLogicOnEmptyRegions(doc, new EmptyRegionsHandler(), regions); |
سيؤدي استدعاء هذا التحميل الزائد باستخدام ArrayList المحدد إلى إنشاء مصدر البيانات الذي يحتوي فقط على صفوف البيانات للمناطق المحددة. لن يتم التعامل مع مناطق أخرى غير منطقة ContactDetails
وستتم إزالتها تلقائيا بواسطة محرك Mail Merge بدلا من ذلك. تظهر نتيجة المكالمة أعلاه باستخدام الرمز في معالجنا الأصلي أدناه.