كيفية إدراج تعليق في مستند Word باستخدام C#

في هذا الموضوع ، سنشرح كيفية إدراج التعليق في مستند Word باستخدام C#. تعليق التعليق التوضيحي في برنامج MS Word مثبت على موضع في النص أو منطقة من النص. في نموذج كائن مستند Aspose.Words ، يكون التعليق عقدة على مستوى السطر ولا يمكن أن يكون إلا عنصرًا فرعيًا من الفقرة. سنستخدم نموذج مستند Word للإدخال وإدخال تعليق في بداية DOCX مع بضعة أسطر من كود C#. يمكنك استخدام نفس الأسلوب لإدراج التعليق على أي فقرة في المستند.

خطوات إدراج تعليق في مستند Word باستخدام C#

  1. قم بتثبيت حزمة Aspose.Words for .NET من NuGet.org
  2. أضف مرجعًا إلى Aspose.Words
  3. حدد الترخيص باستخدام طريقة License.SetLicense قبل استيراد المستند
  4. قم باستيراد مستند Word المدخل
  5. تهيئة مثيل فئة DocumentBuilder وتحريك المؤشر إلى بداية المستند
  6. تهيئة مثيل فئة التعليق وإضافة نص التعليق باستخدام الفقرة
  7. أضف تعليقًا إلى الفقرة الأولى من المستند
  8. أخيرًا ، احفظ المستند بتنسيق ملف Word DOCX

في السابق ، بحثنا في كيفية تحويل PDF إلى Word في C# بدون Interop. الآن ، سوف تتعلم كيفية إدراج تعليق في تنسيق الملف DOCX.

رمز لإدراج تعليق في مستند Word باستخدام C#

using Aspose.Words;
using System;
namespace InsertCommentinWord
{
class how_to_insert_comment_into_word_document_using_c_sharp
{
public static void InsertComment(String directorypath)
{
//Set Aspose license before importing document.
Aspose.Words.License AsposeWordsLicense = new Aspose.Words.License();
AsposeWordsLicense.SetLicense(directorypath + @"Aspose.Words.lic");
//Import the Document into Aspose.Words DOM.
Document doc = new Document(directorypath + "input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
//Move the cursor to the beginning of the document.
builder.MoveToDocumentStart();
//Insert comment to first paragraph of document.
Comment comment = new Comment(doc, "Aspose.Words", "AW", DateTime.Today);
builder.CurrentParagraph.AppendChild(comment);
comment.Paragraphs.Add(new Paragraph(doc));
comment.FirstParagraph.Runs.Add(new Run(doc, "Comment text."));
//Save the Document
doc.Save(directorypath + @"output.docx", SaveFormat.Docx);
}
}
}

إدخال تعليق في مستند Word باستخدام رمز C# أعلاه لا يحتاج إلى تثبيت MS Office ويمكن استخدامه حيث تم تثبيت .NET. يقوم مثال التعليمات البرمجية هذا بإدراج التعليق في نهاية الفقرة الأولى من المستند.

 عربي