Utwórz Word za pomocą Python via .NET biblioteki

Nasza potężna Python biblioteka umożliwia programistom programowe tworzenie Word w zaledwie kilku krokach

Programiści Python via .NET mogą łatwo tworzyć Word, korzystając tylko z naszego zaawansowanego interfejsu API produktu. Oznacza to, że nasze rozwiązanie zapewni programistom wszystko, czego potrzebują do tworzenia Word w Python.

Zobacz fragment kodu

Twórz program Word w Python

Dzięki naszej Python bibliotece programiści mogą łatwo tworzyć Word od podstaw. Aby to zrobić, programiści Python via .NET muszą wykonać tylko kilka kroków:

  1. Dodaj nazwę pliku
  2. Zacznij tworzyć Word dokument za pomocą Python
  3. Zapisz wyjściowy Word plik

Warto zauważyć, że technicznie pusty dokument powinien zawierać jeden akapit, więc gdy programowo utworzysz Word dokument, otrzymasz dokładnie taką podstawową strukturę dokumentu.

Pamiętaj, że możesz natychmiast dodać zawartość do nowo utworzonego Word pliku. W ten sposób otrzymasz nie tylko pusty dokument, ale dokument zawierający niezbędną treść. Aby uzyskać więcej informacji na temat edycji dokumentu, zobacz stronę Edycja.

Twórz Word w Python

Ta Python via .NET biblioteka umożliwia programowe tworzenie Word dokumentów. Wypróbuj naszą zaawansowaną funkcjonalność i zobacz, jak tworzyć Word w niektórych formatach, korzystając z następującego przykładu:

Utwórz nowy DOCX za pomocą Python
Wybierz format docelowy z listy
Uruchom kod
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") # Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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") # Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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") # Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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") # Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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")
# Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie.
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") # Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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") # Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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") # Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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") # Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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);
Uruchom kod

Jak zrobić Word w Python

  1. Zainstaluj Aspose.Words for Python via .NET
  2. Dodaj odniesienie do biblioteki (zaimportuj bibliotekę) do swojego Python projektu
  3. Utwórz nowy Word dokument
  4. Wywołaj metodę "save()", przekazując nazwę pliku
  5. Uzyskaj wynik jako osobny plik

Python biblioteka do utworzenia Word

Nasze pakiety Python hostujemy w repozytoriach PyPi. Postępuj zgodnie z instrukcjami krok po kroku, jak zainstalować "Aspose.Words for Python via .NET" w swoim środowisku deweloperskim.

wymagania systemowe

Ten pakiet jest kompatybilny z Python ≥3.5 i <3.12. Jeśli tworzysz oprogramowanie dla systemu Linux, zapoznaj się z dodatkowymi wymaganiami dotyczącymi gcc i libpython w dokumentacji produktu.

Inne obsługiwane formaty plików

Możesz tworzyć dokumenty w innych formatach plików:

5%

Subskrybuj aktualizacje produktów Aspose

Otrzymuj comiesięczne biuletyny i oferty dostarczane bezpośrednio do Twojej skrzynki pocztowej.

© Aspose Pty Ltd 2001-2024. Wszelkie prawa zastrzeżone.