Skip to content

Commit ce3197f

Browse files
Merge pull request #449 from SyncfusionExamples/ES-958622-EditableRanges
ES-958622 - Add GitHub samples for APIs to set editable ranges in protected DOCX documents
2 parents f6d2aec + df2a0ce commit ce3197f

File tree

36 files changed

+667
-0
lines changed

36 files changed

+667
-0
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.13.35825.156 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-editable-range-in-a-table", "Add-editable-range-in-a-table\Add-editable-range-in-a-table.csproj", "{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}"
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+
{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}.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 = {1FBCA517-BE3F-40EF-B53A-536B02603ECA}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Add_editable_range_in_a_table</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\Template.docx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Output\.gitkeep">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
using System.IO;
4+
5+
namespace Add_editable_range_in_a_table
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
// Load the Word document
12+
using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Template.docx")))
13+
{
14+
// Access the first table in the first section of the document
15+
WTable table = document.Sections[0].Tables[0] as WTable;
16+
// Access the paragraph in the third row and third column of the table
17+
WParagraph paragraph = table[2, 2].ChildEntities[0] as WParagraph;
18+
// Create a new editable range start for the table cell paragraph
19+
EditableRangeStart editableRangeStart = new EditableRangeStart(document);
20+
// Insert the editable range start at the beginning of the paragraph
21+
paragraph.ChildEntities.Insert(0, editableRangeStart);
22+
// Set the editor group for the editable range to allow everyone to edit
23+
editableRangeStart.EditorGroup = EditorType.Everyone;
24+
// Apply editable range to second column only
25+
editableRangeStart.FirstColumn = 1;
26+
editableRangeStart.LastColumn = 1;
27+
// Access the paragraph
28+
paragraph = table[5, 2].ChildEntities[0] as WParagraph;
29+
// Append an editable range end to close the editable region
30+
paragraph.AppendEditableRangeEnd();
31+
//Sets the protection with password and allows only reading
32+
document.Protect(ProtectionType.AllowOnlyReading, "password");
33+
//Creates file stream
34+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
35+
{
36+
//Saves the Word document to file stream
37+
document.Save(outputStream, FormatType.Docx);
38+
}
39+
}
40+
}
41+
}
42+
}
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.13.35825.156 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-editable-range", "Add-editable-range\Add-editable-range.csproj", "{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}"
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+
{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}.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 = {74BE8749-A1F1-427A-92CF-977EEAC2B413}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Add_editable_range</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Output\.gitkeep">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using System.IO;
4+
5+
namespace Add_editable_range
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
//Create a Word document
12+
using (WordDocument document = new WordDocument())
13+
{
14+
//Add a section and a paragraph to the Word document
15+
document.EnsureMinimal();
16+
WParagraph paragraph = document.LastParagraph;
17+
18+
//Append text to the paragraph
19+
paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks ");
20+
21+
//Add an editable range to the paragraph
22+
EditableRangeStart editableRangeStart = paragraph.AppendEditableRangeStart();
23+
paragraph.AppendText("sample databases are based, is a large, multinational manufacturing company.");
24+
paragraph.AppendEditableRangeEnd(editableRangeStart);
25+
26+
//Set protection with a password to allow read-only access
27+
document.Protect(ProtectionType.AllowOnlyReading, "password");
28+
29+
//Creates file stream
30+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
31+
{
32+
//Saves the Word document to file stream
33+
document.Save(outputStream, FormatType.Docx);
34+
}
35+
}
36+
}
37+
}
38+
}
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.13.35825.156 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-editable-range-by-id", "Find-editable-range-by-id\Find-editable-range-by-id.csproj", "{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}"
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+
{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}.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 = {EAADC1D0-BF63-4DF6-B606-1CECD2395ADA}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)