How to Edit Text in a Word Document

This article was translated from English: Does it need improvement?
Translated
View the article in English

Editing text in Word documents is crucial for content updates and maintaining documents. IronWord provides direct access to paragraph text runs, allowing precise modifications to existing DOCX content programmatically.

This tutorial demonstrates how to edit text in DOCX files using C# and IronWord.

Get started with IronWord

今日あなたのプロジェクトでIronWordを無料トライアルで使用開始。

最初のステップ:
green arrow pointer


Edit Text Example

To edit text in a Word document, load the existing file and access the target paragraph. The paragraph exposes a Texts array, and Texts[0] property references the first text run within that paragraph. Text runs are segments of text with consistent formatting.

ヒントIf a paragraph contains multiple formatting styles, each distinct segment is a separate text run.

:path=/static-assets/word/content-code-examples/how-to/edit-text-simple.cs
using IronWord;

// Load a DOCX document
WordDocument doc = new WordDocument("raw_document.docx");

// Edit existing text on the first paragraph
doc.Paragraphs[0].Texts[0].Text = "First paragraph is updated successfully";

// Export docx
doc.SaveAs("edited_document.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Before Modification

Document before text modification

After Modification

Document after text modification

Edit Specific Text Run

When a paragraph contains multiple text runs with different formatting, you can target specific runs using array indexing. Text runs use zero-based indexing, where Texts[0] is the first run, Texts[1] is the second, and so on. In this example, we target the second text run of the fourth paragraph using Paragraphs[3].Texts[1].

:path=/static-assets/word/content-code-examples/how-to/edit-text-text-run.cs
using IronWord;

// Load the document
WordDocument doc = new WordDocument("text_document.docx");

// Edit second text run in the 4th paragraph
doc.Paragraphs[3].Texts[1].Text = "Edited the textrun successfully within the same paragraph";

// Save to the same file
doc.SaveAs("text_document.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Before Modification

Document before text run modification

After Modification

Document after text run modification

よくある質問

IronWordとは何か?

IronWord は、DOCX ファイルを操作するために設計された強力な C# ライブラリであり、ユーザーは Word 文書内のテキストをプログラムで編集および変更できます。

IronWord を使用して DOCX ファイル内のテキストを編集するにはどうすればよいですか?

IronWord を使用して DOCX ファイル内のテキストを編集するには、既存のファイルを読み込み、変更するテキストを含む段落を特定し、更新されたファイルをエクスポートする前に `Texts` 配列を使用して変更を加えます。

Word 文書内のテキスト ランとは何ですか?

テキストランとは、段落内のテキストセグメントのうち、一貫した書式が維持されるセグメントを指します。特に異なる書式スタイルが適用されている場合、各段落には複数のテキストランが含まれることがあります。

IronWord を使用して段落内の特定のテキストをターゲットにするにはどうすればよいでしょうか?

ゼロベースのインデックスを使用して、特定のテキストランをターゲットにすることができます。例えば、4番目の段落の2番目のテキストランを編集するには、`Paragraphs[3].Texts[1]` を使用します。

Word 文書でテキストを編集することの重要性は何ですか?

Word 文書内のテキストを編集することは、コンテンツを更新し、文書の正確性と関連性を維持するために不可欠です。

IronWord は段落内の複数の書式スタイルを処理できますか?

はい、IronWord は、各セグメントを個別のテキスト ランとして扱い、個別にアクセスして変更することで、段落内の複数の書式設定スタイルを処理できます。

C# を使用してプログラム的に Word 文書にアクセスすることは可能ですか?

はい、IronWord などのライブラリの助けを借りて、C# を使用してプログラムで Word 文書にアクセスし、操作することができます。

Ahmad Sohail
フルスタックデベロッパー

Ahmadは、C#、Python、およびウェブ技術に強い基盤を持つフルスタック開発者です。彼はスケーラブルなソフトウェアソリューションの構築に深い関心を持ち、デザインと機能が実際のアプリケーションでどのように融合するかを探求することを楽しんでいます。

Iron Softwareチームに参加する前、Ahmadは自動化プロジェクトやAPI統合に取り組み、パフォーマンスの向上と開発者の体験向上に注力してきました。

彼の自由時間には、UI/UXのアイデアを試したり、オープンソースツールに貢献したり、時折テクニカルライティングやドキュメンテーションに取り組んで、複雑なトピックを理解しやすくすることを目指しています。

準備はいいですか?
Nuget ダウンロード 25,807 | バージョン: 2025.11 ただ今リリースされました