Skip to content

Commit fd7bec3

Browse files
Merge branch 'SyncfusionExamples:main' into main
2 parents 3115aa2 + 385c3ce commit fd7bec3

File tree

54 files changed

+1098
-116
lines changed

Some content is hidden

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

54 files changed

+1098
-116
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}") = "Replace-bookmark-content-with-HTML", "Replace-bookmark-content-with-HTML\Replace-bookmark-content-with-HTML.csproj", "{ABBFFEB7-79DA-41B9-8FCE-A9FA869CADEC}"
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+
{ABBFFEB7-79DA-41B9-8FCE-A9FA869CADEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{ABBFFEB7-79DA-41B9-8FCE-A9FA869CADEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{ABBFFEB7-79DA-41B9-8FCE-A9FA869CADEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{ABBFFEB7-79DA-41B9-8FCE-A9FA869CADEC}.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 = {5E468015-11EC-43FF-B1B4-8DB14E7C192D}
24+
EndGlobalSection
25+
EndGlobal

Bookmarks/Replace-bookmark-content-with-HTML/.NET/Replace-bookmark-content-with-HTML/Data/Input.html

Lines changed: 68 additions & 0 deletions
Large diffs are not rendered by default.

Sections/Set-image-in-first-page-only/.NET/Set-image-in-first-page-only/Output/.gitkeep renamed to Bookmarks/Replace-bookmark-content-with-HTML/.NET/Replace-bookmark-content-with-HTML/Output/.gitkeep

File renamed without changes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Syncfusion.DocIO.DLS;
2+
3+
using (WordDocument document = new WordDocument())
4+
{
5+
//Initialize the paragraph where the bookmark will be inserted.
6+
IWParagraph paragraph = null;
7+
//Get the full path of the input HTML file.
8+
string htmlPage = Path.GetFullPath(@"Data/Input.html");
9+
//Read the HTML content from the input file.
10+
string htmlContent = File.ReadAllText(htmlPage);
11+
//Add a new section to the Word document.
12+
IWSection section = document.AddSection();
13+
//Add a paragraph to the section.
14+
paragraph = section.AddParagraph();
15+
//Insert a bookmark start at the current location in the paragraph.
16+
paragraph.AppendBookmarkStart("Index");
17+
//Insert a bookmark end at the current location in the paragraph.
18+
paragraph.AppendBookmarkEnd("Index");
19+
//Convert the HTML content into a WordDocumentPart.
20+
WordDocumentPart htmlDocumentPart = ConvertHTMLToWordDocumentPart(htmlContent);
21+
//Create an instance of BookmarksNavigator to navigate to the bookmark.
22+
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
23+
//Move the virtual cursor to the location of the bookmark named "Index".
24+
bookmarkNavigator.MoveToBookmark("Index");
25+
//Replace the bookmark content with the converted HTML content.
26+
bookmarkNavigator.ReplaceContent(htmlDocumentPart);
27+
//Close htmlDocumentPart.
28+
htmlDocumentPart.Close();
29+
//Save the modified document to a specified file path in DOCX format.
30+
using (FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.docx"), FileMode.Create, FileAccess.Write))
31+
{
32+
document.Save(outputStream, Syncfusion.DocIO.FormatType.Docx);
33+
}
34+
}
35+
36+
/// <summary>
37+
/// Converts an HTML string into a WordDocumentPart to be inserted into the Word document.
38+
/// </summary>
39+
static WordDocumentPart ConvertHTMLToWordDocumentPart(string html)
40+
{
41+
//Create a new Word document.
42+
WordDocument tempDocument = new WordDocument();
43+
//Add minimal content to the document (ensures the document structure is valid).
44+
tempDocument.EnsureMinimal();
45+
//Append the HTML string to the last paragraph of the temporary Word document.
46+
tempDocument.LastParagraph.AppendHTML(html);
47+
//Create a new WordDocumentPart instance.
48+
WordDocumentPart wordDocumentPart = new WordDocumentPart();
49+
//Load the temporary document into the WordDocumentPart.
50+
wordDocumentPart.Load(tempDocument);
51+
//Return the WordDocumentPart containing the converted HTML content.
52+
return wordDocumentPart;
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Replace_bookmark_content_with_HTML</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\Input.html">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
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}") = "Set-text-right-to-stacked-bar-chart", "Set-text-right-to-stacked-bar-chart\Set-text-right-to-stacked-bar-chart.csproj", "{A9848002-0422-421D-93FC-10BC0E86B426}"
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+
{A9848002-0422-421D-93FC-10BC0E86B426}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A9848002-0422-421D-93FC-10BC0E86B426}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A9848002-0422-421D-93FC-10BC0E86B426}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A9848002-0422-421D-93FC-10BC0E86B426}.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 = {309CAA54-3ADD-4B1A-8B79-3A2C01C26DA1}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Syncfusion.DocIO.DLS;
2+
3+
// Creates a new instance of WordDocument (Empty Word Document).
4+
using (WordDocument document = new WordDocument())
5+
{
6+
// Adds a section to the document.
7+
IWSection sec = document.AddSection();
8+
// Adds a paragraph to the section.
9+
IWParagraph paragraph = sec.AddParagraph();
10+
// Loads the Excel file as a stream.
11+
Stream excelStream = File.OpenRead(Path.GetFullPath("Data/InputTemplate.xlsx"));
12+
// Creates and appends a chart to the paragraph with the Excel stream as a parameter.
13+
// The chart is created based on the data from the Excel file (range A1:D6), with specified width and height.
14+
WChart chart = paragraph.AppendChart(excelStream, 1, "A1:D6", 470, 300);
15+
// Sets the chart type to Stacked Bar Chart.
16+
chart.ChartType = Syncfusion.OfficeChart.OfficeChartType.Bar_Stacked;
17+
// Apply chart elements.
18+
// Sets the chart title.
19+
chart.ChartTitle = "Stacked Bar Chart";
20+
// Displays data labels for the third series (Series 2).
21+
chart.Series[2].DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
22+
23+
// Manually positions the data labels for each data point in the third series.
24+
chart.Series[2].DataPoints[0].DataLabels.Text = "Label 1";
25+
chart.Series[2].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 0.1;
26+
chart.Series[2].DataPoints[1].DataLabels.Text = "Label 2";
27+
chart.Series[2].DataPoints[1].DataLabels.Layout.ManualLayout.Left = 0.1;
28+
chart.Series[2].DataPoints[2].DataLabels.Text = "Label 3";
29+
chart.Series[2].DataPoints[2].DataLabels.Layout.ManualLayout.Left = 0.13;
30+
chart.Series[2].DataPoints[3].DataLabels.Text = "Label 4";
31+
chart.Series[2].DataPoints[3].DataLabels.Layout.ManualLayout.Left = 0.18;
32+
chart.Series[2].DataPoints[4].DataLabels.Text = "Label 5";
33+
chart.Series[2].DataPoints[4].DataLabels.Layout.ManualLayout.Left = 0.20;
34+
35+
// Sets the chart legend and positions it at the bottom of the chart.
36+
chart.HasLegend = true;
37+
chart.Legend.Position = Syncfusion.OfficeChart.OfficeLegendPosition.Bottom;
38+
using (FileStream outputStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create, FileAccess.Write))
39+
{
40+
// Saves the generated Word document to the specified file stream in DOCX format.
41+
document.Save(outputStream, Syncfusion.DocIO.FormatType.Docx);
42+
}
43+
}
44+
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>Set_text_right_to_stacked_bar_chart</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\Input.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Data\InputTemplate.xlsx">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Output\.gitkeep">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
</ItemGroup>
26+
27+
</Project>

0 commit comments

Comments
 (0)