diff --git a/File-Formats-toc.html b/File-Formats-toc.html index c71069e19..e612f2927 100644 --- a/File-Formats-toc.html +++ b/File-Formats-toc.html @@ -674,6 +674,7 @@
  • Azure Vision
  • AWS Textract
  • Linux
  • +
  • Mac
  • Features
  • @@ -1066,6 +1067,7 @@
  • .NET MAUI
  • Linux
  • Mac
  • +
  • Console
  • Azure
  • diff --git a/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img1.png b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img1.png new file mode 100644 index 000000000..56c99f7e1 Binary files /dev/null and b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img1.png differ diff --git a/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img2.png b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img2.png new file mode 100644 index 000000000..190b20906 Binary files /dev/null and b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img2.png differ diff --git a/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img3.png b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img3.png new file mode 100644 index 000000000..30877534f Binary files /dev/null and b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img3.png differ diff --git a/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img4.png b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img4.png new file mode 100644 index 000000000..7e5dcdb07 Binary files /dev/null and b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img4.png differ diff --git a/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img5.png b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img5.png new file mode 100644 index 000000000..14cc33f06 Binary files /dev/null and b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img5.png differ diff --git a/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img6.png b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img6.png new file mode 100644 index 000000000..448ca6063 Binary files /dev/null and b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img6.png differ diff --git a/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img7.png b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img7.png new file mode 100644 index 000000000..a5e494105 Binary files /dev/null and b/File-Formats/XlsIO/Console-Apps-images/Console-Apps-images_img7.png differ diff --git a/File-Formats/XlsIO/create-excel-files-in-console-apps-c-sharp.md b/File-Formats/XlsIO/create-excel-files-in-console-apps-c-sharp.md new file mode 100644 index 000000000..c1588c169 --- /dev/null +++ b/File-Formats/XlsIO/create-excel-files-in-console-apps-c-sharp.md @@ -0,0 +1,818 @@ +--- +title: Create Excel file in Console Application | Syncfusion +description: Learn here how to create an Excel file in Console Application using Syncfusion Excel library. +platform: file-formats +control: XlsIO +documentation: UG +--- +# Create an Excel file in a Console application + +[Syncfusion Excel library for ASP.NET Core platform](https://www.syncfusion.com/document-processing/excel-framework/net-core/excel-library) can be used to create, read, edit Excel files. This also convert Excel files to PDF. + +## Create a simple Excel report using .NET Core + +The below steps illustrates creating a simple Invoice formatted Excel document in console application using .NET Core. + +Step 1: Create a new C# Console Application project. + +Create console application in Visual Studio + +Step 2: Name the project. + +Name the Application + +Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +Install Syncfusion.XlsIO.NET.COre NuGet Package + +N> Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion license key in your applications to use our components. + +Step 4: Include the following namespaces in the Program.cs file. +{% capture codesnippet1 %} +{% tabs %} +{% highlight c# tabtitle="C#" %} +using Syncfusion.XlsIO; +using System.IO; +using Syncfusion.Drawing; +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET" %} +Imports Syncfusion.XlsIO +Imports System.IO +Imports Syncfusion.Drawing +{% endhighlight %} +{% endtabs %} +{% endcapture %} +{{ codesnippet1 | OrderList_Indent_Level_1 }} + +Step 5: Include the below code snippet in program.cs to create an Excel file. +{% capture codesnippet3 %} +{% tabs %} +{% highlight c# tabtitle="C#" %} +//Create an instance of ExcelEngine +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + //Create a workbook + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Adding a picture + FileStream imageStream = new FileStream("AdventureCycles-Logo.png", FileMode.Open, FileAccess.Read); + IPictureShape shape = worksheet.Pictures.AddPicture(1, 1, imageStream, 20, 20); + + //Disable gridlines in the worksheet + worksheet.IsGridLinesVisible = false; + + //Enter values to the cells from A3 to A5 + worksheet.Range["A3"].Text = "46036 Michigan Ave"; + worksheet.Range["A4"].Text = "Canton, USA"; + worksheet.Range["A5"].Text = "Phone: +1 231-231-2310"; + + //Make the text bold + worksheet.Range["A3:A5"].CellStyle.Font.Bold = true; + + //Merge cells + worksheet.Range["D1:E1"].Merge(); + + //Enter text to the cell D1 and apply formatting. + worksheet.Range["D1"].Text = "INVOICE"; + worksheet.Range["D1"].CellStyle.Font.Bold = true; + worksheet.Range["D1"].CellStyle.Font.RGBColor = Color.FromArgb(42, 118, 189); + worksheet.Range["D1"].CellStyle.Font.Size = 35; + + //Apply alignment in the cell D1 + worksheet.Range["D1"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight; + worksheet.Range["D1"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop; + + //Enter values to the cells from D5 to E8 + worksheet.Range["D5"].Text = "INVOICE#"; + worksheet.Range["E5"].Text = "DATE"; + worksheet.Range["D6"].Number = 1028; + worksheet.Range["E6"].Value = "12/31/2018"; + worksheet.Range["D7"].Text = "CUSTOMER ID"; + worksheet.Range["E7"].Text = "TERMS"; + worksheet.Range["D8"].Number = 564; + worksheet.Range["E8"].Text = "Due Upon Receipt"; + + //Apply RGB backcolor to the cells from D5 to E8 + worksheet.Range["D5:E5"].CellStyle.Color = Color.FromArgb(42, 118, 189); + worksheet.Range["D7:E7"].CellStyle.Color = Color.FromArgb(42, 118, 189); + + //Apply known colors to the text in cells D5 to E8 + worksheet.Range["D5:E5"].CellStyle.Font.Color = ExcelKnownColors.White; + worksheet.Range["D7:E7"].CellStyle.Font.Color = ExcelKnownColors.White; + + //Make the text as bold from D5 to E8 + worksheet.Range["D5:E8"].CellStyle.Font.Bold = true; + + //Apply alignment to the cells from D5 to E8 + worksheet.Range["D5:E8"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + worksheet.Range["D5:E5"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter; + worksheet.Range["D7:E7"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter; + worksheet.Range["D6:E6"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop; + + //Enter value and applying formatting in the cell A7 + worksheet.Range["A7"].Text = " BILL TO"; + worksheet.Range["A7"].CellStyle.Color = Color.FromArgb(42, 118, 189); + worksheet.Range["A7"].CellStyle.Font.Bold = true; + worksheet.Range["A7"].CellStyle.Font.Color = ExcelKnownColors.White; + + //Apply alignment + worksheet.Range["A7"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft; + worksheet.Range["A7"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter; + + //Enter values in the cells A8 to A12 + worksheet.Range["A8"].Text = "Steyn"; + worksheet.Range["A9"].Text = "Great Lakes Food Market"; + worksheet.Range["A10"].Text = "20 Whitehall Rd"; + worksheet.Range["A11"].Text = "North Muskegon,USA"; + worksheet.Range["A12"].Text = "+1 231-654-0000"; + + //Create a Hyperlink for e-mail in the cell A13 + IHyperLink hyperlink = worksheet.HyperLinks.Add(worksheet.Range["A13"]); + hyperlink.Type = ExcelHyperLinkType.Url; + hyperlink.Address = "Steyn@greatlakes.com"; + hyperlink.ScreenTip = "Send Mail"; + + //Merge column A and B from row 15 to 22 + worksheet.Range["A15:B15"].Merge(); + worksheet.Range["A16:B16"].Merge(); + worksheet.Range["A17:B17"].Merge(); + worksheet.Range["A18:B18"].Merge(); + worksheet.Range["A19:B19"].Merge(); + worksheet.Range["A20:B20"].Merge(); + worksheet.Range["A21:B21"].Merge(); + worksheet.Range["A22:B22"].Merge(); + + //Enter details of products and prices + worksheet.Range["A15"].Text = " DESCRIPTION"; + worksheet.Range["C15"].Text = "QTY"; + worksheet.Range["D15"].Text = "UNIT PRICE"; + worksheet.Range["E15"].Text = "AMOUNT"; + worksheet.Range["A16"].Text = "Cabrales Cheese"; + worksheet.Range["A17"].Text = "Chocos"; + worksheet.Range["A18"].Text = "Pasta"; + worksheet.Range["A19"].Text = "Cereals"; + worksheet.Range["A20"].Text = "Ice Cream"; + worksheet.Range["C16"].Number = 3; + worksheet.Range["C17"].Number = 2; + worksheet.Range["C18"].Number = 1; + worksheet.Range["C19"].Number = 4; + worksheet.Range["C20"].Number = 3; + worksheet.Range["D16"].Number = 21; + worksheet.Range["D17"].Number = 54; + worksheet.Range["D18"].Number = 10; + worksheet.Range["D19"].Number = 20; + worksheet.Range["D20"].Number = 30; + worksheet.Range["D23"].Text = "Total"; + + //Apply number format + worksheet.Range["D16:E22"].NumberFormat = "$.00"; + worksheet.Range["E23"].NumberFormat = "$.00"; + + //Apply incremental formula for column Amount by multiplying Qty and UnitPrice + application.EnableIncrementalFormula = true; + worksheet.Range["E16:E20"].Formula = "=C16*D16"; + + //Formula for Sum the total + worksheet.Range["E23"].Formula = "=SUM(E16:E22)"; + + //Apply borders + worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin; + worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin; + worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].Color = ExcelKnownColors.Grey_25_percent; + worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].Color = ExcelKnownColors.Grey_25_percent; + worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin; + worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin; + worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].Color = ExcelKnownColors.Black; + worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].Color = ExcelKnownColors.Black; + + //Apply font setting for cells with product details + worksheet.Range["A3:E23"].CellStyle.Font.FontName = "Arial"; + worksheet.Range["A3:E23"].CellStyle.Font.Size = 10; + worksheet.Range["A15:E15"].CellStyle.Font.Color = ExcelKnownColors.White; + worksheet.Range["A15:E15"].CellStyle.Font.Bold = true; + worksheet.Range["D23:E23"].CellStyle.Font.Bold = true; + + //Apply cell color + worksheet.Range["A15:E15"].CellStyle.Color = Color.FromArgb(42, 118, 189); + + //Apply alignment to cells with product details + worksheet.Range["A15"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft; + worksheet.Range["C15:C22"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + worksheet.Range["D15:E15"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + + //Apply row height and column width to look good + worksheet.Range["A1"].ColumnWidth = 36; + worksheet.Range["B1"].ColumnWidth = 11; + worksheet.Range["C1"].ColumnWidth = 8; + worksheet.Range["D1:E1"].ColumnWidth = 18; + worksheet.Range["A1"].RowHeight = 47; + worksheet.Range["A2"].RowHeight = 15; + worksheet.Range["A3:A4"].RowHeight = 15; + worksheet.Range["A5"].RowHeight = 18; + worksheet.Range["A6"].RowHeight = 29; + worksheet.Range["A7"].RowHeight = 18; + worksheet.Range["A8"].RowHeight = 15; + worksheet.Range["A9:A14"].RowHeight = 15; + worksheet.Range["A15:A23"].RowHeight = 18; + + //Saving the Excel to the Stream + FileStream stream = new FileStream("CreateExcel.xlsx", FileMode.Create, FileAccess.Write); + workbook.SaveAs(stream); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET" %} +'Create an instance of ExcelEngine +Using excelEngine As ExcelEngine = New ExcelEngine() + + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + 'Create a workbook + Dim workbook As IWorkbook = application.Workbooks.Create(1) + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + 'Adding a picture + Dim imageStream As FileStream = New FileStream("AdventureCycles-Logo.png", FileMode.Open, FileAccess.Read) + Dim shape As IPictureShape = worksheet.Pictures.AddPicture(1, 1, imageStream, 20, 20) + + 'Disable gridlines in the worksheet + worksheet.IsGridLinesVisible = False + + 'Enter values to the cells from A3 to A5 + worksheet.Range("A3").Text = "46036 Michigan Ave" + worksheet.Range("A4").Text = "Canton, USA" + worksheet.Range("A5").Text = "Phone: +1 231-231-2310" + + 'Make the text bold + worksheet.Range("A3:A5").CellStyle.Font.Bold = True + + 'Merge cells + worksheet.Range("D1:E1").Merge() + + 'Enter text to the cell D1 and apply formatting. + worksheet.Range("D1").Text = "INVOICE" + worksheet.Range("D1").CellStyle.Font.Bold = True + worksheet.Range("D1").CellStyle.Font.RGBColor = Color.FromArgb(42, 118, 189) + worksheet.Range("D1").CellStyle.Font.Size = 35 + + 'Apply alignment in the cell D1 + worksheet.Range("D1").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight + worksheet.Range("D1").CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop + + 'Enter values to the cells from D5 to E8 + worksheet.Range("D5").Text = "INVOICE#" + worksheet.Range("E5").Text = "DATE" + worksheet.Range("D6").Number = 1028 + worksheet.Range("E6").Value = "12/31/2018" + worksheet.Range("D7").Text = "CUSTOMER ID" + worksheet.Range("E7").Text = "TERMS" + worksheet.Range("D8").Number = 564 + worksheet.Range("E8").Text = "Due Upon Receipt" + + 'Apply RGB back color to the cells from D5 to E8 + worksheet.Range("D5:E5").CellStyle.Color = Color.FromArgb(42, 118, 189) + worksheet.Range("D7:E7").CellStyle.Color = Color.FromArgb(42, 118, 189) + + 'Apply known colors to the text in cells D5 to E8 + worksheet.Range("D5:E5").CellStyle.Font.Color = ExcelKnownColors.White + worksheet.Range("D7:E7").CellStyle.Font.Color = ExcelKnownColors.White + + 'Make the text as bold from D5 to E8 + worksheet.Range("D5:E8").CellStyle.Font.Bold = True + + 'Apply alignment to the cells from D5 to E8 + worksheet.Range("D5:E8").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter + worksheet.Range("D5:E5").CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter + worksheet.Range("D7:E7").CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter + worksheet.Range("D6:E6").CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop + + 'Enter value and applying formatting in the cell A7 + worksheet.Range("A7").Text = " BILL TO" + worksheet.Range("A7").CellStyle.Color = Color.FromArgb(42, 118, 189) + worksheet.Range("A7").CellStyle.Font.Bold = True + worksheet.Range("A7").CellStyle.Font.Color = ExcelKnownColors.White + + 'Apply alignment + worksheet.Range("A7").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft + worksheet.Range("A7").CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter + + 'Enter values in the cells A8 to A12 + worksheet.Range("A8").Text = "Steyn" + worksheet.Range("A9").Text = "Great Lakes Food Market" + worksheet.Range("A10").Text = "20 Whitehall Rd" + worksheet.Range("A11").Text = "North Muskegon,USA" + worksheet.Range("A12").Text = "+1 231-654-0000" + + 'Create a Hyperlink for e-mail in the cell A13 + Dim hyperlink As IHyperLink = worksheet.HyperLinks.Add(worksheet.Range("A13")) + hyperlink.Type = ExcelHyperLinkType.Url + hyperlink.Address = "Steyn@greatlakes.com" + hyperlink.ScreenTip = "Send Mail" + + 'Merge column A and B from row 15 to 22 + worksheet.Range("A15:B15").Merge() + worksheet.Range("A16:B16").Merge() + worksheet.Range("A17:B17").Merge() + worksheet.Range("A18:B18").Merge() + worksheet.Range("A19:B19").Merge() + worksheet.Range("A20:B20").Merge() + worksheet.Range("A21:B21").Merge() + worksheet.Range("A22:B22").Merge() + + 'Enter details of products and prices + worksheet.Range("A15").Text = " DESCRIPTION" + worksheet.Range("C15").Text = "QTY" + worksheet.Range("D15").Text = "UNIT PRICE" + worksheet.Range("E15").Text = "AMOUNT" + worksheet.Range("A16").Text = "Cabrales Cheese" + worksheet.Range("A17").Text = "Chocos" + worksheet.Range("A18").Text = "Pasta" + worksheet.Range("A19").Text = "Cereals" + worksheet.Range("A20").Text = "Ice Cream" + worksheet.Range("C16").Number = 3 + worksheet.Range("C17").Number = 2 + worksheet.Range("C18").Number = 1 + worksheet.Range("C19").Number = 4 + worksheet.Range("C20").Number = 3 + worksheet.Range("D16").Number = 21 + worksheet.Range("D17").Number = 54 + worksheet.Range("D18").Number = 10 + worksheet.Range("D19").Number = 20 + worksheet.Range("D20").Number = 30 + worksheet.Range("D23").Text = "Total" + + 'Apply number format + worksheet.Range("D16:E22").NumberFormat = "$.00" + worksheet.Range("E23").NumberFormat = "$.00" + + 'Apply incremental formula for column Amount by multiplying Qty and UnitPrice + application.EnableIncrementalFormula = True + worksheet.Range("E16:E20").Formula = "=C16*D16" + + 'Formula for Sum the total + worksheet.Range("E23").Formula = "=SUM(E16:E22)" + + 'Apply borders + worksheet.Range("A16:E22").CellStyle.Borders(ExcelBordersIndex.EdgeTop).LineStyle = ExcelLineStyle.Thin + worksheet.Range("A16:E22").CellStyle.Borders(ExcelBordersIndex.EdgeBottom).LineStyle = ExcelLineStyle.Thin + worksheet.Range("A16:E22").CellStyle.Borders(ExcelBordersIndex.EdgeTop).Color = ExcelKnownColors.Grey_25_percent + worksheet.Range("A16:E22").CellStyle.Borders(ExcelBordersIndex.EdgeBottom).Color = ExcelKnownColors.Grey_25_percent + worksheet.Range("A23:E23").CellStyle.Borders(ExcelBordersIndex.EdgeTop).LineStyle = ExcelLineStyle.Thin + worksheet.Range("A23:E23").CellStyle.Borders(ExcelBordersIndex.EdgeBottom).LineStyle = ExcelLineStyle.Thin + worksheet.Range("A23:E23").CellStyle.Borders(ExcelBordersIndex.EdgeTop).Color = ExcelKnownColors.Black + worksheet.Range("A23:E23").CellStyle.Borders(ExcelBordersIndex.EdgeBottom).Color = ExcelKnownColors.Black + + 'Apply font setting for cells with product details + worksheet.Range("A3:E23").CellStyle.Font.FontName = "Arial" + worksheet.Range("A3:E23").CellStyle.Font.Size = 10 + worksheet.Range("A15:E15").CellStyle.Font.Color = ExcelKnownColors.White + worksheet.Range("A15:E15").CellStyle.Font.Bold = True + worksheet.Range("D23:E23").CellStyle.Font.Bold = True + + 'Apply cell color + worksheet.Range("A15:E15").CellStyle.Color = Color.FromArgb(42, 118, 189) + + 'Apply alignment to cells with product details + worksheet.Range("A15").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft + worksheet.Range("C15:C22").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter + worksheet.Range("D15:E15").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter + + 'Apply row height and column width to look good + worksheet.Range("A1").ColumnWidth = 36 + worksheet.Range("B1").ColumnWidth = 11 + worksheet.Range("C1").ColumnWidth = 8 + worksheet.Range("D1:E1").ColumnWidth = 18 + worksheet.Range("A1").RowHeight = 47 + worksheet.Range("A2").RowHeight = 15 + worksheet.Range("A3:A4").RowHeight = 15 + worksheet.Range("A5").RowHeight = 18 + worksheet.Range("A6").RowHeight = 29 + worksheet.Range("A7").RowHeight = 18 + worksheet.Range("A8").RowHeight = 15 + worksheet.Range("A9:A14").RowHeight = 15 + worksheet.Range("A15:A23").RowHeight = 18 + + 'Saving the Excel to the Stream + Dim stream As FileStream = New FileStream("CreateExcel.xlsx", FileMode.Create, FileAccess.Write) + workbook.SaveAs(stream); +End Using +{% endhighlight %} +{% endtabs %} +{% endcapture %} +{{ codesnippet3 | OrderList_Indent_Level_1 }} + +A complete working example of how to create an Excel file in Console Application using .NET Core in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Getting%20Started/Console/.NET%20Core/Create%20Excel). + +By executing the program, you will get the Excel file as below. +Output File + +## Create a simple Excel report using .NET Framework + +The below steps illustrates creating a simple Invoice formatted Excel document in console application using .NET Framework. + +Step 1: Create a new C# Console Application(.NET Framework) project. + +Create console application(.NET Framework) in Visual Studio + +Step 2: Name the project. + +Name the Application + +Step 3: Install the [Syncfusion.XlsIO.WinForms](https://www.nuget.org/packages/Syncfusion.XlsIO.WinForms) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +Install Syncfusion.XlsIO.WinForms NuGet Package + +N> Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion license key in your applications to use our components. + +Step 4: Include the following namespaces in the program.cs file. +{% capture codesnippet1 %} +{% tabs %} +{% highlight c# tabtitle="C#" %} +using Syncfusion.XlsIO; +using System.IO; +using System.Drawing; +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET" %} +Imports Syncfusion.XlsIO +Imports System.IO +Imports System.Drawing +{% endhighlight %} +{% endtabs %} +{% endcapture %} +{{ codesnippet1 | OrderList_Indent_Level_1 }} + +Step 5: Include the below code snippet in program.cs to create an Excel file. +{% capture codesnippet3 %} +{% tabs %} +{% highlight c# tabtitle="C#" %} +//Create an instance of ExcelEngine +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + //Create a workbook + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Adding a picture + FileStream imageStream = new FileStream("AdventureCycles-Logo.png", FileMode.Open, FileAccess.Read); + IPictureShape shape = worksheet.Pictures.AddPicture(1, 1, imageStream, 20, 20); + + //Disable gridlines in the worksheet + worksheet.IsGridLinesVisible = false; + + //Enter values to the cells from A3 to A5 + worksheet.Range["A3"].Text = "46036 Michigan Ave"; + worksheet.Range["A4"].Text = "Canton, USA"; + worksheet.Range["A5"].Text = "Phone: +1 231-231-2310"; + + //Make the text bold + worksheet.Range["A3:A5"].CellStyle.Font.Bold = true; + + //Merge cells + worksheet.Range["D1:E1"].Merge(); + + //Enter text to the cell D1 and apply formatting. + worksheet.Range["D1"].Text = "INVOICE"; + worksheet.Range["D1"].CellStyle.Font.Bold = true; + worksheet.Range["D1"].CellStyle.Font.RGBColor = Color.FromArgb(42, 118, 189); + worksheet.Range["D1"].CellStyle.Font.Size = 35; + + //Apply alignment in the cell D1 + worksheet.Range["D1"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight; + worksheet.Range["D1"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop; + + //Enter values to the cells from D5 to E8 + worksheet.Range["D5"].Text = "INVOICE#"; + worksheet.Range["E5"].Text = "DATE"; + worksheet.Range["D6"].Number = 1028; + worksheet.Range["E6"].Value = "12/31/2018"; + worksheet.Range["D7"].Text = "CUSTOMER ID"; + worksheet.Range["E7"].Text = "TERMS"; + worksheet.Range["D8"].Number = 564; + worksheet.Range["E8"].Text = "Due Upon Receipt"; + + //Apply RGB backcolor to the cells from D5 to E8 + worksheet.Range["D5:E5"].CellStyle.Color = Color.FromArgb(42, 118, 189); + worksheet.Range["D7:E7"].CellStyle.Color = Color.FromArgb(42, 118, 189); + + //Apply known colors to the text in cells D5 to E8 + worksheet.Range["D5:E5"].CellStyle.Font.Color = ExcelKnownColors.White; + worksheet.Range["D7:E7"].CellStyle.Font.Color = ExcelKnownColors.White; + + //Make the text as bold from D5 to E8 + worksheet.Range["D5:E8"].CellStyle.Font.Bold = true; + + //Apply alignment to the cells from D5 to E8 + worksheet.Range["D5:E8"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + worksheet.Range["D5:E5"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter; + worksheet.Range["D7:E7"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter; + worksheet.Range["D6:E6"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop; + + //Enter value and applying formatting in the cell A7 + worksheet.Range["A7"].Text = " BILL TO"; + worksheet.Range["A7"].CellStyle.Color = Color.FromArgb(42, 118, 189); + worksheet.Range["A7"].CellStyle.Font.Bold = true; + worksheet.Range["A7"].CellStyle.Font.Color = ExcelKnownColors.White; + + //Apply alignment + worksheet.Range["A7"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft; + worksheet.Range["A7"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter; + + //Enter values in the cells A8 to A12 + worksheet.Range["A8"].Text = "Steyn"; + worksheet.Range["A9"].Text = "Great Lakes Food Market"; + worksheet.Range["A10"].Text = "20 Whitehall Rd"; + worksheet.Range["A11"].Text = "North Muskegon,USA"; + worksheet.Range["A12"].Text = "+1 231-654-0000"; + + //Create a Hyperlink for e-mail in the cell A13 + IHyperLink hyperlink = worksheet.HyperLinks.Add(worksheet.Range["A13"]); + hyperlink.Type = ExcelHyperLinkType.Url; + hyperlink.Address = "Steyn@greatlakes.com"; + hyperlink.ScreenTip = "Send Mail"; + + //Merge column A and B from row 15 to 22 + worksheet.Range["A15:B15"].Merge(); + worksheet.Range["A16:B16"].Merge(); + worksheet.Range["A17:B17"].Merge(); + worksheet.Range["A18:B18"].Merge(); + worksheet.Range["A19:B19"].Merge(); + worksheet.Range["A20:B20"].Merge(); + worksheet.Range["A21:B21"].Merge(); + worksheet.Range["A22:B22"].Merge(); + + //Enter details of products and prices + worksheet.Range["A15"].Text = " DESCRIPTION"; + worksheet.Range["C15"].Text = "QTY"; + worksheet.Range["D15"].Text = "UNIT PRICE"; + worksheet.Range["E15"].Text = "AMOUNT"; + worksheet.Range["A16"].Text = "Cabrales Cheese"; + worksheet.Range["A17"].Text = "Chocos"; + worksheet.Range["A18"].Text = "Pasta"; + worksheet.Range["A19"].Text = "Cereals"; + worksheet.Range["A20"].Text = "Ice Cream"; + worksheet.Range["C16"].Number = 3; + worksheet.Range["C17"].Number = 2; + worksheet.Range["C18"].Number = 1; + worksheet.Range["C19"].Number = 4; + worksheet.Range["C20"].Number = 3; + worksheet.Range["D16"].Number = 21; + worksheet.Range["D17"].Number = 54; + worksheet.Range["D18"].Number = 10; + worksheet.Range["D19"].Number = 20; + worksheet.Range["D20"].Number = 30; + worksheet.Range["D23"].Text = "Total"; + + //Apply number format + worksheet.Range["D16:E22"].NumberFormat = "$.00"; + worksheet.Range["E23"].NumberFormat = "$.00"; + + //Apply incremental formula for column Amount by multiplying Qty and UnitPrice + application.EnableIncrementalFormula = true; + worksheet.Range["E16:E20"].Formula = "=C16*D16"; + + //Formula for Sum the total + worksheet.Range["E23"].Formula = "=SUM(E16:E22)"; + + //Apply borders + worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin; + worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin; + worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].Color = ExcelKnownColors.Grey_25_percent; + worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].Color = ExcelKnownColors.Grey_25_percent; + worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin; + worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin; + worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].Color = ExcelKnownColors.Black; + worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].Color = ExcelKnownColors.Black; + + //Apply font setting for cells with product details + worksheet.Range["A3:E23"].CellStyle.Font.FontName = "Arial"; + worksheet.Range["A3:E23"].CellStyle.Font.Size = 10; + worksheet.Range["A15:E15"].CellStyle.Font.Color = ExcelKnownColors.White; + worksheet.Range["A15:E15"].CellStyle.Font.Bold = true; + worksheet.Range["D23:E23"].CellStyle.Font.Bold = true; + + //Apply cell color + worksheet.Range["A15:E15"].CellStyle.Color = Color.FromArgb(42, 118, 189); + + //Apply alignment to cells with product details + worksheet.Range["A15"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft; + worksheet.Range["C15:C22"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + worksheet.Range["D15:E15"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + + //Apply row height and column width to look good + worksheet.Range["A1"].ColumnWidth = 36; + worksheet.Range["B1"].ColumnWidth = 11; + worksheet.Range["C1"].ColumnWidth = 8; + worksheet.Range["D1:E1"].ColumnWidth = 18; + worksheet.Range["A1"].RowHeight = 47; + worksheet.Range["A2"].RowHeight = 15; + worksheet.Range["A3:A4"].RowHeight = 15; + worksheet.Range["A5"].RowHeight = 18; + worksheet.Range["A6"].RowHeight = 29; + worksheet.Range["A7"].RowHeight = 18; + worksheet.Range["A8"].RowHeight = 15; + worksheet.Range["A9:A14"].RowHeight = 15; + worksheet.Range["A15:A23"].RowHeight = 18; + + //Saving the workbook + workbook.SaveAs("CreateExcel.xlsx"); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET" %} +'Create an instance of ExcelEngine +Using excelEngine As ExcelEngine = New ExcelEngine() + + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + 'Create a workbook + Dim workbook As IWorkbook = application.Workbooks.Create(1) + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + 'Adding a picture + Dim imageStream As FileStream = New FileStream("AdventureCycles-Logo.png", FileMode.Open, FileAccess.Read) + Dim shape As IPictureShape = worksheet.Pictures.AddPicture(1, 1, imageStream, 20, 20) + + 'Disable gridlines in the worksheet + worksheet.IsGridLinesVisible = False + + 'Enter values to the cells from A3 to A5 + worksheet.Range("A3").Text = "46036 Michigan Ave" + worksheet.Range("A4").Text = "Canton, USA" + worksheet.Range("A5").Text = "Phone: +1 231-231-2310" + + 'Make the text bold + worksheet.Range("A3:A5").CellStyle.Font.Bold = True + + 'Merge cells + worksheet.Range("D1:E1").Merge() + + 'Enter text to the cell D1 and apply formatting. + worksheet.Range("D1").Text = "INVOICE" + worksheet.Range("D1").CellStyle.Font.Bold = True + worksheet.Range("D1").CellStyle.Font.RGBColor = Color.FromArgb(42, 118, 189) + worksheet.Range("D1").CellStyle.Font.Size = 35 + + 'Apply alignment in the cell D1 + worksheet.Range("D1").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight + worksheet.Range("D1").CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop + + 'Enter values to the cells from D5 to E8 + worksheet.Range("D5").Text = "INVOICE#" + worksheet.Range("E5").Text = "DATE" + worksheet.Range("D6").Number = 1028 + worksheet.Range("E6").Value = "12/31/2018" + worksheet.Range("D7").Text = "CUSTOMER ID" + worksheet.Range("E7").Text = "TERMS" + worksheet.Range("D8").Number = 564 + worksheet.Range("E8").Text = "Due Upon Receipt" + + 'Apply RGB back color to the cells from D5 to E8 + worksheet.Range("D5:E5").CellStyle.Color = Color.FromArgb(42, 118, 189) + worksheet.Range("D7:E7").CellStyle.Color = Color.FromArgb(42, 118, 189) + + 'Apply known colors to the text in cells D5 to E8 + worksheet.Range("D5:E5").CellStyle.Font.Color = ExcelKnownColors.White + worksheet.Range("D7:E7").CellStyle.Font.Color = ExcelKnownColors.White + + 'Make the text as bold from D5 to E8 + worksheet.Range("D5:E8").CellStyle.Font.Bold = True + + 'Apply alignment to the cells from D5 to E8 + worksheet.Range("D5:E8").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter + worksheet.Range("D5:E5").CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter + worksheet.Range("D7:E7").CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter + worksheet.Range("D6:E6").CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop + + 'Enter value and applying formatting in the cell A7 + worksheet.Range("A7").Text = " BILL TO" + worksheet.Range("A7").CellStyle.Color = Color.FromArgb(42, 118, 189) + worksheet.Range("A7").CellStyle.Font.Bold = True + worksheet.Range("A7").CellStyle.Font.Color = ExcelKnownColors.White + + 'Apply alignment + worksheet.Range("A7").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft + worksheet.Range("A7").CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter + + 'Enter values in the cells A8 to A12 + worksheet.Range("A8").Text = "Steyn" + worksheet.Range("A9").Text = "Great Lakes Food Market" + worksheet.Range("A10").Text = "20 Whitehall Rd" + worksheet.Range("A11").Text = "North Muskegon,USA" + worksheet.Range("A12").Text = "+1 231-654-0000" + + 'Create a Hyperlink for e-mail in the cell A13 + Dim hyperlink As IHyperLink = worksheet.HyperLinks.Add(worksheet.Range("A13")) + hyperlink.Type = ExcelHyperLinkType.Url + hyperlink.Address = "Steyn@greatlakes.com" + hyperlink.ScreenTip = "Send Mail" + + 'Merge column A and B from row 15 to 22 + worksheet.Range("A15:B15").Merge() + worksheet.Range("A16:B16").Merge() + worksheet.Range("A17:B17").Merge() + worksheet.Range("A18:B18").Merge() + worksheet.Range("A19:B19").Merge() + worksheet.Range("A20:B20").Merge() + worksheet.Range("A21:B21").Merge() + worksheet.Range("A22:B22").Merge() + + 'Enter details of products and prices + worksheet.Range("A15").Text = " DESCRIPTION" + worksheet.Range("C15").Text = "QTY" + worksheet.Range("D15").Text = "UNIT PRICE" + worksheet.Range("E15").Text = "AMOUNT" + worksheet.Range("A16").Text = "Cabrales Cheese" + worksheet.Range("A17").Text = "Chocos" + worksheet.Range("A18").Text = "Pasta" + worksheet.Range("A19").Text = "Cereals" + worksheet.Range("A20").Text = "Ice Cream" + worksheet.Range("C16").Number = 3 + worksheet.Range("C17").Number = 2 + worksheet.Range("C18").Number = 1 + worksheet.Range("C19").Number = 4 + worksheet.Range("C20").Number = 3 + worksheet.Range("D16").Number = 21 + worksheet.Range("D17").Number = 54 + worksheet.Range("D18").Number = 10 + worksheet.Range("D19").Number = 20 + worksheet.Range("D20").Number = 30 + worksheet.Range("D23").Text = "Total" + + 'Apply number format + worksheet.Range("D16:E22").NumberFormat = "$.00" + worksheet.Range("E23").NumberFormat = "$.00" + + 'Apply incremental formula for column Amount by multiplying Qty and UnitPrice + application.EnableIncrementalFormula = True + worksheet.Range("E16:E20").Formula = "=C16*D16" + + 'Formula for Sum the total + worksheet.Range("E23").Formula = "=SUM(E16:E22)" + + 'Apply borders + worksheet.Range("A16:E22").CellStyle.Borders(ExcelBordersIndex.EdgeTop).LineStyle = ExcelLineStyle.Thin + worksheet.Range("A16:E22").CellStyle.Borders(ExcelBordersIndex.EdgeBottom).LineStyle = ExcelLineStyle.Thin + worksheet.Range("A16:E22").CellStyle.Borders(ExcelBordersIndex.EdgeTop).Color = ExcelKnownColors.Grey_25_percent + worksheet.Range("A16:E22").CellStyle.Borders(ExcelBordersIndex.EdgeBottom).Color = ExcelKnownColors.Grey_25_percent + worksheet.Range("A23:E23").CellStyle.Borders(ExcelBordersIndex.EdgeTop).LineStyle = ExcelLineStyle.Thin + worksheet.Range("A23:E23").CellStyle.Borders(ExcelBordersIndex.EdgeBottom).LineStyle = ExcelLineStyle.Thin + worksheet.Range("A23:E23").CellStyle.Borders(ExcelBordersIndex.EdgeTop).Color = ExcelKnownColors.Black + worksheet.Range("A23:E23").CellStyle.Borders(ExcelBordersIndex.EdgeBottom).Color = ExcelKnownColors.Black + + 'Apply font setting for cells with product details + worksheet.Range("A3:E23").CellStyle.Font.FontName = "Arial" + worksheet.Range("A3:E23").CellStyle.Font.Size = 10 + worksheet.Range("A15:E15").CellStyle.Font.Color = ExcelKnownColors.White + worksheet.Range("A15:E15").CellStyle.Font.Bold = True + worksheet.Range("D23:E23").CellStyle.Font.Bold = True + + 'Apply cell color + worksheet.Range("A15:E15").CellStyle.Color = Color.FromArgb(42, 118, 189) + + 'Apply alignment to cells with product details + worksheet.Range("A15").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft + worksheet.Range("C15:C22").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter + worksheet.Range("D15:E15").CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter + + 'Apply row height and column width to look good + worksheet.Range("A1").ColumnWidth = 36 + worksheet.Range("B1").ColumnWidth = 11 + worksheet.Range("C1").ColumnWidth = 8 + worksheet.Range("D1:E1").ColumnWidth = 18 + worksheet.Range("A1").RowHeight = 47 + worksheet.Range("A2").RowHeight = 15 + worksheet.Range("A3:A4").RowHeight = 15 + worksheet.Range("A5").RowHeight = 18 + worksheet.Range("A6").RowHeight = 29 + worksheet.Range("A7").RowHeight = 18 + worksheet.Range("A8").RowHeight = 15 + worksheet.Range("A9:A14").RowHeight = 15 + worksheet.Range("A15:A23").RowHeight = 18 + + 'Saving the workbook + workbook.SaveAs("CreateExcel.xlsx"); +End Using +{% endhighlight %} +{% endtabs %} +{% endcapture %} +{{ codesnippet3 | OrderList_Indent_Level_1 }} + +A complete working example of how to create an Excel file in Console Application using .NET Framework in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Getting%20Started/Console/.NET%20Framework/Create%20Excel). + +By executing the program, you will get the Excel file as below. +Output File + +Click [here](https://www.syncfusion.com/document-processing/excel-framework/net) to explore the rich set of Syncfusion Excel library (XlsIO) features. + +An online sample link to [create an Excel document](https://ej2.syncfusion.com/aspnetcore/Excel/Create#/material3) in ASP.NET Core. diff --git a/File-Formats/XlsIO/faqs/how-to-set-rounded-corner-for-chart-in-excel-document.md b/File-Formats/XlsIO/faqs/how-to-set-rounded-corner-for-chart-in-excel-document.md new file mode 100644 index 000000000..c85d010e9 --- /dev/null +++ b/File-Formats/XlsIO/faqs/how-to-set-rounded-corner-for-chart-in-excel-document.md @@ -0,0 +1,124 @@ +--- +title: How to set rounded corner for chart in Excel document | Syncfusion +description: Code example to set rounded corner for chart in Excel document using Syncfusion .NET Excel library (XlsIO). +platform: file-formats +control: XlsIO +documentation: UG +--- + +# How to set rounded corner for chart in Excel document? + +The following code snippet shows how to set rounded corner for chart in Excel document. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet sheet = workbook.Worksheets[0]; + + object[] xValues = new object[] { "Total Income", "Expenses", "Profit" }; + object[] yValues = new object[] { 2000, 1000, 1500 }; + + //Adding series and values + IChartShape chart = sheet.Charts.Add(); + IChartSerie serie = chart.Series.Add(ExcelChartType.Column_Clustered); + + //set the rounded border for the chart + chart.ChartArea.IsBorderCornersRound = true; + + //sets the top row of the chart + chart.TopRow = 5; + chart.BottomRow = 20; + chart.LeftColumn = 5; + chart.RightColumn = 13; + + //Enters the X and Y values directly + serie.EnteredDirectlyValues = yValues; + serie.EnteredDirectlyCategoryLabels = xValues; + + //Saving the workbook as stream + FileStream stream = new FileStream("Chart.xlsx", FileMode.Create, FileAccess.ReadWrite); + workbook.SaveAs(stream); + stream.Dispose(); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet sheet = workbook.Worksheets[0]; + + object[] xValues = new object[] { "Total Income", "Expenses", "Profit" }; + object[] yValues = new object[] { 2000, 1000, 1500 }; + + //Adding series and values + IChartShape chart = sheet.Charts.Add(); + IChartSerie serie = chart.Series.Add(ExcelChartType.Column_Clustered); + + //set the rounded border for the chart + chart.ChartArea.IsBorderCornersRound = true; + + //sets the top row of the chart + chart.TopRow = 5; + chart.BottomRow = 20; + chart.LeftColumn = 5; + chart.RightColumn = 13; + + //Enters the X and Y values directly + serie.EnteredDirectlyValues = yValues; + serie.EnteredDirectlyCategoryLabels = xValues; + + //Saving the workbook + workbook.SaveAs("Chart.xlsx"); + stream.Dispose(); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As ExcelEngine = New ExcelEngine() + Dim Application As IApplication = excelEngine.Excel + Application.DefaultVersion = ExcelVersion.Xlsx + Dim workbook As IWorkbook = Application.Workbooks.Create(1) + Dim sheet As IWorksheet = workbook.Worksheets(0) + + Dim xValues As Object() = New Object() {"Total Income", "Expenses", "Profit"} + Dim yValues As Object() = New Object() {2000, 1000, 1000} + + 'Adding series And values + Dim chart As IChartShape = sheet.Charts.Add() + Dim serie As IChartSerie = chart.Series.Add(ExcelChartType.Column_Clustered) + + 'set the rounded border for the chart + chart.ChartArea.IsBorderCornersRound = True + + 'sets the top row of the chart + chart.TopRow = 5 + chart.BottomRow = 20 + chart.LeftColumn = 5 + chart.RightColumn = 13 + + 'Enters the X And Y values directly + serie.EnteredDirectlyValues = yValues + serie.EnteredDirectlyCategoryLabels = xValues + + 'Saving the workbook as stream + Dim Stream As FileStream = New FileStream("Chart.xlsx", FileMode.Create, FileAccess.ReadWrite) + workbook.SaveAs(Stream) + Stream.Dispose() +End Using +{% endhighlight %} +{% endtabs %} + +## See Also + +* [How to change the border style for chart series](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#border-style-for-chart-series) +* [How to explode a Pie Chart](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#explode-a-pie-chart) +* [How to add picture to the chart and assign hyperlink](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#add-picture-to-chart-and-assign-hyperlink) +* [How to customizing chart and chart elements](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#customizing-chart-and-chart-elements) +* [How to add data label to the chart](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#add-datatable-to-chart)