
目次が含まれていない大きな文書を考えてみてください。読者は情報を探すために長時間スクロールし続けなければならず、多くの時間が浪費されます。目次(TOC)は、文書の構造とナビゲートの可能性を明確に示すことで、この問題を即座に解決します。この記事では、Word文書に目次を追加する方法を説明します。
MS Wordで目次を追加する手順
ステップ 1: 文書の準備
Wordに目次を追加する前に、文書が適切にフォーマットされていることを確認してください。見出し(見出し 1、見出し 2、見出し 3)を使用してコンテンツを構造化します。Wordはこれらの見出しを使用してTOCを生成します。
ステップ 2: MS Wordに目次を挿入する
- 目次を挿入したい場所をクリックします。通常は文書の最初に配置します。
- リボンの参照タブに移動します。
- 目次グループで、目次ボタンをクリックします。
- ドロップダウンメニューからTOCスタイルを選択します。Wordは複数の組み込みスタイルを提供しています。

MS Wordに目次を追加する
WordでTOCを追加する:開発者ガイド
次のセクションでは、開発者がAspose.Wordsライブラリを使用してWord文書にプログラム的に目次を挿入する方法を示します。この機能をさまざまなプログラミング言語で実装する方法を学びましょう。
C#を使用してWordに目次を追加する
C#を使用してWord文書に目次を追加する手順は以下の通りです。
- Aspose.Words for .NETをアプリケーションにインストールします。
- 次のコードサンプルを使用して、C#でWord文書に目次を追加します。
// Initialize document. | |
Document doc = new Document(); | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
// Insert a table of contents at the beginning of the document. | |
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u"); | |
// The newly inserted table of contents will be initially empty. | |
// It needs to be populated by updating the fields in the document. | |
doc.UpdateFields(); | |
// Save the document | |
doc.Save("InsertTOC_out.doc"); |
C#を使用してWord文書で目次を作成および操作する方法を学びましょう。
Javaを使用してWordに目次を挿入する
Javaを使用してWord文書に目次を挿入する手順は以下の通りです。
- Aspose.Words for Javaをアプリケーションにインストールします。
- 次のコードサンプルを使用して、JavaでWord文書に目次を挿入します。
// Load the Word document | |
Document doc = new Document("Word.docx"); | |
// Create a document builder | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
// Insert a table of contents at the beginning of the document. | |
builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u"); | |
builder.insertBreak(BreakType.PAGE_BREAK); | |
// The newly inserted table of contents will be initially empty. | |
// It needs to be populated by updating the fields in the document. | |
doc.updateFields(); | |
// Save the updated document | |
doc.save("Output.docx"); |
詳細については、Javaを使用してWord文書で目次を作成および更新する方法に関する記事をお読みください。
Pythonを使用してWordに目次を追加する
Pythonを使用してWord文書に目次を追加する手順は以下の通りです。
- Aspose.Words for Pythonをアプリケーションにインストールします。
- 次のコードサンプルを使用して、PythonでWord文書に目次を追加します。
# This code example shows how to insert a Table of Contents in an existing Word document. | |
# Load an existing Word document | |
doc = Document("toc_sample.docx"); | |
builder = DocumentBuilder(doc); | |
# Insert a table of contents at the beginning of the document. | |
builder.insert_table_of_contents("\\o \"1-3\" \\h \\z \\u"); | |
# The newly inserted table of contents will be initially empty. | |
# It needs to be populated by updating the fields in the document. | |
doc.update_fields(); | |
# Save the document | |
doc.save("InsertTOC_out.docx"); |
Pythonを使用してWordの目次(TOC)を操作する方法を確認してください。
C++を使用してWordに目次を挿入する
C++を使用してWord文書に目次を追加する手順は以下の通りです。
- Aspose.Words for C++をアプリケーションにインストールします。
- 次のコードサンプルを使用して、C++でWord文書に目次を挿入します。
// Source and output directory paths. | |
System::String sourceDataDir = u"SourceDirectory\\"; | |
System::String outputDataDir = u"OutputDirectory\\"; | |
// Load the Word file | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(sourceDataDir + u"Sample 5.docx"); | |
// Create an instance of the DocumentBuilder class | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
// Insert a table of contents at the beginning of the document. | |
builder->InsertTableOfContents(u"\\o \"1-3\" \\h \\z \\u"); | |
// The newly inserted table of contents will be initially empty. | |
// It needs to be populated by updating the fields in the document. | |
doc->UpdateFields(); | |
// Output file path | |
System::String outputPath = outputDataDir + u"AddTOC.docx"; | |
// Save the Word file | |
doc->Save(outputPath); |
C++を使用してWord文書で目次を操作する方法について詳しく学びましょう。
TOC in Word – 無料リソース
Word文書でTOCを操作する以外にも、以下のリソースを使ってAspose.Words for Pythonの機能を探索してください。
Wordに目次を追加して文書処理をプログラムで自動化する準備は整いましたか? Aspose.Wordsの無料の一時ライセンスを取得し、評価制限なしでライブラリの使用を開始しましょう。
結論
Wordで目次を追加することは、整理されたプロフェッショナルで読みやすい文書を作成するために重要です。このガイドで説明した手順に従うことで、MS Wordに簡単に目次を挿入できます。この記事では、さまざまなプログラミング言語を使用してWordに目次を追加する手順とコードサンプルも提供しています。質問がある場合や追加のサポートが必要な場合は、無料サポートフォーラムでお気軽にお問い合わせください。