Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KB samples #204

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34928.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-text-and-add-comments", "Find-text-and-add-comments\Find-text-and-add-comments.csproj", "{8B2E34B8-B23D-4717-A86A-34EB32012EC3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6140D05B-D8BA-4632-A04A-84100359C4AF}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Find_text_and_add_comments</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

using (FileStream inputStream = new FileStream(@"../../../Data/InsertComment.docx", FileMode.Open, FileAccess.Read))
{
//Open the existing Word document.
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
{
//Find all occurrence of a particular text ending with comma in the document using regex.
TextSelection[] textSelection = document.FindAll("panda", true, true);
if (textSelection != null)
{
//Iterates through each occurrence and comment it.
for (int i = 0; i < textSelection.Count(); i++)
{
WTextRange textRange = textSelection[i].GetAsOneRange();

//Get the index of the found text.
int textIndex = textRange.OwnerParagraph.ChildEntities.IndexOf(textRange);
//Add comment to a paragraph.
WComment comment = textRange.OwnerParagraph.AppendComment("comment test_" + i);
//Specify the author of the comment.
comment.Format.User = "Peter";
//Set the date and time for the comment.
comment.Format.DateTime = DateTime.Now;
//Insert the comment next to the textrange.
textRange.OwnerParagraph.ChildEntities.Insert(textIndex + 1, comment);
//Add the paragraph items to the commented items.
comment.AddCommentedItem(textRange);
}
}

//Save the Word document
using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write))
{
document.Save(outputStream, FormatType.Docx);
}
}
}
25 changes: 25 additions & 0 deletions Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34928.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Remove_all_page_breaks", "Remove_all_page_breaks\Remove_all_page_breaks.csproj", "{BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5AA2BDB5-3AE9-4E8D-8115-E0B1DF21850D}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

using (FileStream inputStream = new FileStream(@"../../../Data/Template.docx", FileMode.Open, FileAccess.Read))
{
//Open the existing Word document.
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
{
//Get the list of page breaks
List<Entity> entities = document.FindAllItemsByProperty(EntityType.Break, "BreakType", "PageBreak");

//Iterate through all page breaks and remove it from the owner paragraph
foreach (Entity entity in entities)
(entity as Break).OwnerParagraph.ChildEntities.Remove(entity);

//Save the Word document
using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write))
{
document.Save(outputStream, FormatType.Docx);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34928.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add_toc_in_merged_documents", "Add_toc_in_merged_documents\Add_toc_in_merged_documents.csproj", "{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CF8B010D-A0FC-4D30-8767-8B601222372E}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
</ItemGroup>

</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using Syncfusion.DocIORenderer;

//Get the Source document names from the folder.
string[] sourceDocumentNames = Directory.GetFiles(@"../../../Data/");

//Create an WordDocumentinstance for destination document.
using (WordDocument destinationDocument = new WordDocument())
{
//Add an section and paragraph to the destination document.
IWSection section = destinationDocument.AddSection();
IWParagraph paragraph = section.AddParagraph();
//Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries.
paragraph.AppendTOC(1, 3);

//Merge each source document to the destination document.
foreach (string subDocumentName in sourceDocumentNames)
{
//Open the source document files as a stream.
using (FileStream sourceDocumentPathStream = new FileStream(Path.GetFullPath(subDocumentName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Open the source documents.
using (WordDocument sourceDocument = new WordDocument(sourceDocumentPathStream, FormatType.Docx))
{
//Sets the break-code of First section of source document as NoBreak to avoid imported from a new page
sourceDocument.Sections[0].BreakCode = SectionBreakCode.NoBreak;
//Imports the contents of source document at the end of destination document
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles);
}
}
}

//Updates the table of contents
destinationDocument.UpdateTableOfContents();
//Save the destination document.
using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write))
{
destinationDocument.Save(outputStream, FormatType.Docx);
}
}
Loading