يلخص هذا البرنامج التعليمي البسيط ** كيفية إضافة تعليقات في Word باستخدام Java **. يمكنك تعيين خصائص متقدمة مختلفة للتعليقات المتوفرة لملف Word وحفظ الملف مرة أخرى باسم DOCX. فيما يلي خطوات * كيفية إدراج تعليق في Word باستخدام Java *.
خطوات إضافة تعليقات في Word باستخدام Java
- أضف Aspose.Words من مستودع Maven لإدراج التعليقات
- افتح ملف Word المصدر باستخدام كائن فئة Document
- حرك المؤشر إلى الفقرة الهدف
- إدراج تعليق في فقرة مستند Word باستخدام Java *
- احفظ الملف بعد إضافة التعليقات
باستخدام هذه الخطوات ، نفتح مستند Word ونبدأ في تهيئة الكائن DocumentBuilder الذي يمكن استخدامه للوصول إلى عناصر مختلفة من ملف Word مثل فقراته. يمكننا تحريك المؤشر إلى أي عنصر يحاكي حركة المؤشر في برنامج MS Word يدويًا. أخيرًا نضيف التعليقات ونحفظ ملف Word.
رمز لإضافة تعليقات إلى مستند Word باستخدام Java
import com.aspose.words.License; | |
import com.aspose.words.Document; | |
import com.aspose.words.DocumentBuilder; | |
import com.aspose.words.Comment; | |
import com.aspose.words.Paragraph; | |
import com.aspose.words.Run; | |
import java.util.Date; | |
public class HowToAddCommentsInWordUsingJava | |
{ | |
public static void main(String[] args) throws Exception { //main function for AddImageInWord class | |
// Initialize a license to avoid trial version watermark in the output Word file after adding image | |
License license = new License(); | |
license.setLicense("Aspose.Words.lic"); | |
// Load the Word document where comments are to be added | |
Document DocumentForComment = new Document("input.docx"); | |
DocumentBuilder builder = new DocumentBuilder(DocumentForComment); | |
// Move the cursor to the beginning of the document for adding comments | |
builder.moveToDocumentStart(); | |
// Insert comment to first paragraph of document by providing Author, Initial, time and comment text | |
Comment comment = new Comment(DocumentForComment, "Aspose.Words", "AW", new Date()); | |
builder.getCurrentParagraph().appendChild(comment); | |
comment.getParagraphs().add(new Paragraph(DocumentForComment)); | |
comment.getFirstParagraph().getRuns().add(new Run(DocumentForComment, "Comment text.")); | |
// Save the Document with comments | |
DocumentForComment.save("OutputDocumentWithComments.docx"); | |
} | |
} |
في كود Java هذا ، استخدمنا كائن فئة Comment الذي يحتوي على جميع الخصائص المطلوبة لتكوين تعليق في مستند Word. نقدم اسم المؤلف ، والحرف الأول من اسم المستخدم ، ووقت التعليقات ثم أخيرًا نضبط نص التعليقات.
في هذا البرنامج التعليمي خطوة بخطوة ، فتحنا ملفًا موجودًا وأضفنا تعليقات إليه. إذا كنت تريد معرفة المزيد من الميزات مثل إضافة صف إلى جدول ، فراجع المقالة على كيفية إضافة صف إلى جدول في Word باستخدام Java. لاحظ أنه لا يلزم وجود MS Word أو Interop على النظام لتشغيل الكود أعلاه.