Skip to content

Commit 2b35683

Browse files
Merge branch 'SyncfusionExamples:main' into ES-916206-How-to-delete-a-content-from-a-Word-document
2 parents f5fb0c1 + 614ee00 commit 2b35683

File tree

182 files changed

+1733
-1023
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+1733
-1023
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35309.182
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maintain-source-list-format-after-replace", "Maintain-source-list-format-after-replace\Maintain-source-list-format-after-replace.csproj", "{162D7557-79E5-4AAA-97B9-4BE8C3F12CA6}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{162D7557-79E5-4AAA-97B9-4BE8C3F12CA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{162D7557-79E5-4AAA-97B9-4BE8C3F12CA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{162D7557-79E5-4AAA-97B9-4BE8C3F12CA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{162D7557-79E5-4AAA-97B9-4BE8C3F12CA6}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {C5C11616-290D-4824-A387-AF3D408F533E}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Maintain_source_list_format_after_replace</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\DestinationDocument.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Data\SourceDocument.docx">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Output\.gitkeep">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
</ItemGroup>
26+
27+
</Project>

Tables/Replace-cell-content/.NET/Replace-cell-content/Output/.gitkeep renamed to Bookmarks/Maintain-source-list-format-after-replace/.NET/Maintain-source-list-format-after-replace/Output/.gitkeep

File renamed without changes.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
namespace Replace_content_with_bookmark
5+
{
6+
internal class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
using (FileStream destinationStream = new FileStream(Path.GetFullPath("Data/DestinationDocument.docx"), FileMode.Open, FileAccess.Read))
11+
{
12+
//Open the destination Word document.
13+
using (WordDocument destinationDocument = new WordDocument(destinationStream, FormatType.Docx))
14+
{
15+
using (FileStream sourceStream = new FileStream(Path.GetFullPath(@"Data/SourceDocument.docx"), FileMode.Open, FileAccess.Read))
16+
{
17+
//Open the source Word document.
18+
using (WordDocument sourceDocument = new WordDocument(sourceStream, FormatType.Docx))
19+
{
20+
//Replace text "Text one" in the destination document with content from the bookmark "bkmk1" in the source document.
21+
ReplaceTextAndMaintainListFormat(destinationDocument, sourceDocument, "Text one", "bkmk1");
22+
//Replace text "Text two" in the destination document with content from the bookmark "bkmk2" in the source document.
23+
ReplaceTextAndMaintainListFormat(destinationDocument, sourceDocument, "Text two", "bkmk2");
24+
//Save the modified destination document to the output stream.
25+
using (FileStream output = new FileStream(Path.GetFullPath("Output/Output.docx"), FileMode.Create, FileAccess.Write))
26+
{
27+
destinationDocument.Save(output, FormatType.Docx);
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
35+
/// <summary>
36+
/// Replaces specific text in a Word document with bookmarked content from another document, maintaining formatting.
37+
/// </summary>
38+
private static void ReplaceTextAndMaintainListFormat(WordDocument destinationDocument, WordDocument sourceDocument, string tokenToFind, string textBookmark)
39+
{
40+
string bookmarkRef = textBookmark + "_bm";
41+
// Find the text in the destination document where the bookmark start needs to be inserted.
42+
TextSelection start = destinationDocument.Find(tokenToFind, true, true);
43+
if (start != null)
44+
{
45+
// Get the selected text range and its parent paragraph.
46+
WTextRange startText = start.GetAsOneRange();
47+
WParagraph startParagraph = startText.OwnerParagraph;
48+
// Get the index of the selected text range in the paragraph.
49+
int index = startParagraph.Items.IndexOf(startText);
50+
// Remove the selected text at the identified index.
51+
startParagraph.Items.Remove(startText);
52+
// Create a BookmarkStart with a unique reference and insert it at the same index.
53+
BookmarkStart bookmarkStart = new BookmarkStart(destinationDocument, bookmarkRef);
54+
startParagraph.Items.Insert(index, bookmarkStart);
55+
// Append a BookmarkEnd with the same reference to mark the bookmark’s end.
56+
startParagraph.AppendBookmarkEnd(bookmarkRef);
57+
58+
// Check if the specified bookmark exists in the source document.
59+
if (sourceDocument.Bookmarks.FindByName(textBookmark) != null)
60+
{
61+
// Move the navigator to the bookmark in the source document.
62+
BookmarksNavigator bookmarksNavigator = new BookmarksNavigator(sourceDocument);
63+
bookmarksNavigator.MoveToBookmark(textBookmark);
64+
// Extract the content within the bookmark.
65+
WordDocumentPart wordDocumentPart = bookmarksNavigator.GetContent();
66+
67+
// Move the navigator to the newly created bookmark in the destination document.
68+
bookmarksNavigator = new BookmarksNavigator(destinationDocument);
69+
bookmarksNavigator.MoveToBookmark(bookmarkRef);
70+
// Get the paragraph containing the bookmark start in the destination document.
71+
WParagraph destinationPara = bookmarksNavigator.CurrentBookmark.BookmarkStart.OwnerParagraph;
72+
// Store the list style, first-line indent, and left indent of the paragraph.
73+
string listStyleName = destinationPara.ListFormat.CustomStyleName;
74+
float firstLineIndent = destinationPara.ParagraphFormat.FirstLineIndent;
75+
float leftIndent = destinationPara.ParagraphFormat.LeftIndent;
76+
// Replace the bookmark content with the extracted content from the source document.
77+
bookmarksNavigator.ReplaceContent(wordDocumentPart);
78+
// Reapply the original list style and indent settings to the paragraph.
79+
destinationPara.ListFormat.ApplyStyle(listStyleName);
80+
destinationPara.ParagraphFormat.FirstLineIndent = firstLineIndent;
81+
destinationPara.ParagraphFormat.LeftIndent = leftIndent;
82+
}
83+
else
84+
{
85+
// If the bookmark is not found, replace the content with an empty string.
86+
BookmarksNavigator bookmarksNavigator = new BookmarksNavigator(destinationDocument);
87+
bookmarksNavigator.MoveToBookmark(bookmarkRef);
88+
bookmarksNavigator.ReplaceBookmarkContent(string.Empty, true);
89+
}
90+
}
91+
}
92+
}
93+
}

Charts/Convert-chart-to-image/.NET-Framework/Convert-chart-to-image/Convert-chart-to-image.csproj

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@
3434
<WarningLevel>4</WarningLevel>
3535
</PropertyGroup>
3636
<ItemGroup>
37-
<Reference Include="Syncfusion.Compression.Base, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
38-
<HintPath>..\packages\Syncfusion.Compression.Base.26.1.42\lib\net462\Syncfusion.Compression.Base.dll</HintPath>
37+
<Reference Include="Syncfusion.Compression.Base, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
38+
<HintPath>..\packages\Syncfusion.Compression.Base.27.1.53\lib\net462\Syncfusion.Compression.Base.dll</HintPath>
3939
</Reference>
40-
<Reference Include="Syncfusion.DocIO.Base, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Syncfusion.DocIO.WinForms.26.1.42\lib\net462\Syncfusion.DocIO.Base.dll</HintPath>
40+
<Reference Include="Syncfusion.DocIO.Base, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
41+
<HintPath>..\packages\Syncfusion.DocIO.WinForms.27.1.53\lib\net462\Syncfusion.DocIO.Base.dll</HintPath>
4242
</Reference>
43-
<Reference Include="Syncfusion.Licensing, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
44-
<HintPath>..\packages\Syncfusion.Licensing.26.1.42\lib\net462\Syncfusion.Licensing.dll</HintPath>
43+
<Reference Include="Syncfusion.Licensing, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
44+
<HintPath>..\packages\Syncfusion.Licensing.27.1.53\lib\net462\Syncfusion.Licensing.dll</HintPath>
4545
</Reference>
46-
<Reference Include="Syncfusion.OfficeChart.Base, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
47-
<HintPath>..\packages\Syncfusion.OfficeChart.Base.26.1.42\lib\net462\Syncfusion.OfficeChart.Base.dll</HintPath>
46+
<Reference Include="Syncfusion.OfficeChart.Base, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Syncfusion.OfficeChart.Base.27.1.53\lib\net462\Syncfusion.OfficeChart.Base.dll</HintPath>
4848
</Reference>
49-
<Reference Include="Syncfusion.OfficeChartToImageConverter.Wpf, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
50-
<HintPath>..\packages\Syncfusion.OfficeChartToImageConverter.WinForms.26.1.42\lib\net462\Syncfusion.OfficeChartToImageConverter.Wpf.dll</HintPath>
49+
<Reference Include="Syncfusion.OfficeChartToImageConverter.Wpf, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
50+
<HintPath>..\packages\Syncfusion.OfficeChartToImageConverter.WinForms.27.1.53\lib\net462\Syncfusion.OfficeChartToImageConverter.Wpf.dll</HintPath>
5151
</Reference>
52-
<Reference Include="Syncfusion.SfChart.WPF, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
53-
<HintPath>..\packages\Syncfusion.SfChart.WPF.26.1.42\lib\net462\Syncfusion.SfChart.WPF.dll</HintPath>
52+
<Reference Include="Syncfusion.SfChart.WPF, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
53+
<HintPath>..\packages\Syncfusion.SfChart.WPF.27.1.53\lib\net462\Syncfusion.SfChart.WPF.dll</HintPath>
5454
</Reference>
5555
<Reference Include="System" />
5656
<Reference Include="System.Core" />
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Syncfusion.Compression.Base" version="26.1.42" targetFramework="net462" />
4-
<package id="Syncfusion.DocIO.WinForms" version="26.1.42" targetFramework="net462" />
5-
<package id="Syncfusion.Licensing" version="26.1.42" targetFramework="net462" />
6-
<package id="Syncfusion.OfficeChart.Base" version="26.1.42" targetFramework="net462" />
7-
<package id="Syncfusion.OfficeChartToImageConverter.WinForms" version="26.1.42" targetFramework="net462" />
8-
<package id="Syncfusion.SfChart.WPF" version="26.1.42" targetFramework="net462" />
3+
<package id="Syncfusion.Compression.Base" version="27.1.53" targetFramework="net462" />
4+
<package id="Syncfusion.DocIO.WinForms" version="27.1.53" targetFramework="net462" />
5+
<package id="Syncfusion.Licensing" version="27.1.53" targetFramework="net462" />
6+
<package id="Syncfusion.OfficeChart.Base" version="27.1.53" targetFramework="net462" />
7+
<package id="Syncfusion.OfficeChartToImageConverter.WinForms" version="27.1.53" targetFramework="net462" />
8+
<package id="Syncfusion.SfChart.WPF" version="27.1.53" targetFramework="net462" />
99
</packages>

Charts/Create-Pie-chart-from-database/.NET-Framework/Create-Pie-chart-from-database/Create-Pie-chart-from-database.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434
<WarningLevel>4</WarningLevel>
3535
</PropertyGroup>
3636
<ItemGroup>
37-
<Reference Include="Syncfusion.Compression.Base, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
38-
<HintPath>..\packages\Syncfusion.Compression.Base.26.1.42\lib\net462\Syncfusion.Compression.Base.dll</HintPath>
37+
<Reference Include="Syncfusion.Compression.Base, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
38+
<HintPath>..\packages\Syncfusion.Compression.Base.27.1.53\lib\net462\Syncfusion.Compression.Base.dll</HintPath>
3939
</Reference>
40-
<Reference Include="Syncfusion.DocIO.Base, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Syncfusion.DocIO.WinForms.26.1.42\lib\net462\Syncfusion.DocIO.Base.dll</HintPath>
40+
<Reference Include="Syncfusion.DocIO.Base, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
41+
<HintPath>..\packages\Syncfusion.DocIO.WinForms.27.1.53\lib\net462\Syncfusion.DocIO.Base.dll</HintPath>
4242
</Reference>
43-
<Reference Include="Syncfusion.Licensing, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
44-
<HintPath>..\packages\Syncfusion.Licensing.26.1.42\lib\net462\Syncfusion.Licensing.dll</HintPath>
43+
<Reference Include="Syncfusion.Licensing, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
44+
<HintPath>..\packages\Syncfusion.Licensing.27.1.53\lib\net462\Syncfusion.Licensing.dll</HintPath>
4545
</Reference>
46-
<Reference Include="Syncfusion.OfficeChart.Base, Version=26.1462.42.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
47-
<HintPath>..\packages\Syncfusion.OfficeChart.Base.26.1.42\lib\net462\Syncfusion.OfficeChart.Base.dll</HintPath>
46+
<Reference Include="Syncfusion.OfficeChart.Base, Version=27.1462.53.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Syncfusion.OfficeChart.Base.27.1.53\lib\net462\Syncfusion.OfficeChart.Base.dll</HintPath>
4848
</Reference>
4949
<Reference Include="System" />
5050
<Reference Include="System.Core" />
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Syncfusion.Compression.Base" version="26.1.42" targetFramework="net462" />
4-
<package id="Syncfusion.DocIO.WinForms" version="26.1.42" targetFramework="net462" />
5-
<package id="Syncfusion.Licensing" version="26.1.42" targetFramework="net462" />
6-
<package id="Syncfusion.OfficeChart.Base" version="26.1.42" targetFramework="net462" />
3+
<package id="Syncfusion.Compression.Base" version="27.1.53" targetFramework="net462" />
4+
<package id="Syncfusion.DocIO.WinForms" version="27.1.53" targetFramework="net462" />
5+
<package id="Syncfusion.Licensing" version="27.1.53" targetFramework="net462" />
6+
<package id="Syncfusion.OfficeChart.Base" version="27.1.53" targetFramework="net462" />
77
<package id="System.Data.OleDb" version="8.0.0" targetFramework="net472" />
88
</packages>

0 commit comments

Comments
 (0)