Skip to content

Commit 0cd87a7

Browse files
authored
Merge pull request #2622 from syncfusion-content/1006546-ChartProperties
UG documentation 1006546: FAQ for how to set chart title properites like type of font, color, bold, size using XlsIO?
2 parents 215fcf0 + ca581e0 commit 0cd87a7

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

Document-Processing-toc.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6641,6 +6641,9 @@
66416641
<li>
66426642
<a href="/document-processing/excel/excel-library/net/faqs/how-to-retrieve-the-name-of-the-chart-in-an-Excel-worksheet">How to retrieve the name of the chart in an Excel worksheet?</a>
66436643
</li>
6644+
<li>
6645+
<a href="/document-processing/excel/excel-library/net/faqs/how-to-set-chart-title-properites-like-type-of-font, color, bold, size">How to set chart title properties like type of font, color, bold, size using XLsIO?</a>
6646+
</li>
66446647
</ul>
66456648
</li>
66466649
</ul>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: Setting Chart properties using Syncfusion XLsIO | Syncfusion
3+
description: This page tells how to set chart title properties like type of font, color, bold, size.
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to set chart title properties like type of font, color, bold, size using XLsIO?
10+
11+
This following code samples demonstrate how to set chart title properties like type of font, color, bold, size using C# (Cross-platform and Windows-specific) and VB.NET.
12+
13+
{% tabs %}
14+
{% highlight c# tabtitle="C# [Cross-platform]" %}
15+
using (ExcelEngine excelEngine = new ExcelEngine())
16+
{
17+
#region Workbook Initialization
18+
IApplication application = excelEngine.Excel;
19+
application.DefaultVersion = ExcelVersion.Xlsx;
20+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
21+
IWorksheet worksheet = workbook.Worksheets[0];
22+
#endregion
23+
24+
//Create a Chart
25+
IChartShape chart = workbook.Worksheets[0].Charts.Add();
26+
27+
chart.DataRange = worksheet.Range["A3:C15"];
28+
chart.ChartType = ExcelChartType.Column_Clustered;
29+
chart.IsSeriesInRows = false;
30+
31+
//Formatting the chart
32+
chart.ChartTitle = "Crescent City, CA";
33+
chart.ChartTitleArea.FontName = "Calibri";
34+
chart.ChartTitleArea.Size = 14;
35+
chart.ChartTitleArea.Bold = true;
36+
chart.ChartTitleArea.Color = ExcelKnownColors.Red;
37+
38+
//Embedded Chart Position
39+
chart.TopRow = 2;
40+
chart.BottomRow = 30;
41+
chart.LeftColumn = 5;
42+
chart.RightColumn = 18;
43+
44+
#region Save
45+
//Saving the workbook
46+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
47+
#endregion
48+
}
49+
{% endhighlight %}
50+
51+
{% highlight c# tabtitle="C# [Windows-specific]" %}
52+
using (ExcelEngine excelEngine = new ExcelEngine())
53+
{
54+
#region Workbook Initialization
55+
IApplication application = excelEngine.Excel;
56+
application.DefaultVersion = ExcelVersion.Xlsx;
57+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
58+
IWorksheet worksheet = workbook.Worksheets[0];
59+
#endregion
60+
61+
//Create a Chart
62+
IChartShape chart = workbook.Worksheets[0].Charts.Add();
63+
64+
chart.DataRange = worksheet.Range["A3:C15"];
65+
chart.ChartType = ExcelChartType.Column_Clustered;
66+
chart.IsSeriesInRows = false;
67+
68+
//Formatting the chart
69+
chart.ChartTitle = "Crescent City, CA";
70+
chart.ChartTitleArea.FontName = "Calibri";
71+
chart.ChartTitleArea.Size = 14;
72+
chart.ChartTitleArea.Bold = true;
73+
chart.ChartTitleArea.Color = ExcelKnownColors.Red;
74+
75+
//Embedded Chart Position
76+
chart.TopRow = 2;
77+
chart.BottomRow = 30;
78+
chart.LeftColumn = 5;
79+
chart.RightColumn = 18;
80+
81+
#region Save
82+
//Saving the workbook
83+
workbook.SaveAs("Output.xlsx");
84+
#endregion
85+
}
86+
{% endhighlight %}
87+
88+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
89+
Using excelEngine As New ExcelEngine()
90+
Dim application As IApplication = excelEngine.Excel
91+
application.DefaultVersion = ExcelVersion.Xlsx
92+
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
93+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
94+
95+
'Create a Chart
96+
Dim chart As IChartShape = workbook.Worksheets(0).Charts.Add()
97+
98+
chart.DataRange = worksheet.Range("A3:C15")
99+
chart.ChartType = ExcelChartType.Column_Clustered
100+
chart.IsSeriesInRows = False
101+
102+
'Formatting the chart
103+
chart.ChartTitle = "Crescent City, CA"
104+
chart.ChartTitleArea.FontName = "Calibri"
105+
chart.ChartTitleArea.Size = 14
106+
chart.ChartTitleArea.Bold = True
107+
chart.ChartTitleArea.Color = ExcelKnownColors.Red
108+
109+
'Embedded Chart Position
110+
chart.TopRow = 2
111+
chart.BottomRow = 30
112+
chart.LeftColumn = 5
113+
chart.RightColumn = 18
114+
115+
'Saving the workbook
116+
workbook.SaveAs("Output.xlsx")
117+
End Using
118+
{% endhighlight %}
119+
{% endtabs %}
120+
121+
A complete working example in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/1006546-ChartProperties/FAQ/Chart/.NET/ChartProperties">this GitHub page</a>.

0 commit comments

Comments
 (0)