Python ライブラリを使用すると、開発者は HTML を最初から簡単に作成できます。これを行うには、Python via .NET 開発者はいくつかの手順を実行する必要があります。
空白のドキュメントには技術的に1つの段落が含まれることになっているため、プログラムで HTML ドキュメントを作成すると、まさにその基本的なドキュメント構造が得られることに注意してください。
新しく作成した HTML ファイルにコンテンツをすぐに追加できることに注意してください。したがって、空のドキュメントだけでなく、必要なコンテンツを含むドキュメントも取得できます。ドキュメントを編集する方法の詳細については、編集ページを参照してください。
この Python via .NET ライブラリを使用すると、HTML ドキュメントをプログラムで作成できます。強力な機能を試して、次の例を使用していくつかの形式で HTML を作成する方法を確認してください。
pip install aspose-words コピー 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.html") 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 が null の場合、これが段落内の最後の 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.html") 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 が null の場合、これが段落内の最後の 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.html", 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.html") 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 が null の場合、これが段落内の最後の 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.html") 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 が null の場合、これが段落内の最後の 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.html", 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 が null の場合、これが段落内の最後の 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.html") 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 が null の場合、これが段落内の最後の 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.html") 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 が null の場合、これが段落内の最後の 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.html", 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.html") 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 が null の場合、これが段落内の最後の 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.html") 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 が null の場合、これが段落内の最後の 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.html", save_options); Python パッケージはPyPiリポジトリでホストしています。 "Aspose.Words for Python via .NET" 開発者環境にインストールする方法のステップバイステップの説明に従ってください。
このパッケージは Python ≥3.5 および <3.12 と互換性があります。 Linux 用のソフトウェアを開発する場合は、 製品ドキュメントの gcc および libpython の追加要件を参照してください。