텍스트 편집
IronWord 의 "텍스트 편집" 기능은 개발자가 기존 DOCX 문서의 내용을 수정할 수 있도록 해줍니다. Developers can change the text directly by accessing the Paragraphs collection and selecting the specific Text object within a paragraph and replacing it with the ReplaceText method. 이를 통해 보고서의 특정 섹션 업데이트, 자리 표시자 교체 또는 사용자 입력이나 데이터에 따라 텍스트를 수정하는 등 콘텐츠를 동적으로 업데이트해야 하는 시나리오에 유연성을 제공합니다.
세부적인 수준까지 텍스트를 편집할 수 있는 기능 덕분에 문서의 구조나 서식을 변경하지 않고도 정확한 수정을 할 수 있습니다. 이 기능은 콘텐츠를 자주 업데이트하거나 수정해야 하는 자동 문서 생성 워크플로에서 특히 유용합니다.
기존 DOCX 파일의 텍스트를 편집하는 5단계
using IronWord;WordDocumentdoc= newWordDocument("sample.docx");doc.Paragraphs[0].ReplaceText("old text.", "This is the edited text.");doc.Paragraphs[1].ReplaceText(doc.Paragraphs[1].Texts[1].Text, "Updated content for the second paragraph.");doc.SaveAs("document.docx");
텍스트 바꾸기
이 코드는 IronWord 사용하여 기존 Word 문서 내의 특정 텍스트를 편집하는 방법을 보여줍니다. A WordDocument object is initialized to load "sample.docx". The code then accesses the Paragraphs collection from the WordDocument and modifies the first and second paragraphs of the document. The first modification updates the text of the first Text object in the first paragraph by calling UpdateText. The method ReplaceText takes in two parameters, the first being the string value to find and the second being the text to replace the old value with. 이 예시에서는 첫 번째 매개변수에 고정된 문자열을 제공하고 첫 번째 단락에 대한 새 문자열로 업데이트했습니다.
하지만 때로는 더 동적인 변수가 필요할 때도 있습니다. 이를 위해 두 번째 단락 내의 기존 텍스트에 접근할 수 있습니다. We first access the Paragraphs collection, which is similar to the first instance. Still, in the old text field, we input further drill down to access the existing text by accessing the Texts array property and then the Text property. 이 방법을 사용하면 기존 문자열을 찾고 업데이트하는 데 있어 완벽한 제어 권한을 얻을 수 있으므로 문서 조작 프로세스에 대한 신뢰도를 확보할 수 있습니다.
Explore Document Elements in IronWord Tutorial ReplaceText ReplaceText ReplaceText

