Skip to content

Commit

Permalink
Added README files for DocIO interactive sample browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Suriya-Balamurugan committed Nov 21, 2024
1 parent 2c5cc2b commit 26eb03d
Show file tree
Hide file tree
Showing 22 changed files with 1,324 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Replace bookmark content in a Word document using C#

The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **replace bookmark content in a Word document** using C#.

## Steps to replace bookmark content programmatically

Step 1: Create a new .NET Core console application project.

Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).

Step 3: Include the following namespaces in the Program.cs file.

```csharp
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;
```

Step 4: Add the following code snippet in Program.cs file to replace bookmark content in the Word document.

```csharp
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Opens an existing Word document.
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
{
//Creates the bookmark navigator instance to access the bookmark.
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
//Moves the virtual cursor to the location before the end of the bookmark "Northwind".
bookmarkNavigator.MoveToBookmark("Northwind");
//Gets the bookmark content.
TextBodyPart textBodyPart = bookmarkNavigator.GetBookmarkContent();
document.AddSection();
IWParagraph paragraph = document.LastSection.AddParagraph();
paragraph.AppendText("Northwind Database is a set of tables containing data fitted into predefined categories.");
//Adds the new bookmark into Word document.
paragraph.AppendBookmarkStart("bookmark_empty");
paragraph.AppendBookmarkEnd("bookmark_empty");
//Moves the virtual cursor to the location before the end of the bookmark "bookmark_empty".
bookmarkNavigator.MoveToBookmark("bookmark_empty");
//Replaces the bookmark content with text body part.
bookmarkNavigator.ReplaceBookmarkContent(textBodyPart);
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Docx);
}
}
}
```

More information about the bookmarks can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-bookmarks) section.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Compare Word documents using C#

The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **compare Word documents** using C#.

## Steps to compare Word documents programmatically

Step 1: Create a new .NET Core console application project.

Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).

Step 3: Include the following namespaces in the Program.cs file.

```csharp
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
```

Step 4: Add the following code snippet in Program.cs file to compare Word documents.

```csharp
//Loads the original document.
using (FileStream originalDocumentStreamPath = new FileStream(Path.GetFullPath(@"Data/OriginalDocument.docx"), FileMode.Open, FileAccess.Read))
{
using (WordDocument originalDocument = new WordDocument(originalDocumentStreamPath, FormatType.Docx))
{
//Loads the revised document
using (FileStream revisedDocumentStreamPath = new FileStream(Path.GetFullPath(@"Data/RevisedDocument.docx"), FileMode.Open, FileAccess.Read))
{
using (WordDocument revisedDocument = new WordDocument(revisedDocumentStreamPath, FormatType.Docx))
{
//Compare the original and revised Word documents.
originalDocument.Compare(revisedDocument);
//Save the Word document.
using (FileStream fileStreamOutput = File.Create(Path.GetFullPath("Output/Output.docx")))
{
originalDocument.Save(fileStreamOutput, FormatType.Docx);
}
}
}
}
}
```

More information about comparing Word document can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/word-document/compare-word-documents) section.
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Form filling in Word document using C#

The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **fill forms in a Word document** using C#.

## Steps to fill forms programmatically

Step 1: Create a new .NET Core console application project.

Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).

Step 3: Include the following namespaces in the Program.cs file.

```csharp
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;
```

Step 4: Add the following code snippet in Program.cs file to fill forms in the Word document.

```csharp
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Creates a new Word document.
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
{
IWSection sec = document.LastSection;
InlineContentControl inlineCC;
InlineContentControl dropDownCC;
WTable table1 = sec.Tables[1] as WTable;
WTableRow row1 = table1.Rows[1];

#region General Information
//Fill the name.
WParagraph cellPara1 = row1.Cells[0].ChildEntities[1] as WParagraph;
inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl;
WTextRange text = new WTextRange(document);
text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat);
text.Text = "Steve Jobs";
inlineCC.ParagraphItems.Add(text);
//Fill the date of birth.
cellPara1 = row1.Cells[0].ChildEntities[3] as WParagraph;
inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl;
text = new WTextRange(document);
text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat);
text.Text = "06/01/1994";
inlineCC.ParagraphItems.Add(text);
//Fill the address.
cellPara1 = row1.Cells[0].ChildEntities[5] as WParagraph;
inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl;
text = new WTextRange(document);
text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat);
text.Text = "2501 Aerial Center Parkway.";
inlineCC.ParagraphItems.Add(text);
text = new WTextRange(document);
text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat);
text.Text = "Morrisville, NC 27560.";
inlineCC.ParagraphItems.Add(text);
text = new WTextRange(document);
text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat);
text.Text = "USA.";
inlineCC.ParagraphItems.Add(text);
//Fill the phone no.
cellPara1 = row1.Cells[0].ChildEntities[7] as WParagraph;
inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl;
text = new WTextRange(document);
text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat);
text.Text = "+1 919.481.1974";
inlineCC.ParagraphItems.Add(text);
//Fill the email id.
cellPara1 = row1.Cells[0].ChildEntities[9] as WParagraph;
inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl;
text = new WTextRange(document);
text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat);
text.Text = "[email protected]";
inlineCC.ParagraphItems.Add(text);
#endregion

#region Educational Information
table1 = sec.Tables[2] as WTable;
row1 = table1.Rows[1];
//Fill the education type.
cellPara1 = row1.Cells[0].ChildEntities[1] as WParagraph;
dropDownCC = cellPara1.ChildEntities.LastItem as InlineContentControl;
text = new WTextRange(document);
text.ApplyCharacterFormat(dropDownCC.BreakCharacterFormat);
text.Text = dropDownCC.ContentControlProperties.ContentControlListItems[1].DisplayText;
dropDownCC.ParagraphItems.Add(text);
//Fill the university.
cellPara1 = row1.Cells[0].ChildEntities[3] as WParagraph;
inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl;
text = new WTextRange(document);
text.ApplyCharacterFormat(dropDownCC.BreakCharacterFormat);
text.Text = "Michigan University";
inlineCC.ParagraphItems.Add(text);
//Fill the C# experience level.
cellPara1 = row1.Cells[0].ChildEntities[7] as WParagraph;
dropDownCC = cellPara1.ChildEntities.LastItem as InlineContentControl;
text = new WTextRange(document);
text.ApplyCharacterFormat(dropDownCC.BreakCharacterFormat);
text.Text = dropDownCC.ContentControlProperties.ContentControlListItems[2].DisplayText;
dropDownCC.ParagraphItems.Add(text);
//Fill the VB experience level.
cellPara1 = row1.Cells[0].ChildEntities[9] as WParagraph;
dropDownCC = cellPara1.ChildEntities.LastItem as InlineContentControl;
text = new WTextRange(document);
text.ApplyCharacterFormat(dropDownCC.BreakCharacterFormat);
text.Text = dropDownCC.ContentControlProperties.ContentControlListItems[1].DisplayText;
dropDownCC.ParagraphItems.Add(text);
#endregion
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Docx);
}
}
}
```

More information about the content controls can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-content-controls) section.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Find and replace text in Word document using C#

The Syncfusion [. NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **find and replace text in a Word document** using C#.

## Steps to find and replace text programmatically

Step 1: Create a new . NET Core console application project.

Step 2: Install the [Syncfusion. DocIO. Net. Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).

Step 3: Include the following namespaces in the Program.cs file.

```csharp
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;
```

Step 4: Add the following code snippet in Program.cs file to find and replace text in the Word document.

```csharp
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Opens an existing Word document.
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
//Finds all occurrences of a misspelled word and replaces with properly spelled word.
document.Replace("Cyles", "Cycles", true, true);
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Docx);
}
}
}
```

More information about find and replace functionality can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-find-and-replace) section.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Convert HTML to Word document using C#

The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert HTML to a Word document** using C#.

## Steps to convert HTML to Word programmatically

Step 1: Create a new .NET Core console application project.

Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).

Step 3: Include the following namespaces in the Program.cs file.

```csharp
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;
```

Step 4: Add the following code snippet in Program.cs file to convert HTML to a Word document.

```csharp
//Loads an existing Word document into DocIO instance.
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/WordToHtml.html"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Html);
}
}
}
```

More information about HTML to Word conversion and vice versa can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/html) section.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Convert Word document to HTML using C#

The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert a Word document to HTML** using C#.

## Steps to convert Word to HTML programmatically

Step 1: Create a new .NET Core console application project.

Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).

Step 3: Include the following namespaces in the Program.cs file.

```csharp
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;
```

Step 4: Add the following code snippet in Program.cs file to convert a Word document to HTML.

```csharp
//Loads an existing Word document into DocIO instance.
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/WordToHtml.html"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Html);
}
}
}
```

More information about Word to HTML conversion and vice versa can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/html) section.
Loading

0 comments on commit 26eb03d

Please sign in to comment.