Skip to content

Commit fd5e44f

Browse files
Reverted
1 parent c0a8d86 commit fd5e44f

File tree

1 file changed

+10
-9
lines changed
  • Find-item-in-word-document/Replace-text-heading-paragraphs/.NET/Replace-text-heading-paragraphs

1 file changed

+10
-9
lines changed

Find-item-in-word-document/Replace-text-heading-paragraphs/.NET/Replace-text-heading-paragraphs/Program.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Syncfusion.DocIO;
1+

2+
3+
using Microsoft.VisualBasic.FileIO;
4+
using Syncfusion.DocIO;
25
using Syncfusion.DocIO.DLS;
36

47
namespace 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

Comments
 (0)