diff --git a/CSV to Excel/CSV to Excel/.NET/CSV to Excel/README.md b/CSV to Excel/CSV to Excel/.NET/CSV to Excel/README.md new file mode 100644 index 00000000..c96753a2 --- /dev/null +++ b/CSV to Excel/CSV to Excel/.NET/CSV to Excel/README.md @@ -0,0 +1,38 @@ +# How to convert a CSV to an Excel file?? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to convert a CSV to an Excel fil. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.csv"), FileMode.Open, FileAccess.Read); + + //Open the CSV file + IWorkbook workbook = application.Workbooks.Open(inputStream, ","); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Saving the workbook as stream + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Convert Excel to JSON/Workbook to JSON with Schema/.NET/Workbook to JSON with Schema/README.md b/Convert Excel to JSON/Workbook to JSON with Schema/.NET/Workbook to JSON with Schema/README.md new file mode 100644 index 00000000..e4d31367 --- /dev/null +++ b/Convert Excel to JSON/Workbook to JSON with Schema/.NET/Workbook to JSON with Schema/README.md @@ -0,0 +1,51 @@ +# How to convert an Excel workbook to a JSON file with schema? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System; +using System.IO; +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to convert an Excel workbook to a JSON file with schema. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + #region save as JSON + //Saves the workbook to a JSON filestream, as schema by default + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema-default.json"), FileMode.Create, FileAccess.ReadWrite); + workbook.SaveAsJson(outputStream); + + //Saves the workbook to a JSON filestream as schema + FileStream stream1 = new FileStream(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema.json"), FileMode.Create, FileAccess.ReadWrite); + workbook.SaveAsJson(stream1, true); + #endregion + + //Dispose streams + outputStream.Dispose(); + stream1.Dispose(); + inputStream.Dispose(); + + #region Open JSON + //Open default JSON + + //Open JSON with Schema + #endregion +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Charts/Create Chart/.NET/Create Chart/README.md b/Create and Edit Charts/Create Chart/.NET/Create Chart/README.md new file mode 100644 index 00000000..7c2e82a0 --- /dev/null +++ b/Create and Edit Charts/Create Chart/.NET/Create Chart/README.md @@ -0,0 +1,68 @@ +# How to create a chart in the worksheet? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System.IO; +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to create a chart in the worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic); + IWorksheet sheet = workbook.Worksheets[0]; + + //Create a Chart + IChartShape chart = sheet.Charts.Add(); + + //Set Chart Type + chart.ChartType = ExcelChartType.Column_Clustered; + + //Set data range in the worksheet + chart.DataRange = sheet.Range["A1:C6"]; + chart.IsSeriesInRows = false; + + //Set Datalabels + IChartSerie serie1 = chart.Series[0]; + IChartSerie serie2 = chart.Series[1]; + + serie1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; + serie2.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; + serie1.DataPoints.DefaultDataPoint.DataLabels.Position = ExcelDataLabelPosition.Outside; + serie2.DataPoints.DefaultDataPoint.DataLabels.Position = ExcelDataLabelPosition.Outside; + + //Set Legend + chart.HasLegend = true; + chart.Legend.Position = ExcelLegendPosition.Bottom; + + //Positioning the chart in the worksheet + chart.TopRow = 8; + chart.LeftColumn = 1; + chart.BottomRow = 23; + chart.RightColumn = 8; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Chart.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Table/Create Table/.NET/Create Table/README.md b/Create and Edit Table/Create Table/.NET/Create Table/README.md new file mode 100644 index 00000000..71a24608 --- /dev/null +++ b/Create and Edit Table/Create Table/.NET/Create Table/README.md @@ -0,0 +1,43 @@ +# How to create a table in the worksheet? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System; +using System.IO; +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to create a table in the worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Create for the given data + IListObject table = worksheet.ListObjects.Create("Table1", worksheet["A1:C5"]); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CreateTable.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + inputStream.Dispose(); + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Data Validation/List Validation/.NET/List Validation/README.md b/Data Validation/List Validation/.NET/List Validation/README.md new file mode 100644 index 00000000..9ff06b6f --- /dev/null +++ b/Data Validation/List Validation/.NET/List Validation/README.md @@ -0,0 +1,50 @@ +# How to set list data validation in Excel? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System.IO; +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to set list data validation in Excel. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Data Validation for List + IDataValidation listValidation = worksheet.Range["C3"].DataValidation; + worksheet.Range["C1"].Text = "Data Validation List in C3"; + worksheet.Range["C1"].AutofitColumns(); + listValidation.ListOfValues = new string[] { "ListItem1", "ListItem2", "ListItem3" }; + + //Shows the error message + listValidation.ErrorBoxText = "Choose the value from the list"; + listValidation.ErrorBoxTitle = "ERROR"; + listValidation.PromptBoxText = "Data validation for list"; + listValidation.IsPromptBoxVisible = true; + listValidation.ShowPromptBox = true; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ListValidation.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Excel to CSV/Excel to CSV/.NET/Excel to CSV/README.md b/Excel to CSV/Excel to CSV/.NET/Excel to CSV/README.md new file mode 100644 index 00000000..69e16ef0 --- /dev/null +++ b/Excel to CSV/Excel to CSV/.NET/Excel to CSV/README.md @@ -0,0 +1,35 @@ +# How to convert an Excel file to CSV? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to convert an Excel file to CSV. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + + //Saving the workbook as streams + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.csv"), FileMode.Create, FileAccess.ReadWrite); + workbook.SaveAs(outputStream, ","); + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Excel to PDF/Workbook to PDF/.NET/Workbook to PDF/README.md b/Excel to PDF/Workbook to PDF/.NET/Workbook to PDF/README.md new file mode 100644 index 00000000..6412bdd2 --- /dev/null +++ b/Excel to PDF/Workbook to PDF/.NET/Workbook to PDF/README.md @@ -0,0 +1,46 @@ +# How to convert an Excel workbook to PDF? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System.IO; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; +using Syncfusion.Pdf; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to convert an Excel workbook to PDF. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + + //Initialize XlsIO renderer. + XlsIORenderer renderer = new XlsIORenderer(); + + //Convert Excel document into PDF document + PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/WorkbookToPDF.pdf"), FileMode.Create, FileAccess.Write); + pdfDocument.Save(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Getting Started/Console/.NET/Create Excel/README.md b/Getting Started/Console/.NET/Create Excel/README.md new file mode 100644 index 00000000..64d46202 --- /dev/null +++ b/Getting Started/Console/.NET/Create Excel/README.md @@ -0,0 +1,197 @@ +# How to create an Excel file in console application? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System; +using Syncfusion.XlsIO; +using Syncfusion.Drawing; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to create an Excel file in console application. +{% 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(Path.GetFullPath(@"Data/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 = "$0.00"; + worksheet.Range["E23"].NumberFormat = "$0.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(Path.GetFullPath(@"Output/Output.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(stream); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import Data to Template/Import Data Table/.NET/Import Data Table/README.md b/Import Data to Template/Import Data Table/.NET/Import Data Table/README.md new file mode 100644 index 00000000..b6f54d01 --- /dev/null +++ b/Import Data to Template/Import Data Table/.NET/Import Data Table/README.md @@ -0,0 +1,64 @@ +# How to bind data from a data table to a template marker? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System; +using System.Data; +using System.IO; +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to bind data from a data table to a template marker. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Create Template Marker Processor + ITemplateMarkersProcessor marker = workbook.CreateTemplateMarkersProcessor(); + + //Create an instance for Data table + DataTable reports = new DataTable(); + + //Add value to data table + reports.Columns.Add("SalesPerson"); + reports.Columns.Add("FromDate", typeof(DateTime)); + reports.Columns.Add("ToDate", typeof(DateTime)); + + reports.Rows.Add("Andy Bernard", new DateTime(2014, 09, 08), new DateTime(2014, 09, 11)); + reports.Rows.Add("Jim Halpert", new DateTime(2014, 09, 11), new DateTime(2014, 09, 15)); + reports.Rows.Add("Karen Fillippelli", new DateTime(2014, 09, 15), new DateTime(2014, 09, 20)); + reports.Rows.Add("Phyllis Lapin", new DateTime(2014, 09, 21), new DateTime(2014, 09, 25)); + reports.Rows.Add("Stanley Hudson", new DateTime(2014, 09, 26), new DateTime(2014, 09, 30)); + + //Add collection to marker variable + marker.AddVariable("Reports", reports, VariableTypeAction.DetectNumberFormat); + + //Process the markers in the template + marker.ApplyMarkers(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataTable.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/DataTable to Worksheet/.NET/DataTable to Worksheet/README.md b/Import and Export Data/DataTable to Worksheet/.NET/DataTable to Worksheet/README.md index f5b34dc7..bd30636e 100644 --- a/Import and Export Data/DataTable to Worksheet/.NET/DataTable to Worksheet/README.md +++ b/Import and Export Data/DataTable to Worksheet/.NET/DataTable to Worksheet/README.md @@ -16,28 +16,52 @@ using Syncfusion.XlsIO; Step 5: Include the below code snippet in **Program.cs** to import data from DataTable to Excel. {% tabs %} {% highlight c# tabtitle="C#" %} -using (ExcelEngine excelEngine = new ExcelEngine()) +class Program { - IApplication application = excelEngine.Excel; - application.DefaultVersion = ExcelVersion.Xlsx; - IWorkbook workbook = application.Workbooks.Create(1); - IWorksheet worksheet = workbook.Worksheets[0]; - - #region Import from Data Table - //Initialize the DataTable - DataTable table = SampleDataTable(); - //Import DataTable to the worksheet - worksheet.ImportDataTable(table, true, 1, 1); - #endregion - - #region Save - //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataTable.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); - #endregion - - //Dispose streams - outputStream.Dispose(); + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + #region Import from Data Table + //Initialize the DataTable + DataTable table = SampleDataTable(); + //Import DataTable to the worksheet + worksheet.ImportDataTable(table, true, 1, 1); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataTable.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + } + } + private static DataTable SampleDataTable() + { + //Create a DataTable with four columns + DataTable table = new DataTable(); + table.Columns.Add("Dosage", typeof(int)); + table.Columns.Add("Drug", typeof(string)); + table.Columns.Add("Patient", typeof(string)); + table.Columns.Add("Date", typeof(DateTime)); + + //Add five DataRows + table.Rows.Add(25, "Indocin", "David", DateTime.Now); + table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); + table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); + table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); + table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); + + return table; + } } {% endhighlight %} {% endtabs %} \ No newline at end of file diff --git a/Pivot Table/Create Pivot Table/.NET/Create Pivot Table/README.md b/Pivot Table/Create Pivot Table/.NET/Create Pivot Table/README.md new file mode 100644 index 00000000..4bc89a98 --- /dev/null +++ b/Pivot Table/Create Pivot Table/.NET/Create Pivot Table/README.md @@ -0,0 +1,55 @@ +# How to create a pivot table in the worksheet? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System.IO; +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to create a pivot table in the worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/PivotData.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + IWorksheet pivotSheet = workbook.Worksheets[1]; + + //Create Pivot cache with the given data range + IPivotCache cache = workbook.PivotCaches.Add(worksheet["A1:H50"]); + + //Create "PivotTable1" with the cache at the specified range + IPivotTable pivotTable = pivotSheet.PivotTables.Add("PivotTable1", pivotSheet["A1"], cache); + + //Add Pivot table fields (Row and Column fields) + pivotTable.Fields[2].Axis = PivotAxisTypes.Row; + pivotTable.Fields[6].Axis = PivotAxisTypes.Row; + pivotTable.Fields[3].Axis = PivotAxisTypes.Column; + + //Add data field + IPivotField field = pivotTable.Fields[5]; + pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/PivotTable.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Threaded Comments/Add Comment/.NET/Add Comment/README.md b/Threaded Comments/Add Comment/.NET/Add Comment/README.md new file mode 100644 index 00000000..3c9a52b5 --- /dev/null +++ b/Threaded Comments/Add Comment/.NET/Add Comment/README.md @@ -0,0 +1,44 @@ +# How to add threaded comments in the worksheet? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System; +using System.IO; +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to add threaded comments in the worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/CommentsTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic); + + IWorksheet worksheet = workbook.Worksheets[0]; + + //Add Threaded Comment + IThreadedComment threadedComment = worksheet.Range["H16"].AddThreadedComment("What is the reason for the higher total amount of \"desk\" in the west region?", "User1", DateTime.Now); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/AddComment.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Worksheet to Image/Worksheet to Image/.NET/Worksheet to Image/README.md b/Worksheet to Image/Worksheet to Image/.NET/Worksheet to Image/README.md new file mode 100644 index 00000000..9ed1ba02 --- /dev/null +++ b/Worksheet to Image/Worksheet to Image/.NET/Worksheet to Image/README.md @@ -0,0 +1,43 @@ +# How to convert an Excel worksheet to an image? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System.IO; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to convert an Excel worksheet to an image. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet sheet = workbook.Worksheets[0]; + + //Initialize XlsIORenderer + application.XlsIORenderer = new XlsIORenderer(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Image.png"), FileMode.Create, FileAccess.Write); + sheet.ConvertToImage(sheet.UsedRange, outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/XlsIO-Excel-Protect-UnProtect/Protect-Workbook/.NET/Protect-Workbook/README.md b/XlsIO-Excel-Protect-UnProtect/Protect-Workbook/.NET/Protect-Workbook/README.md new file mode 100644 index 00000000..f84342af --- /dev/null +++ b/XlsIO-Excel-Protect-UnProtect/Protect-Workbook/.NET/Protect-Workbook/README.md @@ -0,0 +1,45 @@ +# How to protect a workbook with a password? + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using System; +using System.IO; +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to protect a workbook with a password. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputWorkbook.xlsx"), FileMode.Open, FileAccess.ReadWrite); + + //Open Excel + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Protect workbook with password + workbook.Protect(true, true, "syncfusion"); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ProtectedWorkbook.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file