|
| 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