C#/VB.NET: Word 문서에서 단락 제거

2023-09-27 05:51:29 zaki zou

NuGet을 통해 설치됨

PM> Install-Package Spire.Doc

관련된 링크들

Word 문서를 처리할 때 일부 단락을 제거해야 할 수도 있습니다. 예를 들어, 중복되는 단락이 많은 인터넷의 내용을 문서에 복사한 후 추가 단락을 삭제하고 유용한 단락만 유지해야 합니다. 삭제는 다른 소프트웨어 없이 프로그래밍하여 Spire.Doc for .NET을 통해 쉽게 수행할 수 있습니다. 이 기사에서는 자세한 단계를 보여줍니다 Word 문서에서 단락 제거 Spire.Doc for .NET을 사용합니다.

Spire.Doc for .NET 설치

먼저 Spire.Doc for.NET 패키지에 포함된 DLL 파일을 .NET 프로젝트의 참조로 추가해야 합니다. DLL 파일은 이 링크에서 다운로드하거나 NuGet을 통해 설치할 수 있습니다.

PM> Install-Package Spire.Doc

Word 문서에서 특정 단락 삭제

Spire.Doc for .NET 단락을 제거하기 위해 ParagraphCollection 아래에 RemoveAt() 메서드를 제공합니다.

특정 단락을 제거하는 세부 단계는 다음과 같습니다.

  • Document 클래스의 객체를 생성합니다.
  • Document.LoadFromFile() 메서드를 사용하여 Word 문서를 로드합니다.
  • Document.Section[] 속성을 사용하여 첫 번째 섹션을 가져옵니다.
  • Section.Paragraphs.RemoveAt() 메서드를 사용하여 네 번째 단락을 제거합니다.
  • Document.SaveToFile() 메서드를 사용하여 문서를 저장합니다.
  • C#
  • VB.NET
using System;
    using Spire.Doc;
    
    namespace RemoveParagraphs
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                //Create an object of Document class
                Document document = new Document();
    
                //Load a Word document
                document.LoadFromFile("Sample.docx");
    
                //Get the first section
                Section section = document.Sections[0];
    
                //Remove the first paragraph in the section
                section.Paragraphs.RemoveAt(3);
    
                //Save the document
                document.SaveToFile("RemoveParagraphs.docx", FileFormat.Docx2013);
            }
        }
    }

C#/VB.NET: Remove Paragraphs in a Word Document

Word 문서에서 모든 단락 삭제

모든 단락을 제거하려면 Spire.Doc for .NET에서 제공하는 ParagraphCollection 아래의 Clear() 메서드를 사용하면 됩니다.

자세한 단계는 다음과 같습니다.

  • Document 클래스의 객체를 생성합니다.
  • Document.LoadFromFile() 메서드를 사용하여 Word 문서를 로드합니다.
  • 모든 섹션을 반복하고 Section.Paragraphs.Clear() 메서드를 사용하여 각 섹션의 모든 단락을 제거합니다.
  • Document.SaveToFile() 메서드를 사용하여 문서를 저장합니다.
  • C#
  • VB.NET
using System;
    using Spire.Doc;
    
    namespace RemoveAllParagraphs
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                //Create an object of Document class
                Document document = new Document();
    
                //Load a Word document
                document.LoadFromFile("Sample.docx");
    
                //Loop through all sections
                foreach (Section section in document.Sections)
                {
                    //Remove all paragraphs in the section
                    section.Paragraphs.Clear();
                }
    
                //Save the document
                document.SaveToFile("RemoveAllParagraphs.docx", FileFormat.Docx2013);
            }
        }
    }

C#/VB.NET: Remove Paragraphs in a Word Document

임시 라이센스 신청

생성된 문서에서 평가 메시지를 제거하고 싶거나, 기능 제한을 없애고 싶다면 30일 평가판 라이센스 요청 자신을 위해.

또한보십시오