1- using Syncfusion . DocIO ;
1+
2+
3+ using Microsoft . VisualBasic . FileIO ;
4+ using Syncfusion . DocIO ;
25using Syncfusion . DocIO . DLS ;
36
47namespace Replace_text_heading_paragraphs
@@ -7,26 +10,24 @@ class Program
710 {
811 static void Main ( string [ ] args )
912 {
10- using ( FileStream inputFileStream = new FileStream ( Path . GetFullPath ( @"Data/Input.docx" ) , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
13+ using ( FileStream fileStreamPath = new FileStream ( Path . GetFullPath ( @"Data/Input.docx" ) , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
1114 {
12- //Opens the input Word document.
13- using ( WordDocument document = new WordDocument ( inputFileStream , FormatType . Automatic ) )
15+ //Opens an existing Word document.
16+ using ( WordDocument document = new WordDocument ( fileStreamPath , FormatType . Automatic ) )
1417 {
1518 for ( int headingLevel = 1 ; headingLevel < 10 ; headingLevel ++ )
1619 {
1720 //Find headings based on the levels and endnote by paragraph in Word document.
1821 List < Entity > headings = document . FindAllItemsByProperty ( EntityType . Paragraph , "StyleName" , "Heading " + headingLevel ) ;
19- //Iterate through all headings in the list .
22+ //Replace the headings with text .
2023 for ( int index = 0 ; index < headings . Count ; index ++ )
2124 {
22- //Cast the current heading to WParagraph.
2325 WParagraph paragraph = headings [ index ] as WParagraph ;
24- //Remove all child elements from the paragraph.
2526 paragraph . ChildEntities . Clear ( ) ;
26- //Add new text to replace the heading content.
27- paragraph . AppendText ( "Replaced Heading" + headingLevel + " text" ) ;
27+ paragraph . AppendText ( "Replaced Heading" + headingLevel + " text" ) ;
2828 }
2929 }
30+ //Creates file stream.
3031 using ( FileStream outputFileStream = new FileStream ( Path . GetFullPath ( @"Output/Result.docx" ) , FileMode . Create , FileAccess . ReadWrite ) )
3132 {
3233 //Saves the Word document to file stream.
0 commit comments