Naudodami mūsų programavimo API, Python via .NET kūrėjai gali lengvai sukurti PDF, DOC, DOCX, HTML, EPUB ir daugelio kitų formatų dokumentą naudodami tik kelias kodo eilutes.
Naudodami pateiktą galingą API, "Python" kūrėjai gali kurti dokumentus beveik bet kokiu formatu. Norėdami tai padaryti, naudodami Python via .NET biblioteką turite atlikti kelis veiksmus:
Verta paminėti, kad tuščiame dokumente techniškai turėtų būti viena pastraipa, todėl programiškai kurdami dokumentą gausite būtent tokią pagrindinę dokumento struktūrą.
Atminkite, kad galite akimirksniu įtraukti turinį į naujai sukurtą dokumentą. Taigi jūs gausite ne tik tuščią dokumentą, bet ir dokumentą su reikiamu turiniu. Daugiau informacijos apie tai, kaip redaguoti dokumentą, rasite puslapyje Redagavimas.
Suteikta Python via .NET biblioteka leidžia programiškai kurti dokumentą bet kokiu palaikomu formatu – PDF, DOCX, DOC, RTF, ODT, EPUB, HTML ir kt.
Išbandykite mūsų galingą funkciją ir sužinokite, kaip sukurti dokumentą kai kuriais formatais, naudojant šį pavyzdį:
pip install aspose-words
Kopijuoti
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")
# Jei NextSibling yra nulis, greičiausiai tai yra paskutinis Run pastraipoje.
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")
# Jei NextSibling yra nulis, greičiausiai tai yra paskutinis Run pastraipoje.
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")
# Jei NextSibling yra nulis, greičiausiai tai yra paskutinis Run pastraipoje.
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")
# Jei NextSibling yra nulis, greičiausiai tai yra paskutinis Run pastraipoje.
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")
# Jei NextSibling yra nulis, greičiausiai tai yra paskutinis Run pastraipoje.
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")
# Jei NextSibling yra nulis, greičiausiai tai yra paskutinis Run pastraipoje.
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")
# Jei NextSibling yra nulis, greičiausiai tai yra paskutinis Run pastraipoje.
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")
# Jei NextSibling yra nulis, greičiausiai tai yra paskutinis Run pastraipoje.
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")
# Jei NextSibling yra nulis, greičiausiai tai yra paskutinis Run pastraipoje.
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);
Python paketus talpiname PyPi saugyklose. Vadovaukitės nuosekliomis instrukcijomis, kaip įdiegti "Aspose.Words for Python via .NET" į kūrėjo aplinką.
Šis paketas suderinamas su Python ≥3.5 ir <3.12. Jei kuriate programinę įrangą, skirtą Linux, peržiūrėkite papildomus gcc ir libpython reikalavimus produkto dokumentacijoje.