Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of C # operating Word

Shulou Source: shulou.com Published: 2022-06-02 08:55:24 10月03日 Update

This article mainly explains "what is the method of C # operating Word". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the method of operating Word in C#"?

The connotation of C # operating Word: when C # operates the Office suite, you need to use COM components, and you need to add corresponding COM components to the project. There are two ways to find specified keywords in Word with C#: Selection object and Range object.

The usage of the Selection object of C # manipulating Word:

/ / C # internal void SelectionFind () {string strFind = "find me"; Word.Find fnd = ThisApplication.Selection.Find; fnd.ClearFormatting (); fnd.Text = strFind; object missingValue = Type.Missing If (fnd.Execute (ref missingValue, ref missingValue) {MessageBox.Show ("Text found.");} else {MessageBox.Show ("The text could not be located.");}}

The usage of the Range object of C # manipulating Word:

/ / C # internal void RangeFind () {Word.Range rng = ThisDocument.Paragraphs [2] .range; Word.Find fnd = rng.Find; fnd.ClearFormatting (); object missingValue = Type.Missing; object findStr = "find me" If (fnd.Execute (ref findStr, ref missingValue, ref missingValue)) {MessageBox.Show ("Text found.");} else {MessageBox.Show ("Text not found.");} rng.Select () } at this point, I believe you have a deeper understanding of "what is the method of operating Word in C#". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Caching methods objects content components learning practicality deeper keywords keywords interests connotations suites practicality practicality ease of operation time more friends websites Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei Linux Microsoft vpn