اجعل DOCX باستخدام مكتبة Python via .NET

تتيح مكتبتنا Python القوية للمطورين إنشاء DOCX برمجيًا في بضع خطوات فقط

يمكن للمطورين Python via .NET إنشاء DOCX بسهولة باستخدام واجهة برمجة تطبيقات منتجنا الفعالة فقط. هذا يعني أن الحل الذي نقدمه سيزود المبرمجين بكل ما يحتاجونه للإنشاء DOCX في Python.

اعرض مقتطف الشفرة

جعل DOCX في Python برمجيًا

مع مطوري مكتبة Python لدينا يمكنهم بسهولة إنشاء DOCX من البداية. للقيام بذلك، يحتاج مطورو Python via .NET إلى تنفيذ بضع خطوات فقط:

  1. أضف اسم الملف
  2. ابدأ في إنشاء مستند DOCX باستخدام Python
  3. احفظ ملف DOCX الناتج

تجدر الإشارة إلى أنه من المفترض أن يحتوي المستند الفارغ من الناحية الفنية على فقرة واحدة، لذلك عندما تقوم بإنشاء مستند DOCX برمجيًا، ستحصل بالضبط على هيكل المستند الأساسي هذا.

لاحظ أنه يمكنك إضافة محتوى على الفور إلى ملف DOCX تم إنشاؤه حديثًا. وبالتالي، لن تحصل على مستند فارغ فحسب، بل مستند يحتوي على المحتوى الضروري. لمزيد من المعلومات حول كيفية تحرير مستند، راجع صفحة التحرير.

قم بإنشاء DOCX في Python

تتيح لك مكتبة Python via .NET هذه إنشاء مستندات DOCX برمجيًا. جرب وظائفنا القوية واطلع على كيفية إنشاء DOCX في بعض التنسيقات باستخدام المثال التالي:

إنشاء DOCX جديد باستخدام Python
حدد التنسيق الهدف من القائمة
قم بتشغيل الكود
import aspose.words as aw

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

font = builder.font
font.name = "Courier New"
font.color = drawing.Color.blue
font.size = 36
font.highlight_color = drawing.Color.yellow

builder.write("Morbi enim nunc faucibus a.")

doc.Save("Output.docx")
import aspose.words as aw doc = aw.Document() builder = aw.DocumentBuilder(doc) firstRun = aw.Run(doc, "Proin eros metus, sagittis sed. ") secondRun = aw.Run(doc, "Morbi enim nunc faucibus a.") doc.first_section.body.first_paragraph.append_child(firstRun) doc.first_section.body.first_paragraph.append_child(secondRun) builder.move_to(secondRun) builder.start_bookmark("Aspose bookmark") # إذا كانت NextSibling فارغة، فمن المرجح أن يكون هذا هو Run الأخير في الفقرة. if (secondRun.next_sibling != None): builder.move_to(secondRun.next_sibling) else: builder.move_to(secondRun.parent_paragraph) builder.end_bookmark("Aspose bookmark") doc.Save("Output.docx") import aspose.words as aw doc = aw.Document() builder = aw.DocumentBuilder(doc) firstRun = aw.Run(doc, "Proin eros metus, sagittis sed. ") secondRun = aw.Run(doc, "Morbi enim nunc faucibus a.") doc.first_section.body.first_paragraph.append_child(firstRun) doc.first_section.body.first_paragraph.append_child(secondRun) builder.move_to(secondRun) builder.start_bookmark("Aspose bookmark") # إذا كانت NextSibling فارغة، فمن المرجح أن يكون هذا هو Run الأخير في الفقرة. if (secondRun.next_sibling != None): builder.move_to(secondRun.next_sibling) else: builder.move_to(secondRun.parent_paragraph) builder.end_bookmark("Aspose bookmark") save_options = aw.saving.PdfSaveOptions() save_options.outline_options.bookmarks_outline_levels.add("Aspose bookmark", 1); doc.Save("Output.docx", save_options);
import aspose.words as aw

doc = aw.Document()

run = aw.Run(doc, "Proin eros metus, sagittis sed.")
para = doc.first_section.body.first_paragraph
para.append_child(run)

comment = aw.Comment(doc)
comment.author = "John Doe"
comment.initial = "JD"
comment.date_time = datetime.now()
comment.set_text("Quisque fringilla leo.")

commentRangeStart = aw.CommentRangeStart(doc, comment.id)
commentRangeEnd = aw.CommentRangeEnd(doc, comment.id)

run.parent_node.insert_before(commentRangeStart, run)
run.parent_node.insert_after(commentRangeEnd, run)
commentRangeEnd.parent_node.insert_after(comment, commentRangeEnd)

comment.add_reply("Jane Doe", "JD", datetime.now(), "Pellentesque vel sapien justo.")

doc.save("Output.docx")
import aspose.words as aw doc = aw.Document() builder = aw.DocumentBuilder(doc) firstRun = aw.Run(doc, "Proin eros metus, sagittis sed. ") secondRun = aw.Run(doc, "Morbi enim nunc faucibus a.") doc.first_section.body.first_paragraph.append_child(firstRun) doc.first_section.body.first_paragraph.append_child(secondRun) builder.move_to(secondRun) builder.start_bookmark("Aspose bookmark") # إذا كانت NextSibling فارغة، فمن المرجح أن يكون هذا هو Run الأخير في الفقرة. if (secondRun.next_sibling != None): builder.move_to(secondRun.next_sibling) else: builder.move_to(secondRun.parent_paragraph) builder.end_bookmark("Aspose bookmark") doc.Save("Output.docx") import aspose.words as aw doc = aw.Document() builder = aw.DocumentBuilder(doc) firstRun = aw.Run(doc, "Proin eros metus, sagittis sed. ") secondRun = aw.Run(doc, "Morbi enim nunc faucibus a.") doc.first_section.body.first_paragraph.append_child(firstRun) doc.first_section.body.first_paragraph.append_child(secondRun) builder.move_to(secondRun) builder.start_bookmark("Aspose bookmark") # إذا كانت NextSibling فارغة، فمن المرجح أن يكون هذا هو Run الأخير في الفقرة. if (secondRun.next_sibling != None): builder.move_to(secondRun.next_sibling) else: builder.move_to(secondRun.parent_paragraph) builder.end_bookmark("Aspose bookmark") save_options = aw.saving.PdfSaveOptions() save_options.outline_options.bookmarks_outline_levels.add("Aspose bookmark", 1); doc.Save("Output.docx", save_options);
import aspose.words as aw

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

firstRun = aw.Run(doc, "Proin eros metus, sagittis sed. ")
secondRun = aw.Run(doc, "Morbi enim nunc faucibus a.")
doc.first_section.body.first_paragraph.append_child(firstRun)
doc.first_section.body.first_paragraph.append_child(secondRun)

builder.move_to(secondRun)
builder.start_bookmark("Aspose bookmark")
# إذا كانت NextSibling فارغة، فمن المرجح أن يكون هذا هو Run الأخير في الفقرة.
if (secondRun.next_sibling != None):
    builder.move_to(secondRun.next_sibling)
else:
    builder.move_to(secondRun.parent_paragraph)
builder.end_bookmark("Aspose bookmark")

doc.Save("Output.docx")
import aspose.words as aw doc = aw.Document() builder = aw.DocumentBuilder(doc) firstRun = aw.Run(doc, "Proin eros metus, sagittis sed. ") secondRun = aw.Run(doc, "Morbi enim nunc faucibus a.") doc.first_section.body.first_paragraph.append_child(firstRun) doc.first_section.body.first_paragraph.append_child(secondRun) builder.move_to(secondRun) builder.start_bookmark("Aspose bookmark") # إذا كانت NextSibling فارغة، فمن المرجح أن يكون هذا هو Run الأخير في الفقرة. if (secondRun.next_sibling != None): builder.move_to(secondRun.next_sibling) else: builder.move_to(secondRun.parent_paragraph) builder.end_bookmark("Aspose bookmark") doc.Save("Output.docx") import aspose.words as aw doc = aw.Document() builder = aw.DocumentBuilder(doc) firstRun = aw.Run(doc, "Proin eros metus, sagittis sed. ") secondRun = aw.Run(doc, "Morbi enim nunc faucibus a.") doc.first_section.body.first_paragraph.append_child(firstRun) doc.first_section.body.first_paragraph.append_child(secondRun) builder.move_to(secondRun) builder.start_bookmark("Aspose bookmark") # إذا كانت NextSibling فارغة، فمن المرجح أن يكون هذا هو Run الأخير في الفقرة. if (secondRun.next_sibling != None): builder.move_to(secondRun.next_sibling) else: builder.move_to(secondRun.parent_paragraph) builder.end_bookmark("Aspose bookmark") save_options = aw.saving.PdfSaveOptions() save_options.outline_options.bookmarks_outline_levels.add("Aspose bookmark", 1); doc.Save("Output.docx", save_options);
import aspose.words as aw

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

shape = builder.insert_chart(aw.drawing.charts.ChartType.PIE, 432, 252)
chart = shape.chart
chart.title.text = "Demo Chart"

chart.series.clear()
chart.series.add("Series 1",
    ["Category1", "Category2", "Category3"],
    [2.7, 3.2, 0.8])

doc.save("Output.docx")
import aspose.words as aw doc = aw.Document() builder = aw.DocumentBuilder(doc) firstRun = aw.Run(doc, "Proin eros metus, sagittis sed. ") secondRun = aw.Run(doc, "Morbi enim nunc faucibus a.") doc.first_section.body.first_paragraph.append_child(firstRun) doc.first_section.body.first_paragraph.append_child(secondRun) builder.move_to(secondRun) builder.start_bookmark("Aspose bookmark") # إذا كانت NextSibling فارغة، فمن المرجح أن يكون هذا هو Run الأخير في الفقرة. if (secondRun.next_sibling != None): builder.move_to(secondRun.next_sibling) else: builder.move_to(secondRun.parent_paragraph) builder.end_bookmark("Aspose bookmark") doc.Save("Output.docx") import aspose.words as aw doc = aw.Document() builder = aw.DocumentBuilder(doc) firstRun = aw.Run(doc, "Proin eros metus, sagittis sed. ") secondRun = aw.Run(doc, "Morbi enim nunc faucibus a.") doc.first_section.body.first_paragraph.append_child(firstRun) doc.first_section.body.first_paragraph.append_child(secondRun) builder.move_to(secondRun) builder.start_bookmark("Aspose bookmark") # إذا كانت NextSibling فارغة، فمن المرجح أن يكون هذا هو Run الأخير في الفقرة. if (secondRun.next_sibling != None): builder.move_to(secondRun.next_sibling) else: builder.move_to(secondRun.parent_paragraph) builder.end_bookmark("Aspose bookmark") save_options = aw.saving.PdfSaveOptions() save_options.outline_options.bookmarks_outline_levels.add("Aspose bookmark", 1); doc.Save("Output.docx", save_options);
قم بتشغيل الكود

كيف تصنع DOCX في Python

  1. تثبيت Aspose.Words for Python via .NET
  2. أضف مرجع مكتبة (استيراد المكتبة) إلى مشروع Python الخاص بك
  3. قم بإنشاء مستند DOCX جديد
  4. استدعاء طريقة "save()"، مرر اسم الملف
  5. احصل على النتيجة كملف منفصل

Python مكتبة لإنشاء DOCX

نستضيف حزم Python بنا في مستودعات PyPi. يرجى اتباع التعليمات خطوة بخطوة حول كيفية تثبيت "Aspose.Words for Python via .NET" في بيئة المطور لديك.

متطلبات النظام

هذه الحزمة متوافقة مع Python ≥3.5 و <3.12. إذا قمت بتطوير برنامج لنظام التشغيل Linux، فيرجى إلقاء نظرة على المتطلبات الإضافية لدول gcc و libpython في وثائق المنتج.

تنسيقات الملفات المدعومة الأخرى

يمكنك إنشاء مستندات بتنسيقات ملفات أخرى:

5%

اشترك في Aspose Product Updates

احصل على رسائل إخبارية وعروض شهرية يتم تسليمها مباشرة إلى صندوق البريد الخاص بك.

© Aspose Pty Ltd 2001-2024. كل الحقوق محفوظة.