diff --git a/Conditional Formatting/Above and Below Average/.NET/Above and Below Average/README.md b/Conditional Formatting/Above and Below Average/.NET/Above and Below Average/README.md new file mode 100644 index 00000000..a44e3cbe --- /dev/null +++ b/Conditional Formatting/Above and Below Average/.NET/Above and Below Average/README.md @@ -0,0 +1,54 @@ +# How to apply conditional formatting for above or below average values? + +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 apply conditional formatting for values below average. +{% 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]; + + //Applying conditional formatting to "M6:M35" + IConditionalFormats formats = worksheet.Range["M6:M35"].ConditionalFormats; + IConditionalFormat format = formats.AddCondition(); + + //Applying above or below average rule in the conditional formatting + format.FormatType = ExcelCFType.AboveBelowAverage; + IAboveBelowAverage aboveBelowAverage = format.AboveBelowAverage; + + //Set AverageType as Below for AboveBelowAverage rule. + aboveBelowAverage.AverageType = ExcelCFAverageType.Below; + + //Set color for Conditional Formattting. + format.FontColorRGB = Syncfusion.Drawing.Color.FromArgb(255, 255, 255); + format.BackColorRGB = Syncfusion.Drawing.Color.FromArgb(166, 59, 38); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/AboveAndBelowAverage.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/Conditional Formatting/Above and Below Standard Deviation/.NET/Above and Below Standard Deviation/README.md b/Conditional Formatting/Above and Below Standard Deviation/.NET/Above and Below Standard Deviation/README.md new file mode 100644 index 00000000..4596cdd4 --- /dev/null +++ b/Conditional Formatting/Above and Below Standard Deviation/.NET/Above and Below Standard Deviation/README.md @@ -0,0 +1,57 @@ +# How to apply conditional formatting for values above or below the standard deviation? + +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 apply conditional formatting for values above the standard deviation. +{% 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]; + + //Applying conditional formatting to "M6:M35" + IConditionalFormats formats = worksheet.Range["M6:M35"].ConditionalFormats; + IConditionalFormat format = formats.AddCondition(); + + //Applying above or below average rule in the conditional formatting + format.FormatType = ExcelCFType.AboveBelowAverage; + IAboveBelowAverage aboveBelowAverage = format.AboveBelowAverage; + + //Set AverageType as AboveStdDev for AboveBelowAverage rule. + aboveBelowAverage.AverageType = ExcelCFAverageType.AboveStdDev; + + //Set value to StdDevValue property for AboveBelowAverage rule. + aboveBelowAverage.StdDevValue = 1; + + //Set color for Conditional Formattting. + format.FontColorRGB = Syncfusion.Drawing.Color.FromArgb(255, 255, 255); + format.BackColorRGB = Syncfusion.Drawing.Color.FromArgb(166, 59, 38); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/AboveAndBelowStandardDeviation.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/Conditional Formatting/Conditional Format with R1C1/.NET/Conditional Format with R1C1/README.md b/Conditional Formatting/Conditional Format with R1C1/.NET/Conditional Format with R1C1/README.md new file mode 100644 index 00000000..89aec5aa --- /dev/null +++ b/Conditional Formatting/Conditional Format with R1C1/.NET/Conditional Format with R1C1/README.md @@ -0,0 +1,43 @@ +# How to apply conditional formatting with formulas 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 apply conditional formatting with formulas in the worksheet. +{% 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]; + + //Using FormulaR1C1 property in Conditional Formatting + IConditionalFormats condition = worksheet.Range["E5:E18"].ConditionalFormats; + IConditionalFormat condition1 = condition.AddCondition(); + condition1.FirstFormulaR1C1 = "=R[1]C[0]"; + condition1.SecondFormulaR1C1 = "=R[1]C[1]"; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ConditionalFormat.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Conditional Formatting/Create Conditional Format/.NET/Create Conditional Format/README.md b/Conditional Formatting/Create Conditional Format/.NET/Create Conditional Format/README.md new file mode 100644 index 00000000..2fcb2955 --- /dev/null +++ b/Conditional Formatting/Create Conditional Format/.NET/Create Conditional Format/README.md @@ -0,0 +1,80 @@ +# How to apply conditional formatting 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 apply conditional formatting in the worksheet. +{% 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]; + + //Applying conditional formatting to "A1" + IConditionalFormats condition = worksheet.Range["A1"].ConditionalFormats; + IConditionalFormat condition1 = condition.AddCondition(); + + //Represents conditional format rule that the value in target range should be between 10 and 20 + condition1.FormatType = ExcelCFType.CellValue; + condition1.Operator = ExcelComparisonOperator.Between; + condition1.FirstFormula = "10"; + condition1.SecondFormula = "20"; + worksheet.Range["A1"].Text = "Enter a number between 10 and 20"; + + //Setting back color and font style to be applied for target range + condition1.BackColor = ExcelKnownColors.Light_orange; + condition1.IsBold = true; + condition1.IsItalic = true; + + //Applying conditional formatting to "A3" + condition = worksheet.Range["A3"].ConditionalFormats; + IConditionalFormat condition2 = condition.AddCondition(); + + //Represents conditional format rule that the cell value should be 1000 + condition2.FormatType = ExcelCFType.CellValue; + condition2.Operator = ExcelComparisonOperator.Equal; + condition2.FirstFormula = "1000"; + worksheet.Range["A3"].Text = "Enter the Number as 1000"; + + //Setting fill pattern and back color to target range + condition2.FillPattern = ExcelPattern.LightUpwardDiagonal; + condition2.BackColor = ExcelKnownColors.Yellow; + + //Applying conditional formatting to "A5" + condition = worksheet.Range["A5"].ConditionalFormats; + IConditionalFormat condition3 = condition.AddCondition(); + + //Setting conditional format rule that the cell value for target range should be less than or equal to 1000 + condition3.FormatType = ExcelCFType.CellValue; + condition3.Operator = ExcelComparisonOperator.LessOrEqual; + condition3.FirstFormula = "1000"; + worksheet.Range["A5"].Text = "Enter a Number which is less than or equal to 1000"; + + //Setting back color to target range + condition3.BackColor = ExcelKnownColors.Light_green; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ConditionalFormat.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Conditional Formatting/Read Conditional Format/.NET/Read Conditional Format/README.md b/Conditional Formatting/Read Conditional Format/.NET/Read Conditional Format/README.md new file mode 100644 index 00000000..542d0d42 --- /dev/null +++ b/Conditional Formatting/Read Conditional Format/.NET/Read Conditional Format/README.md @@ -0,0 +1,36 @@ +# How to read an existing conditional formatting from 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 read an existing conditional formatting from 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 worksheet = workbook.Worksheets[0]; + + //Read conditional formatting settings + string formatType = worksheet.Range["A1"].ConditionalFormats[0].FormatType.ToString(); + string cfOperator = worksheet.Range["A1"].ConditionalFormats[0].Operator.ToString(); + + //Dispose streams + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Conditional Formatting/Remove Conditional Format/.NET/README.md b/Conditional Formatting/Remove Conditional Format/.NET/README.md new file mode 100644 index 00000000..e8fe4614 --- /dev/null +++ b/Conditional Formatting/Remove Conditional Format/.NET/README.md @@ -0,0 +1,43 @@ +# How to remove an existing conditional formatting from 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 remove an existing conditional formatting from the specified range 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 worksheet = workbook.Worksheets[0]; + + //Removing conditional format for a specified range + worksheet.Range["E5"].ConditionalFormats.Remove(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveConditionalFormat.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/Conditional Formatting/Remove all Conditional Formats/.NET/Remove all Conditional Formats/README.md b/Conditional Formatting/Remove all Conditional Formats/.NET/Remove all Conditional Formats/README.md new file mode 100644 index 00000000..ac0ea70e --- /dev/null +++ b/Conditional Formatting/Remove all Conditional Formats/.NET/Remove all Conditional Formats/README.md @@ -0,0 +1,42 @@ +# How to remove conditional formatting from the entire 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 remove conditional formatting from the entire 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 worksheet = workbook.Worksheets[0]; + + //Removing Conditional Formatting Settings From Entire Sheet + worksheet.UsedRange.Clear(ExcelClearOptions.ClearConditionalFormats); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveAll.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/Conditional Formatting/Remove at Index/.NET/Remove at Index/README.md b/Conditional Formatting/Remove at Index/.NET/Remove at Index/README.md new file mode 100644 index 00000000..e88e5650 --- /dev/null +++ b/Conditional Formatting/Remove at Index/.NET/Remove at Index/README.md @@ -0,0 +1,42 @@ +# How to remove conditional formatting at the specified index 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 remove conditional formatting at the specified index 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 worksheet = workbook.Worksheets[0]; + + //Removing first conditional Format at the specified Range + worksheet.UsedRange.ConditionalFormats.RemoveAt(0); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveConditionalFormat.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/Conditional Formatting/Top To Bottom Percent/.NET/Top To Bottom Percent/README.md b/Conditional Formatting/Top To Bottom Percent/.NET/Top To Bottom Percent/README.md new file mode 100644 index 00000000..d9319002 --- /dev/null +++ b/Conditional Formatting/Top To Bottom Percent/.NET/Top To Bottom Percent/README.md @@ -0,0 +1,59 @@ +# How to apply conditional formatting to the top and bottom 'n%' rank values? + +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 apply conditional formatting to format the top 50 percentage rank values. +{% 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]; + + //Applying conditional formatting to "N6:N35". + IConditionalFormats formats = worksheet.Range["N6:N35"].ConditionalFormats; + IConditionalFormat format = formats.AddCondition(); + + //Applying top or bottom rule in the conditional formatting. + format.FormatType = ExcelCFType.TopBottom; + ITopBottom topBottom = format.TopBottom; + + //Set type as Bottom for TopBottom rule. + topBottom.Type = ExcelCFTopBottomType.Bottom; + + //Set true to Percent property for TopBottom rule. + topBottom.Percent = true; + + //Set rank value for the TopBottom rule. + topBottom.Rank = 50; + + //Set color for Conditional Formattting. + format.BackColorRGB = Syncfusion.Drawing.Color.FromArgb(51, 153, 102); + + #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/Conditional Formatting/Top to Bottom Rank/.NET/Top to Bottom Rank/README.md b/Conditional Formatting/Top to Bottom Rank/.NET/Top to Bottom Rank/README.md new file mode 100644 index 00000000..49464223 --- /dev/null +++ b/Conditional Formatting/Top to Bottom Rank/.NET/Top to Bottom Rank/README.md @@ -0,0 +1,56 @@ +# How to apply conditional formatting to the top and bottom N rank values? + +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 apply conditional formatting to format the top 10 rank values. +{% 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]; + + //Applying conditional formatting to "N6:N35". + IConditionalFormats formats = worksheet.Range["N6:N35"].ConditionalFormats; + IConditionalFormat format = formats.AddCondition(); + + //Applying top or bottom rule in the conditional formatting. + format.FormatType = ExcelCFType.TopBottom; + ITopBottom topBottom = format.TopBottom; + + //Set type as Top for TopBottom rule. + topBottom.Type = ExcelCFTopBottomType.Top; + + //Set rank value for the TopBottom rule. + topBottom.Rank = 10; + + //Set color for Conditional Formattting. + format.BackColorRGB = Syncfusion.Drawing.Color.FromArgb(51, 153, 102); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/TopToBottomRank.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/Conditional Formatting/Unique and Duplicate/.NET/Unique and Duplicate/README.md b/Conditional Formatting/Unique and Duplicate/.NET/Unique and Duplicate/README.md new file mode 100644 index 00000000..5ec4a2d9 --- /dev/null +++ b/Conditional Formatting/Unique and Duplicate/.NET/Unique and Duplicate/README.md @@ -0,0 +1,100 @@ +# How to highlight cells using conditional formatting? + +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 highlight cells by formatting unique and duplicate values using conditional formatting. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Excel2016; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Fill worksheet with data + worksheet.Range["A1:B1"].Merge(); + worksheet.Range["A1:B1"].CellStyle.Font.RGBColor = Color.FromArgb(255, 102, 102, 255); + worksheet.Range["A1:B1"].CellStyle.Font.Size = 14; + worksheet.Range["A1:B1"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + worksheet.Range["A1"].Text = "Global Internet Usage"; + worksheet.Range["A1:B1"].CellStyle.Font.Bold = true; + + worksheet.Range["A3:B21"].CellStyle.Font.RGBColor = Color.FromArgb(255, 64, 64, 64); + worksheet.Range["A3:B3"].CellStyle.Font.Bold = true; + worksheet.Range["B3"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight; + + worksheet.Range["A3"].Text = "Country"; + worksheet.Range["A4"].Text = "Northern America"; + worksheet.Range["A5"].Text = "Central America"; + worksheet.Range["A6"].Text = "The Caribbean"; + worksheet.Range["A7"].Text = "South America"; + worksheet.Range["A8"].Text = "Northern Europe"; + worksheet.Range["A9"].Text = "Eastern Europe"; + worksheet.Range["A10"].Text = "Western Europe"; + worksheet.Range["A11"].Text = "Southern Europe"; + worksheet.Range["A12"].Text = "Northern Africa"; + worksheet.Range["A13"].Text = "Eastern Africa"; + worksheet.Range["A14"].Text = "Middle Africa"; + worksheet.Range["A15"].Text = "Western Africa"; + worksheet.Range["A16"].Text = "Southern Africa"; + worksheet.Range["A17"].Text = "Central Asia"; + worksheet.Range["A18"].Text = "Eastern Asia"; + worksheet.Range["A19"].Text = "Southern Asia"; + worksheet.Range["A20"].Text = "SouthEast Asia"; + worksheet.Range["A21"].Text = "Oceania"; + + worksheet.Range["B3"].Text = "Usage"; + worksheet.Range["B4"].Value = "88%"; + worksheet.Range["B5"].Value = "61%"; + worksheet.Range["B6"].Value = "49%"; + worksheet.Range["B7"].Value = "68%"; + worksheet.Range["B8"].Value = "94%"; + worksheet.Range["B9"].Value = "74%"; + worksheet.Range["B10"].Value = "90%"; + worksheet.Range["B11"].Value = "77%"; + worksheet.Range["B12"].Value = "49%"; + worksheet.Range["B13"].Value = "27%"; + worksheet.Range["B14"].Value = "12%"; + worksheet.Range["B15"].Value = "39%"; + worksheet.Range["B16"].Value = "51%"; + worksheet.Range["B17"].Value = "50%"; + worksheet.Range["B18"].Value = "58%"; + worksheet.Range["B19"].Value = "36%"; + worksheet.Range["B20"].Value = "58%"; + worksheet.Range["B21"].Value = "69%"; + + worksheet.SetColumnWidth(1, 23.45); + worksheet.SetColumnWidth(2, 8.09); + + IConditionalFormats conditionalFormats = + worksheet.Range["A4:B21"].ConditionalFormats; + IConditionalFormat condition = conditionalFormats.AddCondition(); + + //conditional format to set duplicate format type + condition.FormatType = ExcelCFType.Duplicate; + condition.BackColorRGB = Color.FromArgb(255, 255, 199, 206); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/UniqueandDuplicate.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Argument Separator/.NET/Argument Separator/README.md b/Create and Edit Formulas/Argument Separator/.NET/Argument Separator/README.md new file mode 100644 index 00000000..20fe77ca --- /dev/null +++ b/Create and Edit Formulas/Argument Separator/.NET/Argument Separator/README.md @@ -0,0 +1,41 @@ +# How to set the argument separator in an Excel workbook? + +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 the argument separator in an Excel workbook. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + + #region Set Separators + //Setting the argument separator + workbook.SetSeparators(';', ','); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Calculated Column/.NET/Calculated Column/README.md b/Create and Edit Formulas/Calculated Column/.NET/Calculated Column/README.md new file mode 100644 index 00000000..9aad283d --- /dev/null +++ b/Create and Edit Formulas/Calculated Column/.NET/Calculated Column/README.md @@ -0,0 +1,57 @@ +# How to create a calculated column in a table.? + +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 calculated column in a table. +{% 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]; + + //Create Table with data in the given range + IListObject table = worksheet.ListObjects.Create("Table1", worksheet["A1:D3"]); + + //Create data + worksheet[1, 1].Text = "Products"; + worksheet[1, 2].Text = "Rate"; + worksheet[1, 3].Text = "Quantity"; + worksheet[1, 4].Text = "Total"; + + worksheet[2, 1].Text = "Item1"; + worksheet[2, 2].Number = 200; + worksheet[2, 3].Number = 2; + + worksheet[3, 1].Text = "Item2"; + worksheet[3, 2].Number = 300; + worksheet[3, 3].Number = 3; + + //Set table formula + table.Columns[3].CalculatedFormula = "SUM(20,[Rate]*[Quantity])"; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CalculatedColumn.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Calculated Value/.NET/Calculated Value/README.md b/Create and Edit Formulas/Calculated Value/.NET/Calculated Value/README.md new file mode 100644 index 00000000..09432b60 --- /dev/null +++ b/Create and Edit Formulas/Calculated Value/.NET/Calculated Value/README.md @@ -0,0 +1,54 @@ +# How to access the calculated value of a formula? + +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 access the calculated value of a formula. +{% 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 sheet = workbook.Worksheets[0]; + + sheet.Range["A1"].Value = "10"; + sheet.Range["B1"].Value = "20"; + + sheet.Range["C1"].Formula = "=A1+B1"; + + #region Calculated Value + sheet.EnableSheetCalculations(); + + //Returns the calculated value of a formula using the most current inputs + string calculatedValue = sheet["C1"].CalculatedValue; + sheet.Range["C3"].Value = "Calculated Value of the formula in C1 calculated through XlsIO is : " + calculatedValue; + + sheet.DisableSheetCalculations(); + #endregion + + sheet.Range["C3"].AutofitColumns(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Calculation Modes/.NET/Calculation Modes/README.md b/Create and Edit Formulas/Calculation Modes/.NET/Calculation Modes/README.md new file mode 100644 index 00000000..76971648 --- /dev/null +++ b/Create and Edit Formulas/Calculation Modes/.NET/Calculation Modes/README.md @@ -0,0 +1,40 @@ +# How to set calculation modes in an Excel workbook? + +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 the calculation mode for the worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + //Setting calculation mode for a workbook + workbook.CalculationOptions.CalculationMode = ExcelCalculationMode.Manual; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CalculationMode.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Cross Sheet Formula/.NET/Cross Sheet Formula/README.md b/Create and Edit Formulas/Cross Sheet Formula/.NET/Cross Sheet Formula/README.md new file mode 100644 index 00000000..6dd7d3fd --- /dev/null +++ b/Create and Edit Formulas/Cross Sheet Formula/.NET/Cross Sheet Formula/README.md @@ -0,0 +1,46 @@ +# How to set a formula in an Excel cell with a cross-sheet reference? + +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 a formula in an Excel cell with a cross-sheet reference. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(2); + IWorksheet sheet1 = workbook.Worksheets[0]; + IWorksheet sheet2 = workbook.Worksheets[1]; + + sheet1.Range["A2"].Value = "20"; + sheet2.Range["B2"].Value = "10"; + + #region Cross Sheet Formula + //Setting formula for the range with cross-sheet reference + sheet1.Range["C2"].Formula = "=SUM(Sheet2!B2,Sheet1!A2)"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Delete Named Range/.NET/Delete Named Range/README.md b/Create and Edit Formulas/Delete Named Range/.NET/Delete Named Range/README.md new file mode 100644 index 00000000..4be9fdac --- /dev/null +++ b/Create and Edit Formulas/Delete Named Range/.NET/Delete Named Range/README.md @@ -0,0 +1,47 @@ +# How to delete named ranges in an 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 delete a named range from a worksheet and the workbook. +{% 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]; + + //Deleting named range object + IName name = workbook.Names[0]; + name.Delete(); + + //Deleting named range from workbook + workbook.Names["BookLevelName3"].Delete(); + //Deleting named range from worksheet + sheet.Names["SheetLevelName2"].Delete(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/DeleteNamedRange.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/External Formula/.NET/External Formula/README.md b/Create and Edit Formulas/External Formula/.NET/External Formula/README.md new file mode 100644 index 00000000..6d574d1d --- /dev/null +++ b/Create and Edit Formulas/External Formula/.NET/External Formula/README.md @@ -0,0 +1,40 @@ +# How to insert an external formula into an Excel 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 insert an external formula into an Excel worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + //Write an external formula value + sheet.Range["C1"].Formula = "[C:/Syncfusion/One.xlsx]Sheet1!$A$1*5"; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExternalFormula.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Formula Array/.NET/Formula Array/README.md b/Create and Edit Formulas/Formula Array/.NET/Formula Array/README.md new file mode 100644 index 00000000..912fcdca --- /dev/null +++ b/Create and Edit Formulas/Formula Array/.NET/Formula Array/README.md @@ -0,0 +1,48 @@ +# How to insert an array formula into an Excel 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 insert an array formula into an Excel worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + #region Formula Array + //Assign array formula + sheet.Range["A1:D1"].FormulaArray = "{1,2,3,4}"; + + //Adding a named range for the range A1 to D1 + sheet.Names.Add("ArrayRange", sheet.Range["A1:D1"]); + + //Assign formula array with named range + sheet.Range["A2:D2"].FormulaArray = "ArrayRange+100"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Ignore Error/.NET/Ignore Error/README.md b/Create and Edit Formulas/Ignore Error/.NET/Ignore Error/README.md new file mode 100644 index 00000000..3288ab1d --- /dev/null +++ b/Create and Edit Formulas/Ignore Error/.NET/Ignore Error/README.md @@ -0,0 +1,41 @@ +# How to audit a formula and ignore errors in it? + +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 audit a formula and ignore any errors in it. +{% 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]; + + //Sets warning if number is entered as text. + sheet.Range["A2:D2"].IgnoreErrorOptions = ExcelIgnoreError.NumberAsText; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/FormulaAuditing.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Incremental Formula/.NET/Incremental Formula/README.md b/Create and Edit Formulas/Incremental Formula/.NET/Incremental Formula/README.md new file mode 100644 index 00000000..207b5b5f --- /dev/null +++ b/Create and Edit Formulas/Incremental Formula/.NET/Incremental Formula/README.md @@ -0,0 +1,44 @@ +# How to insert an incremental formula into an Excel 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 insert an incremental formula into an Excel worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + //Enables the incremental formula to updates the reference in cell + application.EnableIncrementalFormula = true; + + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet sheet = workbook.Worksheets[0]; + + //Formula are automatically increments by one for the range of cells + sheet["A1:A5"].Formula = "=B1+C1"; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/IncrementalFormula.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Iteration/.NET/Iteration/README.md b/Create and Edit Formulas/Iteration/.NET/Iteration/README.md new file mode 100644 index 00000000..4b641f93 --- /dev/null +++ b/Create and Edit Formulas/Iteration/.NET/Iteration/README.md @@ -0,0 +1,46 @@ +# How to enable iteration for the repeated recalculation of a 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 enable iteration for the repeated recalculation of a worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + //Setting iteration + workbook.CalculationOptions.IsIterationEnabled = true; + + //Number of times to recalculate + workbook.CalculationOptions.MaximumIteration = 99; + + //Number of acceptable changes + workbook.CalculationOptions.MaximumChange = 40; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Iteration.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Named Range/.NET/Named Range/README.md b/Create and Edit Formulas/Named Range/.NET/Named Range/README.md new file mode 100644 index 00000000..afdc13e6 --- /dev/null +++ b/Create and Edit Formulas/Named Range/.NET/Named Range/README.md @@ -0,0 +1,50 @@ +# How to create a named range and use it in a formula? + +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 workbook-level named range and use it in a formula. +{% 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 sheet = workbook.Worksheets[0]; + sheet.Range["A1"].Value = "10"; + sheet.Range["B1"].Value = "20"; + + //Defining a name in workbook level for the cell A1 + IName name1 = workbook.Names.Add("One"); + name1.RefersToRange = sheet.Range["A1"]; + + //Defining a name in workbook level for the cell B1 + IName name2 = workbook.Names.Add("Two"); + name2.RefersToRange = sheet.Range["B1"]; + + //Formula using defined names + sheet.Range["C1"].Formula = "=SUM(One,Two)"; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Set Formula/.NET/Set Formula/README.md b/Create and Edit Formulas/Set Formula/.NET/Set Formula/README.md new file mode 100644 index 00000000..d7a4d379 --- /dev/null +++ b/Create and Edit Formulas/Set Formula/.NET/Set Formula/README.md @@ -0,0 +1,46 @@ +# How to set a formula in an Excel cell? + +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 a formula in an Excel cell. +{% 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 sheet = workbook.Worksheets[0]; + + //Setting values to the cells + sheet.Range["A1"].Number = 10; + sheet.Range["B1"].Number = 10; + + #region Set Formula + //Setting formula in the cell + sheet.Range["C1"].Formula = "=SUM(A1,B1)"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Create and Edit Formulas/Types of Calculated Value/.NET/Types of Calculated Value/README.md b/Create and Edit Formulas/Types of Calculated Value/.NET/Types of Calculated Value/README.md new file mode 100644 index 00000000..5f6565c9 --- /dev/null +++ b/Create and Edit Formulas/Types of Calculated Value/.NET/Types of Calculated Value/README.md @@ -0,0 +1,54 @@ +# How to access the calculated value of a formula in different formats? + +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 access the calculated value of a formula in different formats. +{% 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 sheet = workbook.Worksheets[0]; + + sheet.Range["A1"].Value = "10"; + sheet.Range["B1"].Value = "20"; + + sheet.Range["C1"].Formula = "=A1+B1"; + + #region Calculated Value + sheet.EnableSheetCalculations(); + + //Returns the calculated value of a formula using the most current inputs + string calculatedValue = sheet["C1"].CalculatedValue; + sheet.Range["C3"].Value = "Calculated Value of the formula in C1 calculated through XlsIO is : " + calculatedValue; + + sheet.DisableSheetCalculations(); + #endregion + + sheet.Range["C3"].AutofitColumns(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Alignment/.NET/Alignment/README.md b/Editing Excel cell-styles/Alignment/.NET/Alignment/README.md new file mode 100644 index 00000000..a99c3394 --- /dev/null +++ b/Editing Excel cell-styles/Alignment/.NET/Alignment/README.md @@ -0,0 +1,80 @@ +# How to apply cell text alignment 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to apply cell text alignment in the worksheet. +{% 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]; + + worksheet.Range["A2"].Text = "HAlignCenter"; + worksheet.Range["A4"].Text = "HAlignFill"; + worksheet.Range["A6"].Text = "HAlignRight"; + worksheet.Range["A8"].Text = "HAlignCenterAcrossSelection"; + worksheet.Range["B2"].Text = "VAlignCenter"; + worksheet.Range["B4"].Text = "VAlignFill"; + worksheet.Range["B6"].Text = "VAlignTop"; + worksheet.Range["B8"].Text = "VAlignCenterAcrossSelection"; + worksheet.Range["C2"].Text = "Text Rotation to 60 degree"; + worksheet.Range["C4"].Text = "Text Rotation to 90 degree"; + worksheet.Range["C6"].Text = "Indent level is 6"; + worksheet.Range["D2"].Text = "Text Direction(LeftToRight)"; + worksheet.Range["D3"].Text = "Text Direction(RightToLeft)"; + worksheet.Range["D4"].Text = "Text Direction(Context)"; + + #region Alignment + //Text Alignment Setting (Horizontal Alignment) + worksheet.Range["A2"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + worksheet.Range["A4"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignFill; + worksheet.Range["A6"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight; + worksheet.Range["A8"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenterAcrossSelection; + + //Text Alignment Setting (Vertical Alignment) + worksheet.Range["B2"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignBottom; + worksheet.Range["B4"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter; + worksheet.Range["B6"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignTop; + worksheet.Range["B8"].CellStyle.VerticalAlignment = ExcelVAlign.VAlignDistributed; + + //Text Orientation Settings + worksheet.Range["C2"].CellStyle.Rotation = 60; + worksheet.Range["C4"].CellStyle.Rotation = 90; + + //Text Indent Setting + worksheet.Range["C6"].CellStyle.IndentLevel = 6; + + //Text Direction Setting + worksheet.Range["D2"].CellStyle.ReadingOrder = ExcelReadingOrderType.LeftToRight; + worksheet.Range["D3"].CellStyle.ReadingOrder = ExcelReadingOrderType.RightToLeft; + worksheet.Range["D4"].CellStyle.ReadingOrder = ExcelReadingOrderType.Context; + #endregion + + worksheet.UsedRange.AutofitColumns(); + worksheet.UsedRange.AutofitRows(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Alignment.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/AutoFit Rows and Columns/.NET/AutoFit Rows and Columns/README.md b/Editing Excel cell-styles/AutoFit Rows and Columns/.NET/AutoFit Rows and Columns/README.md new file mode 100644 index 00000000..5064eb2e --- /dev/null +++ b/Editing Excel cell-styles/AutoFit Rows and Columns/.NET/AutoFit Rows and Columns/README.md @@ -0,0 +1,49 @@ +# How to autofit rows and columns 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to autofit rows and columns in the worksheet. +{% 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]; + + #region AutoFit Row + //Auto-fit rows + worksheet.Range["A2"].Text = "Fit the content to row"; + worksheet.Range["A2"].WrapText = true; + worksheet.Range["A2"].AutofitRows(); + #endregion + + #region AutoFit Column + //Auto-fit columns + worksheet.Range["B4"].Text = "Fit the content to column"; + worksheet.Range["B4"].AutofitColumns(); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/AutoFit.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Border Settings/.NET/Border Settings/README.md b/Editing Excel cell-styles/Border Settings/.NET/Border Settings/README.md new file mode 100644 index 00000000..2371a990 --- /dev/null +++ b/Editing Excel cell-styles/Border Settings/.NET/Border Settings/README.md @@ -0,0 +1,69 @@ +# How to apply different border settings 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to apply different border settings in the worksheet. +{% 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]; + + #region Border Settings + //Apply borders + worksheet.Range["A2"].CellStyle.Borders.LineStyle = ExcelLineStyle.Medium; + worksheet.Range["A4"].CellStyle.Borders.LineStyle = ExcelLineStyle.Double; + worksheet.Range["A6"].CellStyle.Borders.LineStyle = ExcelLineStyle.Dash_dot; + worksheet.Range["A8"].CellStyle.Borders.LineStyle = ExcelLineStyle.Thick; + worksheet.Range["C2"].CellStyle.Borders.LineStyle = ExcelLineStyle.Slanted_dash_dot; + worksheet.Range["C4"].CellStyle.Borders.LineStyle = ExcelLineStyle.Hair; + worksheet.Range["C6"].CellStyle.Borders.LineStyle = ExcelLineStyle.Medium_dash_dot_dot; + worksheet.Range["C8"].CellStyle.Borders.LineStyle = ExcelLineStyle.Thin; + + //Apply Border using Border Index + //Top Border + worksheet.Range["E2"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Medium; + //Left Border + worksheet.Range["E4"].CellStyle.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Double; + //Bottom Border + worksheet.Range["E6"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Dashed; + //Right Border + worksheet.Range["E8"].CellStyle.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thick; + //DiagonalUp Border + worksheet.Range["E10"].CellStyle.Borders[ExcelBordersIndex.DiagonalUp].LineStyle = ExcelLineStyle.Thin; + //DiagonalDown Border + worksheet.Range["E12"].CellStyle.Borders[ExcelBordersIndex.DiagonalDown].LineStyle = ExcelLineStyle.Dotted; + + //Apply border color + worksheet.Range["A2"].CellStyle.Borders.Color = ExcelKnownColors.Blue; + + //Setting the Border as Range + worksheet.Range["G2:I8"].BorderAround(); + worksheet.Range["G2:I8"].BorderInside(ExcelLineStyle.Dash_dot, ExcelKnownColors.Red); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/BorderSettings.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Color Settings/.NET/Color Settings/README.md b/Editing Excel cell-styles/Color Settings/.NET/Color Settings/README.md new file mode 100644 index 00000000..b2ea26a1 --- /dev/null +++ b/Editing Excel cell-styles/Color Settings/.NET/Color Settings/README.md @@ -0,0 +1,47 @@ +# How to apply different color settings 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to apply different color settings in the worksheet. +{% 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]; + + #region Color Settings + //Apply cell back color + worksheet.Range["A1"].CellStyle.ColorIndex = ExcelKnownColors.Aqua; + + //Apply cell pattern + worksheet.Range["A2"].CellStyle.FillPattern = ExcelPattern.Angle; + + //Apply cell fore color + worksheet.Range["A2"].CellStyle.PatternColorIndex = ExcelKnownColors.Green; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ColorSettings.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Create Style/.NET/Create Style/README.md b/Editing Excel cell-styles/Create Style/.NET/Create Style/README.md new file mode 100644 index 00000000..23256692 --- /dev/null +++ b/Editing Excel cell-styles/Create Style/.NET/Create Style/README.md @@ -0,0 +1,45 @@ +# How to create and apply a cell style 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to create and apply a cell style in the worksheet. +{% 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]; + + #region Create Style + //Creating a new style with cell back color, fill pattern and font attribute + IStyle style = workbook.Styles.Add("NewStyle"); + style.Color = Syncfusion.Drawing.Color.LightGreen; + style.FillPattern = ExcelPattern.DarkUpwardDiagonal; + style.Font.Bold = true; + worksheet.Range["B2"].CellStyle = style; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CreateStyle.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Font Settings/.NET/Font Settings/README.md b/Editing Excel cell-styles/Font Settings/.NET/Font Settings/README.md new file mode 100644 index 00000000..4ad0f983 --- /dev/null +++ b/Editing Excel cell-styles/Font Settings/.NET/Font Settings/README.md @@ -0,0 +1,69 @@ +# How to apply different font settings 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to apply different font settings in the worksheet. +{% 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]; + + //Adding text for a range + worksheet.Range["A1:B6"].Text = "Hello World"; + + #region Font Settings + //Setting Font Type + worksheet.Range["A1"].CellStyle.Font.FontName = "Arial Black"; + worksheet.Range["A3"].CellStyle.Font.FontName = "Castellar"; + + //Setting Font Styles + worksheet.Range["A2"].CellStyle.Font.Bold = true; + worksheet.Range["A4"].CellStyle.Font.Italic = true; + + //Setting Font Size + worksheet.Range["A5"].CellStyle.Font.Size = 18; + + //Setting Font Effects + worksheet.Range["A6"].CellStyle.Font.Strikethrough = true; + worksheet.Range["B3"].CellStyle.Font.Subscript = true; + worksheet.Range["B5"].CellStyle.Font.Superscript = true; + + //Setting UnderLine Types + worksheet.Range["B1"].CellStyle.Font.Underline = ExcelUnderline.Double; + worksheet.Range["B2"].CellStyle.Font.Underline = ExcelUnderline.Single; + worksheet.Range["B4"].CellStyle.Font.Underline = ExcelUnderline.DoubleAccounting; + worksheet.Range["B6"].CellStyle.Font.Underline = ExcelUnderline.SingleAccounting; + + //Setting Font Color + worksheet.Range["B6"].CellStyle.Font.Color = ExcelKnownColors.Green; + #endregion + + worksheet.UsedRange.AutofitColumns(); + worksheet.UsedRange.AutofitRows(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/FontSettings.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Global Style/.NET/Global Style/README.md b/Editing Excel cell-styles/Global Style/.NET/Global Style/README.md new file mode 100644 index 00000000..897ed22a --- /dev/null +++ b/Editing Excel cell-styles/Global Style/.NET/Global Style/README.md @@ -0,0 +1,103 @@ +# How to apply a global style 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to apply a global style in the worksheet. +{% 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]; + + //Adding values to a worksheet range + worksheet.Range["A1"].Text = "CustomerID"; + worksheet.Range["B1"].Text = "CompanyName"; + worksheet.Range["C1"].Text = "ContactName"; + worksheet.Range["D1"].Text = "TotalSales (in USD)"; + worksheet.Range["A2"].Text = "ALFKI"; + worksheet.Range["A3"].Text = "ANATR"; + worksheet.Range["A4"].Text = "BONAP"; + worksheet.Range["A5"].Text = "BSBEV"; + worksheet.Range["B2"].Text = "Alfred Futterkiste"; + worksheet.Range["B3"].Text = "Ana Trujillo Emparedados y helados"; + worksheet.Range["B4"].Text = "Bon App"; + worksheet.Range["B5"].Text = "B's Beverages"; + worksheet.Range["C2"].Text = "Maria Anders"; + worksheet.Range["C3"].Text = "Ana Trujillo"; + worksheet.Range["C4"].Text = "Laurence Lebihan"; + worksheet.Range["C5"].Text = "Victoria Ashworth"; + worksheet.Range["D2"].Number = 15000.107; + worksheet.Range["D3"].Number = 27000.208; + worksheet.Range["D4"].Number = 18700.256; + worksheet.Range["D5"].Number = 25000.450; + + #region Global Style + //Formatting + //Global styles should be used when the same style needs to be applied to more than one cell. This usage of a global style reduces memory usage. + //Add custom colors to the palette + workbook.SetPaletteColor(8, Color.FromArgb(255, 174, 33)); + + //Defining header style + IStyle headerStyle = workbook.Styles.Add("HeaderStyle"); + headerStyle.BeginUpdate(); + headerStyle.Color = Color.FromArgb(255, 174, 33); + headerStyle.Font.Bold = true; + headerStyle.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thin; + headerStyle.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thin; + headerStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin; + headerStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin; + headerStyle.EndUpdate(); + + //Add custom colors to the palette + workbook.SetPaletteColor(9, Color.FromArgb(239, 243, 247)); + + //Defining body style + IStyle bodyStyle = workbook.Styles.Add("BodyStyle"); + bodyStyle.BeginUpdate(); + bodyStyle.Color = Color.FromArgb(239, 243, 247); + bodyStyle.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thin; + bodyStyle.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thin; + bodyStyle.EndUpdate(); + + //Defining number format style + IStyle numberformatStyle = workbook.Styles.Add("NumberFormatStyle"); + numberformatStyle.BeginUpdate(); + numberformatStyle.NumberFormat = "0.00"; + numberformatStyle.EndUpdate(); + + //Apply Header style + worksheet.Rows[0].CellStyle = headerStyle; + //Apply Body Style + worksheet.Range["A2:C5"].CellStyle = bodyStyle; + //Apply Number Format style + worksheet.Range["D2:D5"].CellStyle = numberformatStyle; + #endregion + + //Auto-fit the columns + worksheet.UsedRange.AutofitColumns(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/GlobalStyle.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/HTML String Formatting/.NET/HTML String Formatting/README.md b/Editing Excel cell-styles/HTML String Formatting/.NET/HTML String Formatting/README.md new file mode 100644 index 00000000..1e1b8128 --- /dev/null +++ b/Editing Excel cell-styles/HTML String Formatting/.NET/HTML String Formatting/README.md @@ -0,0 +1,42 @@ +# How to apply HTML string formatting 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to apply HTML string formatting in the worksheet. +{% 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]; + + //Add HTML string + worksheet.Range["A1"].HtmlString = "Welcome Syncfusion"; + + //Assign HTML string as text to different range + worksheet.Range["A2"].Text = worksheet.Range["A1"].HtmlString; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HTMLString.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Hide Cell Content/.NET/Hide Cell Content/README.md b/Editing Excel cell-styles/Hide Cell Content/.NET/Hide Cell Content/README.md new file mode 100644 index 00000000..69cf5a2c --- /dev/null +++ b/Editing Excel cell-styles/Hide Cell Content/.NET/Hide Cell Content/README.md @@ -0,0 +1,44 @@ +# How to hide cell content by applying a number format 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to hide cell content by applying a number format in the worksheet. +{% 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]; + + #region Hide Cell Content + //Assign values to a range of cells in the worksheet + worksheet.Range["A1:A10"].Text = "Hide Cell Content"; + + //Apply number format for the cell to hide its content + worksheet.Range["A5"].NumberFormat = ";;;"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HideCellContent.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Merge and UnMerge/.NET/Merge and UnMerge/README.md b/Editing Excel cell-styles/Merge and UnMerge/.NET/Merge and UnMerge/README.md new file mode 100644 index 00000000..15582b39 --- /dev/null +++ b/Editing Excel cell-styles/Merge and UnMerge/.NET/Merge and UnMerge/README.md @@ -0,0 +1,47 @@ +# How to merge and unmerge cells 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to merge and unmerge cells in the worksheet. +{% 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]; + + #region Merge + //Merging cells + worksheet.Range["A5:E10"].Merge(); + worksheet.Range["A15:E20"].Merge(); + #endregion + + #region UnMerge + //Un-Merging merged cells + worksheet.Range["A5:E10"].UnMerge(); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/MergeandUnMerge.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Number Format/.NET/Number Format/README.md b/Editing Excel cell-styles/Number Format/.NET/Number Format/README.md new file mode 100644 index 00000000..c279605a --- /dev/null +++ b/Editing Excel cell-styles/Number Format/.NET/Number Format/README.md @@ -0,0 +1,104 @@ +# How to apply a number format 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to apply a number format in the worksheet. +{% 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]; + + worksheet.Range["A1"].Text = "DATA"; + worksheet.Range["B1"].Text = "NUMBER FORMAT APPLIED"; + worksheet.Range["C1"].Text = "RESULT"; + IStyle headingStyle = workbook.Styles.Add("HeadingStyle"); + headingStyle.Font.Bold = true; + headingStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + worksheet.Range["A1:C1"].CellStyle = headingStyle; + + #region Applying Number Format + //Applying different number formats + worksheet.Range["A2"].Text = "1000000.00075"; + worksheet.Range["B2"].Text = "0.00"; + worksheet.Range["C2"].NumberFormat = "0.00"; + worksheet.Range["C2"].Number = 1000000.00075; + worksheet.Range["A3"].Text = "1000000.500"; + worksheet.Range["B3"].Text = "###,##"; + worksheet.Range["C3"].NumberFormat = "###,##"; + worksheet.Range["C3"].Number = 1000000.500; + worksheet.Range["A5"].Text = "10000"; + worksheet.Range["B5"].Text = "0.00"; + worksheet.Range["C5"].NumberFormat = "0.00"; + worksheet.Range["C5"].Number = 10000; + worksheet.Range["A6"].Text = "-500"; + worksheet.Range["B6"].Text = "[Blue]#,##0"; + worksheet.Range["C6"].NumberFormat = "[Blue]#,##0"; + worksheet.Range["C6"].Number = -500; + worksheet.Range["A7"].Text = "0.000000000000000000001234567890"; + worksheet.Range["B7"].Text = "0.000000000000000000000000000000"; + worksheet.Range["C7"].NumberFormat = "0.000000000000000000000000000000"; + worksheet.Range["C7"].Number = 0.000000000000000000001234567890; + worksheet.Range["A9"].Text = "1.20"; + worksheet.Range["B9"].Text = "0.00E+00"; + worksheet.Range["C9"].NumberFormat = "0.00E+00"; + worksheet.Range["C9"].Number = 1.20; + + //Applying percentage format + worksheet.Range["A10"].Text = "1.20"; + worksheet.Range["B10"].Text = "0.00%"; + worksheet.Range["C10"].NumberFormat = "0.00%"; + worksheet.Range["C10"].Number = 1.20; + + //Applying date format + worksheet.Range["A11"].Text = new DateTime(2005, 12, 25).ToString(); + worksheet.Range["B11"].Text = "m/d/yyyy"; + worksheet.Range["C11"].NumberFormat = "m/d/yyyy"; + worksheet.Range["C11"].DateTime = new DateTime(2005, 12, 25); + + //Applying currency format + worksheet.Range["A12"].Text = "1.20"; + worksheet.Range["B12"].Text = "$#,##0.00"; + worksheet.Range["C12"].NumberFormat = "$#,##0.00"; + worksheet.Range["C12"].Number = 1.20; + + //Applying accounting format + worksheet.Range["A12"].Text = "234"; + worksheet.Range["B12"].Text = "_($* #,##0_)"; + worksheet.Range["C12"].NumberFormat = "_($* #,##0_)"; + worksheet.Range["C12"].Number = 234; + #endregion + + #region Accessing Value with Number Format + //Get display text of the cell + string text = worksheet.Range["C12"].DisplayText; + #endregion + + //Fit column width to data + worksheet.UsedRange.AutofitColumns(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/NumberFormat.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Rich Text/.NET/Rich Text/README.md b/Editing Excel cell-styles/Rich Text/.NET/Rich Text/README.md new file mode 100644 index 00000000..a24d0846 --- /dev/null +++ b/Editing Excel cell-styles/Rich Text/.NET/Rich Text/README.md @@ -0,0 +1,55 @@ +# How to apply rich text formatting 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to apply rich text formatting in the worksheet. +{% 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]; + + //Add Text + IRange range = worksheet.Range["A1"]; + range.Text = "RichText"; + IRichTextString richText = range.RichText; + + //Formatting first 4 characters. + IFont redFont = workbook.CreateFont(); + redFont.Bold = true; + redFont.Italic = true; + redFont.RGBColor = Syncfusion.Drawing.Color.Red; + richText.SetFont(0, 3, redFont); + + //Formatting last 4 characters. + IFont blueFont = workbook.CreateFont(); + blueFont.Bold = true; + blueFont.Italic = true; + blueFont.RGBColor = Syncfusion.Drawing.Color.Blue; + richText.SetFont(4, 7, blueFont); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/RichText.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Row and Column Style/.NET/Row and Column Style/README.md b/Editing Excel cell-styles/Row and Column Style/.NET/Row and Column Style/README.md new file mode 100644 index 00000000..e8d8e414 --- /dev/null +++ b/Editing Excel cell-styles/Row and Column Style/.NET/Row and Column Style/README.md @@ -0,0 +1,49 @@ +# How to apply the default style to rows and columns? + +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 apply the default style to rows and columns in the worksheet. +{% 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]; + + #region Row and Column Style + //Define new styles to apply in rows and columns + IStyle rowStyle = workbook.Styles.Add("RowStyle"); + rowStyle.Color = Syncfusion.Drawing.Color.LightGreen; + IStyle columnStyle = workbook.Styles.Add("ColumnStyle"); + columnStyle.Color = Syncfusion.Drawing.Color.Orange; + + //Set default row style for entire row + worksheet.SetDefaultRowStyle(1, 2, rowStyle); + //Set default column style for entire column + worksheet.SetDefaultColumnStyle(1, 2, columnStyle); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/RowColumnStyle.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cell-styles/Wrap Text/.NET/Wrap Text/README.md b/Editing Excel cell-styles/Wrap Text/.NET/Wrap Text/README.md new file mode 100644 index 00000000..d7161ea9 --- /dev/null +++ b/Editing Excel cell-styles/Wrap Text/.NET/Wrap Text/README.md @@ -0,0 +1,45 @@ +# How to apply text wrapping 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to apply text wrapping in the worksheet. +{% 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]; + + worksheet.Range["A2"].Text = "First Sentence is wrapped"; + worksheet.Range["B2"].Text = "Second Sentence is wrapped"; + worksheet.Range["C2"].Text = "Third Sentence is wrapped"; + + #region Wrap Text + //Applying Wrap-text + worksheet.Range["A2:C2"].WrapText = true; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/WrapText.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Access Cell or Range/.NET/Access Cell or Range/README.md b/Editing Excel cells/Access Cell or Range/.NET/Access Cell or Range/README.md new file mode 100644 index 00000000..36df240d --- /dev/null +++ b/Editing Excel cells/Access Cell or Range/.NET/Access Cell or Range/README.md @@ -0,0 +1,55 @@ +# How to access a single cell or range of cells 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to access a single cell or range of cells in the worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + #region Access Cell or Range + //Access a range by specifying cell address + sheet.Range["A7"].Text = "Accessing a Range by specify cell address "; + + //Access a range by specifying cell row and column index + sheet.Range[9, 1].Text = "Accessing a Range by specify cell row and column index "; + + //Access a Range by specifying using defined name + IName name = workbook.Names.Add("Name"); + name.RefersToRange = sheet.Range["A11"]; + sheet.Range["Name"].Text = "Accessing a Range by specifying using defined name"; + + //Accessing a Range of cells by specifying cells address + sheet.Range["A13:C13"].Text = "Accessing a Range of Cells (Method 1)"; + + //Accessing a Range of cells specifying cell row and column index + sheet.Range[15, 1, 15, 3].Text = "Accessing a Range of Cells (Method 2)"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/AccessCellorRange.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Access Discontinuous Range/.NET/Access Discontinuous Range/README.md b/Editing Excel cells/Access Discontinuous Range/.NET/Access Discontinuous Range/README.md new file mode 100644 index 00000000..903486e5 --- /dev/null +++ b/Editing Excel cells/Access Discontinuous Range/.NET/Access Discontinuous Range/README.md @@ -0,0 +1,48 @@ +# How to access a discontinuous range of cells 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to access a discontinuous range of cells in the worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + #region Discontinuous Range + //range1 and range2 are discontinuous ranges + IRange range1 = sheet.Range["A1:A2"]; + IRange range2 = sheet.Range["C1:C2"]; + IRanges ranges = sheet.CreateRangesCollection(); + + //range1 and range2 are considered as a single range + ranges.Add(range1); + ranges.Add(range2); + ranges.Text = "Test"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/DiscontinuousRange.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Access Migrant Range/.NET/Access Migrant Range/README.md b/Editing Excel cells/Access Migrant Range/.NET/Access Migrant Range/README.md new file mode 100644 index 00000000..f489e05f --- /dev/null +++ b/Editing Excel cells/Access Migrant Range/.NET/Access Migrant Range/README.md @@ -0,0 +1,52 @@ +# How to access migrant range 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to access migrant range in the worksheet. +{% 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]; + + #region Access Migrant Range + //Getting migrant range of worksheet + IMigrantRange migrantRange = worksheet.MigrantRange; + + //Writing data into migrant range + for (int row = 1; row <= 5; row++) + { + for (int column = 1; column <= 5; column++) + { + //Writing values + migrantRange.ResetRowColumn(row, column); + migrantRange.Text = "Test"; + } + } + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/MigrantRange.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Access Relative Range/.NET/Access Relative Range/README.md b/Editing Excel cells/Access Relative Range/.NET/Access Relative Range/README.md new file mode 100644 index 00000000..4c51b6ee --- /dev/null +++ b/Editing Excel cells/Access Relative Range/.NET/Access Relative Range/README.md @@ -0,0 +1,55 @@ +# How to access a relative range of cells 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to access a relative range of cells in the worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + //Setting range index mode to relative + application.RangeIndexerMode = ExcelRangeIndexerMode.Relative; + + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet sheet = workbook.Worksheets[0]; + + #region Access Reative Range + //Creating a range by specifying cells address + IRange range1 = sheet.Range["B3:D5"]; + + //Accessing a range relatively to the existing range by specifying cell row and column index + range1[2, 2].Text = "Returns C4 cell"; + range1[0, 0].Text = "Returns A2 cell"; + + //Creating a range of cells specifying cell row and column index + IRange range2 = sheet.Range[5, 1, 10, 3]; + + //Accessing a range relatively to the existing range of cells by specifying cell row and column index + range2[2, 2, 3, 3].Text = "Returns range of cells B6 to C7"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/AccessRelativeRange.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Access Used Range/.NET/Access Used Range/README.md b/Editing Excel cells/Access Used Range/.NET/Access Used Range/README.md new file mode 100644 index 00000000..f489e05f --- /dev/null +++ b/Editing Excel cells/Access Used Range/.NET/Access Used Range/README.md @@ -0,0 +1,52 @@ +# How to access migrant range 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to access migrant range in the worksheet. +{% 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]; + + #region Access Migrant Range + //Getting migrant range of worksheet + IMigrantRange migrantRange = worksheet.MigrantRange; + + //Writing data into migrant range + for (int row = 1; row <= 5; row++) + { + for (int column = 1; column <= 5; column++) + { + //Writing values + migrantRange.ResetRowColumn(row, column); + migrantRange.Text = "Test"; + } + } + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/MigrantRange.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Accessing Filter/.NET/Accessing Filter/README.md b/Editing Excel cells/Accessing Filter/.NET/Accessing Filter/README.md new file mode 100644 index 00000000..96b1cabb --- /dev/null +++ b/Editing Excel cells/Accessing Filter/.NET/Accessing Filter/README.md @@ -0,0 +1,76 @@ +# How to access different types of filters 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to access different types of filters 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]; + + #region Accessing Filter + //selecting the filter by column index + IAutoFilter filter = worksheet.AutoFilters[0]; + + switch (filter.FilterType) + { + case ExcelFilterType.CombinationFilter: + CombinationFilter filterItems = (filter.FilteredItems as CombinationFilter); + for (int index = 0; index < filterItems.Count; index++) + { + if (filterItems[index].CombinationFilterType == ExcelCombinationFilterType.TextFilter) + { + string textValue = (filterItems[index] as TextFilter).Text; + } + else + { + DateTimeGroupingType groupType = (filterItems[index] as DateTimeFilter).GroupingType; + } + } + break; + + case ExcelFilterType.DynamicFilter: + DynamicFilter dateFilter = (filter.FilteredItems as DynamicFilter); + DynamicFilterType dynamicFilterType = dateFilter.DateFilterType; + break; + + case ExcelFilterType.CustomFilter: + IAutoFilterCondition firstCondition = filter.FirstCondition; + ExcelFilterDataType types = firstCondition.DataType; + break; + + case ExcelFilterType.ColorFilter: + ColorFilter colorFilter = (filter.FilteredItems as ColorFilter); + Syncfusion.Drawing.Color color = colorFilter.Color; + ExcelColorFilterType filterType = colorFilter.ColorFilterType; + break; + + case ExcelFilterType.IconFilter: + IconFilter iconFilter = (filter.FilteredItems as IconFilter); + int iconId = iconFilter.IconId; + ExcelIconSetType iconSetType = iconFilter.IconSetType; + break; + } + #endregion + + //Dispose streams + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Advanced Filter/.NET/Advanced Filter/README.md b/Editing Excel cells/Advanced Filter/.NET/Advanced Filter/README.md new file mode 100644 index 00000000..2cdd4386 --- /dev/null +++ b/Editing Excel cells/Advanced Filter/.NET/Advanced Filter/README.md @@ -0,0 +1,47 @@ +# How to apply an advanced filter to Excel data? + +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 apply an advanced filter to Excel data. +{% 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 Advanced Filter + IRange filterRange = worksheet.Range["A8:G51"]; + IRange criteriaRange = worksheet.Range["A2:B5"]; + IRange copyToRange = worksheet.Range["I8"]; + + //Apply the Advanced Filter with enable of unique value and copy to another place. + worksheet.AdvancedFilter(ExcelFilterAction.FilterCopy, filterRange, criteriaRange, copyToRange, true); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/AdvancedFilter.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/Editing Excel cells/Cell Color Filter/.NET/Cell Color Filter/README.md b/Editing Excel cells/Cell Color Filter/.NET/Cell Color Filter/README.md new file mode 100644 index 00000000..bbb85dbe --- /dev/null +++ b/Editing Excel cells/Cell Color Filter/.NET/Cell Color Filter/README.md @@ -0,0 +1,49 @@ +# How to apply a color filter to Excel data based on cell color? + +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 apply a color filter to Excel data based on cell color. +{% 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 Cell Color Filter + //Creating an AutoFilter in the first worksheet. Specifying the AutoFilter range. + worksheet.AutoFilters.FilterRange = worksheet.Range["A1:A11"]; + + //Column index to which AutoFilter must be applied. + IAutoFilter filter = worksheet.AutoFilters[0]; + + //Applying color filter to filter based on Cell Color. + filter.AddColorFilter(Syncfusion.Drawing.Color.Red, ExcelColorFilterType.CellColor); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CellColorFilter.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/Editing Excel cells/Clear Content/.NET/Clear Content/README.md b/Editing Excel cells/Clear Content/.NET/Clear Content/README.md new file mode 100644 index 00000000..9a364990 --- /dev/null +++ b/Editing Excel cells/Clear Content/.NET/Clear Content/README.md @@ -0,0 +1,44 @@ +# How to clear the content of a cell 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to clear the content of a cell 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]; + + #region Clear Content + //Clearing content and formatting in C3 + worksheet.Range["C3"].Clear(true); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ClearContent.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/Editing Excel cells/Combination Filter/.NET/Combination Filter/README.md b/Editing Excel cells/Combination Filter/.NET/Combination Filter/README.md new file mode 100644 index 00000000..b6a90ee7 --- /dev/null +++ b/Editing Excel cells/Combination Filter/.NET/Combination Filter/README.md @@ -0,0 +1,55 @@ +# How to apply a combination filter to Excel data? + +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 apply a combination filter to Excel data. +{% 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 Combination Filter + //Creating an AutoFilter in the first worksheet. Specifying the AutoFilter range. + worksheet.AutoFilters.FilterRange = worksheet.Range["A1:B22"]; + + //Column index to which AutoFilter must be applied. + IAutoFilter filter = worksheet.AutoFilters[0]; + + //Applying Text filter to filter multiple text to get filter. + filter.AddTextFilter(new string[] { "London", "Ireland", "Canada" }); + + //Column index to which AutoFilter must be applied. + filter = worksheet.AutoFilters[1]; + + //Applying DateTime filter to filter the date based on DateTimeGroupingType. + filter.AddDateFilter(2020, 11, 27, 0, 0, 0, DateTimeGroupingType.minute); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CombinationFilter.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/Editing Excel cells/Custom Filter/.NET/Custom Filter/README.md b/Editing Excel cells/Custom Filter/.NET/Custom Filter/README.md new file mode 100644 index 00000000..ed8fd799 --- /dev/null +++ b/Editing Excel cells/Custom Filter/.NET/Custom Filter/README.md @@ -0,0 +1,54 @@ +# How to apply a custom filter to Excel data? + +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 apply a custom filter to Excel data. +{% 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 Custom Filter + //Creating an AutoFilter in the first worksheet. Specifying the AutoFilter range + worksheet.AutoFilters.FilterRange = worksheet.Range["A1:A11"]; + IAutoFilter filter = worksheet.AutoFilters[0]; + + //Specifying first condition + IAutoFilterCondition firstCondition = filter.FirstCondition; + firstCondition.ConditionOperator = ExcelFilterCondition.Greater; + firstCondition.Double = 100; + + //Specifying second condition + IAutoFilterCondition secondCondition = filter.SecondCondition; + secondCondition.ConditionOperator = ExcelFilterCondition.Less; + secondCondition.Double = 200; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CustomFilter.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/Editing Excel cells/Dynamic Filter/.NET/Dynamic Filter/README.md b/Editing Excel cells/Dynamic Filter/.NET/Dynamic Filter/README.md new file mode 100644 index 00000000..1fb0d4fd --- /dev/null +++ b/Editing Excel cells/Dynamic Filter/.NET/Dynamic Filter/README.md @@ -0,0 +1,49 @@ +# How to apply a dynamic filter to Excel data? + +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 apply a dynamic filter to Excel data. +{% 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 Dynamic Filter + //Creating an AutoFilter in the first worksheet. Specifying the AutoFilter range. + worksheet.AutoFilters.FilterRange = worksheet.Range["A1:A13"]; + + //Column index to which AutoFilter must be applied. + IAutoFilter filter = worksheet.AutoFilters[0]; + + //Applying dynamic filter to filter the date based on DynamicFilterType. + filter.AddDynamicFilter(DynamicFilterType.NextQuarter); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/DynamicFilter.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/Editing Excel cells/Filter/.NET/Filter/README.md b/Editing Excel cells/Filter/.NET/Filter/README.md new file mode 100644 index 00000000..56b80d7e --- /dev/null +++ b/Editing Excel cells/Filter/.NET/Filter/README.md @@ -0,0 +1,53 @@ +# How to apply a filter to Excel data? + +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 apply a filter to Excel data. +{% 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 Filter + //Creating an AutoFilter in the first worksheet. Specifying the AutoFilter range + worksheet.AutoFilters.FilterRange = worksheet.Range["A1:A10"]; + + //Column index to which AutoFilter must be applied + IAutoFilter filter = worksheet.AutoFilters[0]; + + //To apply Top10Number filter, IsTop and IsTop10 must be enabled + filter.IsTop = true; + filter.IsTop10 = true; + + //Setting Top10 filter with number of cell to be filtered from top + filter.Top10Number = 5; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Filter.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/Editing Excel cells/Find/.NET/Find/README.md b/Editing Excel cells/Find/.NET/Find/README.md new file mode 100644 index 00000000..8312bdc3 --- /dev/null +++ b/Editing Excel cells/Find/.NET/Find/README.md @@ -0,0 +1,54 @@ +# How to find all occurrences of text in a worksheet using different find options? + +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 find all occurrences of text in a worksheet using different find options. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(fileStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Searches for the given string within the text of worksheet + IRange[] result1 = worksheet.FindAll("Gill", ExcelFindType.Text); + + //Searches for the given string within the text of worksheet + IRange[] result2 = worksheet.FindAll(700, ExcelFindType.Number); + + //Searches for the given string in formulas + IRange[] result3 = worksheet.FindAll("=SUM(F10:F11)", ExcelFindType.Formula); + + //Searches for the given string in calculated value, number and text + IRange[] result4 = worksheet.FindAll("41", ExcelFindType.Values); + + //Searches for the given string in comments + IRange[] result5 = worksheet.FindAll("Desk", ExcelFindType.Comments); + + //Searches for the given string within the text of worksheet and case matched + IRange[] result6 = worksheet.FindAll("Pen Set", ExcelFindType.Text, ExcelFindOptions.MatchCase); + + //Searches for the given string within the text of worksheet and the entire cell content matching to search text + IRange[] result7 = worksheet.FindAll("5", ExcelFindType.Text, ExcelFindOptions.MatchEntireCellContent); + + //Saving the workbook as stream + FileStream stream = new FileStream(Path.GetFullPath(@"Output/Find.xlsx"), FileMode.Create, FileAccess.ReadWrite); + workbook.SaveAs(stream); + stream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Font Color Filter/.NET/Font Color Filter/README.md b/Editing Excel cells/Font Color Filter/.NET/Font Color Filter/README.md new file mode 100644 index 00000000..89a0e4ed --- /dev/null +++ b/Editing Excel cells/Font Color Filter/.NET/Font Color Filter/README.md @@ -0,0 +1,49 @@ +# How to apply a color filter to Excel data based on font color? + +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 apply a color filter to Excel data based on font color. +{% 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 Font Color Filter + //Creating an AutoFilter in the first worksheet. Specifying the AutoFilter range. + worksheet.AutoFilters.FilterRange = worksheet.Range["A1:A11"]; + + //Column index to which AutoFilter must be applied. + IAutoFilter filter = worksheet.AutoFilters[0]; + + //Applying color filter to filter based on Cell Color. + filter.AddColorFilter(Syncfusion.Drawing.Color.Red, ExcelColorFilterType.FontColor); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/FontColorFilter.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/Editing Excel cells/Hyperlinks/.NET/Hyperlinks/README.md b/Editing Excel cells/Hyperlinks/.NET/Hyperlinks/README.md new file mode 100644 index 00000000..4f26a58a --- /dev/null +++ b/Editing Excel cells/Hyperlinks/.NET/Hyperlinks/README.md @@ -0,0 +1,71 @@ +# How to add hyperlinks in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to add hyperlinks in a worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Excel2013; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet sheet = workbook.Worksheets[0]; + + #region Hyperlinks + //Creating a Hyperlink for a Website + IHyperLink hyperlink = sheet.HyperLinks.Add(sheet.Range["C5"]); + hyperlink.Type = ExcelHyperLinkType.Url; + hyperlink.Address = "http://www.syncfusion.com"; + hyperlink.ScreenTip = "To know more about Syncfusion products, go through this link."; + + //Creating a Hyperlink for e-mail + IHyperLink hyperlink1 = sheet.HyperLinks.Add(sheet.Range["C7"]); + hyperlink1.Type = ExcelHyperLinkType.Url; + hyperlink1.Address = "mailto:Username@syncfusion.com"; + hyperlink1.ScreenTip = "Send Mail"; + + //Creating a Hyperlink for Opening Files using type as File + IHyperLink hyperlink2 = sheet.HyperLinks.Add(sheet.Range["C9"]); + hyperlink2.Type = ExcelHyperLinkType.File; + hyperlink2.Address = "C:/Program files"; + hyperlink2.ScreenTip = "File path"; + hyperlink2.TextToDisplay = "Hyperlink for files using File as type"; + + //Creating a Hyperlink for Opening Files using type as Unc + IHyperLink hyperlink3 = sheet.HyperLinks.Add(sheet.Range["C11"]); + hyperlink3.Type = ExcelHyperLinkType.Unc; + hyperlink3.Address = "C:/Documents and Settings"; + hyperlink3.ScreenTip = "Click here for files"; + hyperlink3.TextToDisplay = "Hyperlink for files using Unc as type"; + + //Creating a Hyperlink to another cell using type as Workbook + IHyperLink hyperlink4 = sheet.HyperLinks.Add(sheet.Range["C13"]); + hyperlink4.Type = ExcelHyperLinkType.Workbook; + hyperlink4.Address = "Sheet1!A15"; + hyperlink4.ScreenTip = "Click here"; + hyperlink4.TextToDisplay = "Hyperlink to cell A15"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Hyperlinks.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Icon Filter/.NET/Icon Filter/README.md b/Editing Excel cells/Icon Filter/.NET/Icon Filter/README.md new file mode 100644 index 00000000..2bcf6a8d --- /dev/null +++ b/Editing Excel cells/Icon Filter/.NET/Icon Filter/README.md @@ -0,0 +1,49 @@ +# How to apply an icon filter to Excel data? + +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 apply an icon filter to Excel data. +{% 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 Icon Filter + //Creating an AutoFilter in the first worksheet. Specifying the AutoFilter range. + worksheet.AutoFilters.FilterRange = worksheet.Range["A1:A8"]; + + //Column index to which AutoFilter must be applied. + IAutoFilter filter = worksheet.AutoFilters[0]; + + //Applying Icon filter to filter based on applied icon set. + filter.AddIconFilter(ExcelIconSetType.ThreeFlags, 2); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/IconFilter.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/Editing Excel cells/Modify Hyperlink/.NET/Modify Hyperlink/README.md b/Editing Excel cells/Modify Hyperlink/.NET/Modify Hyperlink/README.md new file mode 100644 index 00000000..810917e0 --- /dev/null +++ b/Editing Excel cells/Modify Hyperlink/.NET/Modify Hyperlink/README.md @@ -0,0 +1,44 @@ +# How to modify an existing hyperlink in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to modify an existing hyperlink in a 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]; + + #region Modify Hyperlink + //Modifying hyperlink’s text to display + IHyperLink hyperlink = worksheet.Range["C5"].Hyperlinks[0]; + hyperlink.TextToDisplay = "Syncfusion"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ModifyHyperlink.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/Editing Excel cells/Modify Shape Hyperlink/.NET/Modify Shape Hyperlink/README.md b/Editing Excel cells/Modify Shape Hyperlink/.NET/Modify Shape Hyperlink/README.md new file mode 100644 index 00000000..8d753780 --- /dev/null +++ b/Editing Excel cells/Modify Shape Hyperlink/.NET/Modify Shape Hyperlink/README.md @@ -0,0 +1,48 @@ +# How to modify an existing shape hyperlink in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to modify an existing shape hyperlink in a 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]; + + #region Modify Shape Hyperlink + //Modifying hyperlink’s screen tip through IWorksheet instance + IHyperLink hyperlink = worksheet.HyperLinks[0]; + hyperlink.ScreenTip = "Syncfusion"; + + //Modifying hyperlink’s screen tip through IShape instance + hyperlink = worksheet.Shapes[1].Hyperlink; + hyperlink.ScreenTip = "Mail Syncfusion"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ModifyShapeHyperlink.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/Editing Excel cells/Precedent and Dependent Cells/.NET/Precedent and Dependent Cells/README.md b/Editing Excel cells/Precedent and Dependent Cells/.NET/Precedent and Dependent Cells/README.md new file mode 100644 index 00000000..af43afb0 --- /dev/null +++ b/Editing Excel cells/Precedent and Dependent Cells/.NET/Precedent and Dependent Cells/README.md @@ -0,0 +1,127 @@ +# How to access the precedent and dependent cells in an Excel worksheet and workbook? + +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 access the precedent and dependent cells in an Excel worksheet and workbook. +{% 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 Precedents in Worksheet + //Getting precedent cells from the worksheet + IRange[] precedents_worksheet = worksheet["A1"].GetPrecedents(); + + Console.WriteLine("Precedents of Sheet1!A1 in Worksheet are : " ); + foreach(IRange range in precedents_worksheet) + { + Console.WriteLine(range.Address); + } + Console.WriteLine(); + #endregion + + #region Precedents in Workbook + //Getting precedent cells from the workbook + IRange[] precedents_workbook = worksheet["A1"].GetPrecedents(true); + + Console.WriteLine("Precedents of Sheet1!A1 in Workbook are : "); + foreach (IRange range in precedents_workbook) + { + Console.WriteLine(range.Address); + } + Console.WriteLine(); + #endregion + + #region Dependents in Worksheet + //Getting dependent cells from the worksheet + IRange[] dependents_worksheet = worksheet["C1"].GetDependents(); + + Console.WriteLine("Dependents of Sheet1!C1 in Worksheet are : "); + foreach (IRange range in dependents_worksheet) + { + Console.WriteLine(range.Address); + } + Console.WriteLine(); + #endregion + + #region Dependents in Workbook + //Getting dependent cells from the workbook + IRange[] dependents_workbook = worksheet["C1"].GetDependents(true); + + Console.WriteLine("Dependents of Sheet1!C1 in Workbook are : "); + foreach (IRange range in dependents_workbook) + { + Console.WriteLine(range.Address); + } + Console.WriteLine(); + #endregion + + #region Direct Precedents in Worksheet + //Getting precedent cells from the worksheet + IRange[] direct_precedents_worksheet = worksheet["A1"].GetDirectPrecedents(); + + Console.WriteLine("Direct Precedents of Sheet1!A1 in Worksheet are : "); + foreach (IRange range in direct_precedents_worksheet) + { + Console.WriteLine(range.Address); + } + Console.WriteLine(); + #endregion + + #region Direct Precedents in Workbook + //Getting precedent cells from the workbook + IRange[] direct_precedents_workbook = worksheet["A1"].GetDirectPrecedents(true); + + Console.WriteLine("Direct Precedents of Sheet1!A1 in Workbook are : "); + foreach (IRange range in direct_precedents_workbook) + { + Console.WriteLine(range.Address); + } + Console.WriteLine(); + #endregion + + #region Direct Dependents in Worksheet + //Getting dependent cells from the worksheet + IRange[] direct_dependents_worksheet = worksheet["C1"].GetDirectDependents(); + + Console.WriteLine("Direct Dependents of Sheet1!C1 in Worksheet are : "); + foreach (IRange range in direct_dependents_worksheet) + { + Console.WriteLine(range.Address); + } + Console.WriteLine(); + #endregion + + #region Direct Dependents in Workbook + //Getting dependent cells from the workbook + IRange[] direct_dependents_workbook = worksheet["C1"].GetDirectDependents(true); + + Console.WriteLine("Direct Dependents of Sheet1!C1 in Workbook are : "); + foreach (IRange range in direct_dependents_workbook) + { + Console.WriteLine(range.Address); + } + Console.WriteLine(); + #endregion + + //Dispose streams + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Remove Hyperlink/.NET/Remove Hyperlink/README.md b/Editing Excel cells/Remove Hyperlink/.NET/Remove Hyperlink/README.md new file mode 100644 index 00000000..08964154 --- /dev/null +++ b/Editing Excel cells/Remove Hyperlink/.NET/Remove Hyperlink/README.md @@ -0,0 +1,43 @@ +# How to remove an existing hyperlink in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to remove an existing hyperlink in a 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]; + + #region Remove Hyperlink + //Removing Hyperlink from Range "C7" + worksheet.Range["C7"].Hyperlinks.RemoveAt(0); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveHyperlink.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/Editing Excel cells/Remove Shape Hyperlink/.NET/Remove Shape Hyperlink/README.md b/Editing Excel cells/Remove Shape Hyperlink/.NET/Remove Shape Hyperlink/README.md new file mode 100644 index 00000000..5f52813f --- /dev/null +++ b/Editing Excel cells/Remove Shape Hyperlink/.NET/Remove Shape Hyperlink/README.md @@ -0,0 +1,41 @@ +# How to remove an existing shape hyperlink in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to remove an existing shape hyperlink in a 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]; + + //Removing hyperlink from sheet with Index + worksheet.HyperLinks.RemoveAt(0); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveShapeHyperlink.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/Editing Excel cells/Replace/.NET/Replace/README.md b/Editing Excel cells/Replace/.NET/Replace/README.md new file mode 100644 index 00000000..068e9ff3 --- /dev/null +++ b/Editing Excel cells/Replace/.NET/Replace/README.md @@ -0,0 +1,49 @@ +# How to replace all occurrences of text with different data? + +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 replace all occurrences of text with different data. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(fileStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Replaces the given string with another string + worksheet.Replace("Wilson", "William"); + + //Replaces the given string with another string on match case + worksheet.Replace("4.99", "4.90", ExcelFindOptions.MatchCase); + + //Replaces the given string with another string matching entire cell content to the search word + worksheet.Replace("Pen Set", "Pen", ExcelFindOptions.MatchEntireCellContent); + + //Replaces the given string with DateTime value + worksheet.Replace("DateValue",DateTime.Now); + + //Replaces the given string with Array + worksheet.Replace("Central", new string[] { "Central", "East" }, true); + + //Saving the workbook as stream + FileStream stream = new FileStream(Path.GetFullPath("Output/Replace.xlsx"), FileMode.Create, FileAccess.ReadWrite); + workbook.Version = ExcelVersion.Xlsx; + workbook.SaveAs(stream); + stream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Shape Hyperlink/.NET/Shape Hyperlink/README.md b/Editing Excel cells/Shape Hyperlink/.NET/Shape Hyperlink/README.md new file mode 100644 index 00000000..3902ac13 --- /dev/null +++ b/Editing Excel cells/Shape Hyperlink/.NET/Shape Hyperlink/README.md @@ -0,0 +1,53 @@ +# How to add a hyperlink to a shape in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to add a hyperlink to a shape in a worksheet. +{% 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]; + + #region Shape Hyperlink + //Adding hyperlink to TextBox + ITextBox textBox = worksheet.TextBoxes.AddTextBox(1, 1, 100, 100); + IHyperLink hyperlink = worksheet.HyperLinks.Add((textBox as IShape), ExcelHyperLinkType.Url, "http://www.Syncfusion.com", "click here"); + + //Adding hyperlink to AutoShape + IShape autoShape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Cloud, 10, 1, 100, 100); + hyperlink = worksheet.HyperLinks.Add(autoShape, ExcelHyperLinkType.Url, "mailto:Username@syncfusion.com", "Send Mail"); + + //Adding hyperlink to picture + IPictureShape picture = worksheet.Pictures.AddPictureAsLink(5, 5, 10, 7, Path.GetFullPath(@"Data/Image.png")); + hyperlink = worksheet.HyperLinks.Add(picture); + hyperlink.Type = ExcelHyperLinkType.Unc; + hyperlink.Address = "C://Documents and Settings"; + hyperlink.ScreenTip = "Click here for files"; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ShapeHyperlink.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Editing Excel cells/Sort On Cell Color/.NET/Sort On Cell Color/README.md b/Editing Excel cells/Sort On Cell Color/.NET/Sort On Cell Color/README.md new file mode 100644 index 00000000..d4190ec0 --- /dev/null +++ b/Editing Excel cells/Sort On Cell Color/.NET/Sort On Cell Color/README.md @@ -0,0 +1,70 @@ +# How to sort data by cell color 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to sort data by cell color 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]; + + #region Sort on Cell Color + //Creates the data sorter + IDataSort sorter = workbook.CreateDataSorter(); + + //Range to sort + sorter.SortRange = worksheet.Range["A1:A11"]; + + //Creates the sort field with the column index, sort based on and order by attribute + ISortField sortField = sorter.SortFields.Add(0, SortOn.CellColor, OrderBy.OnTop); + + //Specifies the color to sort the data + sortField.Color = Syncfusion.Drawing.Color.Yellow; + + //Sort based on the sort Field attribute + sorter.Sort(); + + //Creates the data sorter + sorter = workbook.CreateDataSorter(); + + //Range to sort + sorter.SortRange = worksheet.Range["B1:B11"]; + + //Creates another sort field with the column index, sort based on and order by attribute + sortField = sorter.SortFields.Add(1, SortOn.CellColor, OrderBy.OnBottom); + + //Specifies the color to sort the data + sortField.Color = Syncfusion.Drawing.Color.Yellow; + + //Sort based on the sort Field attribute + sorter.Sort(); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/SortOnCellColor.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/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/README.md b/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/README.md new file mode 100644 index 00000000..a39cff78 --- /dev/null +++ b/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/README.md @@ -0,0 +1,64 @@ +# How to sort data by cell values 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to sort data by cell values 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]; + + #region Sort On Cell Values + //Creates the data sorter + IDataSort sorter = workbook.CreateDataSorter(); + + //Range to sort + sorter.SortRange = worksheet.Range["A1:A11"]; + + //Adds the sort field with the column index, sort based on and order by attribute + sorter.SortFields.Add(0, SortOn.Values, OrderBy.Ascending); + + //Sort based on the sort Field attribute + sorter.Sort(); + + //Creates the data sorter + sorter = workbook.CreateDataSorter(); + + //Range to sort + sorter.SortRange = worksheet.Range["B1:B11"]; + + //Adds the sort field with the column index, sort based on and order by attribute + sorter.SortFields.Add(1, SortOn.Values, OrderBy.Descending); + + //Sort based on the sort Field attribute + sorter.Sort(); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/SortOnValues.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/Editing Excel cells/Sort on Font Color/.NET/Sort on Font Color/README.md b/Editing Excel cells/Sort on Font Color/.NET/Sort on Font Color/README.md new file mode 100644 index 00000000..b596a30c --- /dev/null +++ b/Editing Excel cells/Sort on Font Color/.NET/Sort on Font Color/README.md @@ -0,0 +1,70 @@ +# How to sort data by font color 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to sort data by font color 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]; + + #region Sort on Font Color + //Creates the data sorter + IDataSort sorter = workbook.CreateDataSorter(); + + //Range to sort + sorter.SortRange = worksheet.Range["A1:A11"]; + + //Creates the sort field with the column index, sort based on and order by attribute + ISortField sortField = sorter.SortFields.Add(0, SortOn.FontColor, OrderBy.OnTop); + + //Specifies the color to sort the data + sortField.Color = Syncfusion.Drawing.Color.Red; + + //Sort based on the sort Field attribute + sorter.Sort(); + + //Creates the data sorter + sorter = workbook.CreateDataSorter(); + + //Range to sort + sorter.SortRange = worksheet.Range["B1:B11"]; + + //Creates another sort field with the column index, sort based on and order by attribute + sortField = sorter.SortFields.Add(1, SortOn.FontColor, OrderBy.OnBottom); + + //Specifies the color to sort the data + sortField.Color = Syncfusion.Drawing.Color.Red; + + //Sort based on the sort Field attribute + sorter.Sort(); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/SortOnFontColor.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/Format rows and columns/Autofit Rows and Columns/.NET/Autofit Rows and Columns/README.md b/Format rows and columns/Autofit Rows and Columns/.NET/Autofit Rows and Columns/README.md new file mode 100644 index 00000000..ef430197 --- /dev/null +++ b/Format rows and columns/Autofit Rows and Columns/.NET/Autofit Rows and Columns/README.md @@ -0,0 +1,54 @@ +# How to resize a row and a column to fit their content? + +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 resize a row and a column to fit their content. +{% 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 Autofit Rows + //Autofit applied to a single row + worksheet.AutofitRow(3); + + //Autofit applied to multiple rows + worksheet.Range["6:10"].AutofitRows(); + #endregion + + #region Autofit Columns + //Autofit applied to a single column + worksheet.AutofitColumn(2); + + //Autofit applied to multiple columns + worksheet.Range["E:G"].AutofitColumns(); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/AutofitRowsandColumns.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/Format rows and columns/Delete Rows and Columns/.NET/Delete Rows and Columns/README.md b/Format rows and columns/Delete Rows and Columns/.NET/Delete Rows and Columns/README.md new file mode 100644 index 00000000..57e644cb --- /dev/null +++ b/Format rows and columns/Delete Rows and Columns/.NET/Delete Rows and Columns/README.md @@ -0,0 +1,54 @@ +# How to delete rows and columns in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to delete rows and columns in a 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]; + + #region Delete Rows + //Delete a row + worksheet.DeleteRow(3); + + //Delete multiple rows + worksheet.DeleteRow(10, 3); + #endregion + + #region Delete Columns + //Delete a column + worksheet.DeleteColumn(2); + + //Delete multiple columns + worksheet.DeleteColumn(3, 2); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/DeleteRowsandColumns.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/Format rows and columns/Expand or Collapse Groups/.NET/Expand or Collapse Groups/README.md b/Format rows and columns/Expand or Collapse Groups/.NET/Expand or Collapse Groups/README.md new file mode 100644 index 00000000..2ac27ce7 --- /dev/null +++ b/Format rows and columns/Expand or Collapse Groups/.NET/Expand or Collapse Groups/README.md @@ -0,0 +1,95 @@ +# How to expand or collapse groups 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to expand or collapse groups in the worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +class Program +{ + static void Main(string[] args) + { + ExpandandCollapse obj = new ExpandandCollapse(); + + obj.ExpandGroups(); + obj.CollapseGroups(); + } +} +public class ExpandandCollapse +{ + public void ExpandGroups() + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate - To Expand.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + #region Expand Groups + //Expand row groups + worksheet.Range["A3:A7"].ExpandGroup(ExcelGroupBy.ByRows, ExpandCollapseFlags.ExpandParent); + worksheet.Range["A11:A16"].ExpandGroup(ExcelGroupBy.ByRows); + + //Expand column groups + worksheet.Range["C1:D1"].ExpandGroup(ExcelGroupBy.ByColumns, ExpandCollapseFlags.ExpandParent); + worksheet.Range["F1:G1"].ExpandGroup(ExcelGroupBy.ByColumns); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExpandGroups.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); + } + } + public void CollapseGroups() + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate - To Collapse.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + #region Collapse Groups + //Collapse row groups + worksheet.Range["A3:A7"].CollapseGroup(ExcelGroupBy.ByRows); + worksheet.Range["A11:A16"].CollapseGroup(ExcelGroupBy.ByRows); + + //Collapse column groups + worksheet.Range["C1:D1"].CollapseGroup(ExcelGroupBy.ByColumns); + worksheet.Range["F1:G1"].CollapseGroup(ExcelGroupBy.ByColumns); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CollapseGroups.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/Format rows and columns/Group Rows and Columns/.NET/Group Rows and Columns/README.md b/Format rows and columns/Group Rows and Columns/.NET/Group Rows and Columns/README.md new file mode 100644 index 00000000..1b8bf534 --- /dev/null +++ b/Format rows and columns/Group Rows and Columns/.NET/Group Rows and Columns/README.md @@ -0,0 +1,50 @@ +# How to group rows and columns 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to group rows and columns 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 - ToGroup.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + #region Group Rows + //Group Rows + worksheet.Range["A3:A7"].Group(ExcelGroupBy.ByRows, true); + worksheet.Range["A11:A16"].Group(ExcelGroupBy.ByRows); + #endregion + + #region Group Columns + //Group Columns + worksheet.Range["C1:D1"].Group(ExcelGroupBy.ByColumns, false); + worksheet.Range["F1:G1"].Group(ExcelGroupBy.ByColumns); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/GroupRowsandColumns.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/Format rows and columns/Hide Range/.NET/Hide Range/README.md b/Format rows and columns/Hide Range/.NET/Hide Range/README.md new file mode 100644 index 00000000..569bddb2 --- /dev/null +++ b/Format rows and columns/Hide Range/.NET/Hide Range/README.md @@ -0,0 +1,54 @@ +# How to hide specific range in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to hide specific range in a worksheet. +{% 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]; + + IRange range = worksheet.Range["D4"]; + + #region Hide single cell + //Hiding the range ‘D4’ + worksheet.ShowRange(range, false); + #endregion + + IRange firstRange = worksheet.Range["F6:I9"]; + IRange secondRange = worksheet.Range["C15:G20"]; + RangesCollection rangeCollection = new RangesCollection(application, worksheet); + rangeCollection.Add(firstRange); + rangeCollection.Add(secondRange); + + #region Hide multiple cells + //Hiding a collection of ranges + worksheet.ShowRange(rangeCollection, false); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HideRange.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Format rows and columns/Hide Rows and Columns/.NET/Hide Rows and Columns/README.md b/Format rows and columns/Hide Rows and Columns/.NET/Hide Rows and Columns/README.md new file mode 100644 index 00000000..c66890d6 --- /dev/null +++ b/Format rows and columns/Hide Rows and Columns/.NET/Hide Rows and Columns/README.md @@ -0,0 +1,44 @@ +# How to hide rows and columns in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to hide rows and columns in a 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]; + + #region Hide Row and Column + //Hiding the first column and second row + worksheet.ShowColumn(1, false); + worksheet.ShowRow(2, false); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HideRowsandColumns.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/Format rows and columns/Insert Rows and Columns/.NET/Insert Rows and Columns/README.md b/Format rows and columns/Insert Rows and Columns/.NET/Insert Rows and Columns/README.md new file mode 100644 index 00000000..6624072f --- /dev/null +++ b/Format rows and columns/Insert Rows and Columns/.NET/Insert Rows and Columns/README.md @@ -0,0 +1,54 @@ +# How to insert rows and columns in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to insert rows and columns in a 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]; + + #region Insert Rows + //Insert a row + worksheet.InsertRow(3, 1, ExcelInsertOptions.FormatAsBefore); + + //Insert multiple rows + worksheet.InsertRow(10, 3, ExcelInsertOptions.FormatAsAfter); + #endregion + + #region Insert Columns + //Insert a column + worksheet.InsertColumn(2, 1, ExcelInsertOptions.FormatAsAfter); + + //Insert multiple columns + worksheet.InsertColumn(9, 2, ExcelInsertOptions.FormatAsBefore); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/InsertRowsandColumns.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/Format rows and columns/Move Rows and Columns/.NET/Move Rows and Columns/README.md b/Format rows and columns/Move Rows and Columns/.NET/Move Rows and Columns/README.md new file mode 100644 index 00000000..036b27d6 --- /dev/null +++ b/Format rows and columns/Move Rows and Columns/.NET/Move Rows and Columns/README.md @@ -0,0 +1,48 @@ +# How to move rows and columns in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to move rows and columns in a 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]; + + #region Move Rows + //Shifts cells toward Up after deletion + worksheet.Range["A4:A8"].Clear(ExcelMoveDirection.MoveUp); + #endregion + + #region Move Columns + //Shifts cells towards Left after deletion + worksheet.Range["B1:E1"].Clear(ExcelMoveDirection.MoveLeft); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/MoveRowsandColumns.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/Format rows and columns/Resize Rows and Columns/.NET/Resize Rows and Columns/README.md b/Format rows and columns/Resize Rows and Columns/.NET/Resize Rows and Columns/README.md new file mode 100644 index 00000000..76a26d92 --- /dev/null +++ b/Format rows and columns/Resize Rows and Columns/.NET/Resize Rows and Columns/README.md @@ -0,0 +1,54 @@ +# How to resize a row and a column in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to resize a row and a column in a 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]; + + #region Resize rows + //Modifying the row height of one row + worksheet.SetRowHeight(2, 100); + + //Modifying the row height of multiple rows + worksheet.Range["A5:A10"].RowHeight = 40; + #endregion + + #region Resize columns + //Modifying the column width of one column + worksheet.SetColumnWidth(2, 50); + + //Modifying the column width of multiple columns + worksheet.Range["D1:G1"].ColumnWidth = 5; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ResizeRowsandColumns.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/Format rows and columns/Ungroup Rows and Columns/.NET/Ungroup Rows and Columns/README.md b/Format rows and columns/Ungroup Rows and Columns/.NET/Ungroup Rows and Columns/README.md new file mode 100644 index 00000000..6562bd24 --- /dev/null +++ b/Format rows and columns/Ungroup Rows and Columns/.NET/Ungroup Rows and Columns/README.md @@ -0,0 +1,48 @@ +# How to ungroup rows and columns 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to ungroup rows and columns 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 - ToUngroup.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + #region Un-Group Rows + //Ungroup Rows + worksheet.Range["A3:A7"].Ungroup(ExcelGroupBy.ByRows); + #endregion + + #region Un-Group Columns + //Ungroup Columns + worksheet.Range["C1:D1"].Ungroup(ExcelGroupBy.ByColumns); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/UngroupRowsandColumns.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/Array to Worksheet/.NET/Array to Worksheet/README.md b/Import and Export Data/Array to Worksheet/.NET/Array to Worksheet/README.md new file mode 100644 index 00000000..98490fb8 --- /dev/null +++ b/Import and Export Data/Array to Worksheet/.NET/Array to Worksheet/README.md @@ -0,0 +1,42 @@ +# How to import data from an array into 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 import data from an array into 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]; + + //Initialize the Object Array + object[] array = new object[4] { "Total Income", "Actual Expense", "Expected Expenses", "Profit" }; + //Import the Object Array to Sheet + worksheet.ImportArray(array, 1, 1, false); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ArrayToWorksheet.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/CollectionObjects to Worksheet/.NET/CollectionObjects to Worksheet/README.md b/Import and Export Data/CollectionObjects to Worksheet/.NET/CollectionObjects to Worksheet/README.md new file mode 100644 index 00000000..1e20b60e --- /dev/null +++ b/Import and Export Data/CollectionObjects to Worksheet/.NET/CollectionObjects to Worksheet/README.md @@ -0,0 +1,77 @@ +# How to import data from Collection Objects to 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; +using System.ComponentModel; +using System.Collections.Generic; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to import data from Collection Objects to Excel. +{% tabs %} +{% highlight c# tabtitle="C#" %} +class Program +{ + 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]; + + //Import the data to worksheet + IList reports = GetSalesReports(); + worksheet.ImportData(reports, 2, 1, false); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportCollectionObjects.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + } + } + //Gets a list of sales reports + public static List GetSalesReports() + { + List reports = new List(); + reports.Add(new Customer("Andy Bernard", "45000", "58000")); + reports.Add(new Customer("Jim Halpert", "34000", "65000")); + reports.Add(new Customer("Karen Fillippelli", "75000", "64000")); + reports.Add(new Customer("Phyllis Lapin", "56500", "33600")); + reports.Add(new Customer("Stanley Hudson", "46500", "52000")); + return reports; + } +} + +//Customer details +public class Customer +{ + [DisplayNameAttribute("Sales Person Name")] + public string SalesPerson { get; set; } + [Bindable(false)] + public string SalesJanJun { get; set; } + public string SalesJulDec { get; set; } + + public Customer(string name, string janToJun, string julToDec) + { + SalesPerson = name; + SalesJanJun = janToJun; + SalesJulDec = julToDec; + } +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/DataColumn to Worksheet/.NET/DataColumn to Worksheet/README.md b/Import and Export Data/DataColumn to Worksheet/.NET/DataColumn to Worksheet/README.md new file mode 100644 index 00000000..2afb6f5d --- /dev/null +++ b/Import and Export Data/DataColumn to Worksheet/.NET/DataColumn to Worksheet/README.md @@ -0,0 +1,44 @@ +# How to import data from DataColumn to 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to import data from DataColumn to 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]; + + #region Import from DataColumn + //Initialize the DataTable + DataTable table = SampleDataTable(); + //Import Data Column to the worksheet + DataColumn column = table.Columns[0]; + worksheet.ImportDataColumn(column, true, 1, 1); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataColumn.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/DataGridView to Worksheet/NET Framework/DataGridView to Worksheet/README.md b/Import and Export Data/DataGridView to Worksheet/NET Framework/DataGridView to Worksheet/README.md new file mode 100644 index 00000000..4492363d --- /dev/null +++ b/Import and Export Data/DataGridView to Worksheet/NET Framework/DataGridView to Worksheet/README.md @@ -0,0 +1,76 @@ +# How to import data from the DataGridView to 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; +using System.Data; +using System.Windows.Forms; +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to import data from the DataGridView to Excel. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + //Initialize DataGridView control + DataGridView dataGridView = new DataGridView(); + + //Assign data source + dataGridView.DataSource = GetDataTable(); + + //Add control to group box + groupBox.Controls.Add(dataGridView); + + //Assign the datagridview size + dataGridView.Size = new System.Drawing.Size(441, 150); + + //Initialize Application + IApplication application = excelEngine.Excel; + + //Set default version for application + application.DefaultVersion = ExcelVersion.Xlsx; + + //Create a new workbook + IWorkbook workbook = application.Workbooks.Create(1); + + //Accessing first worksheet in the workbook + IWorksheet worksheet = workbook.Worksheets[0]; + + //Import data from DataGridView control + worksheet.ImportDataGridView(dataGridView, 1, 1, true, true); + + //Save the workbook + workbook.SaveAs("Output.xlsx"); + System.Diagnostics.Process.Start("Output.xlsx"); +} +private static DataTable GetDataTable() +{ + Random r = new Random(); + DataTable dt = new DataTable("NumbersTable"); + + int nCols = 4; + int nRows = 10; + + for (int i = 0; i < nCols; i++) + dt.Columns.Add(new DataColumn("Column" + i.ToString())); + + for (int i = 0; i < nRows; ++i) + { + DataRow dr = dt.NewRow(); + for (int j = 0; j < nCols; j++) + dr[j] = r.Next(0, 10); + dt.Rows.Add(dr); + } + return dt; +} +{% 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 new file mode 100644 index 00000000..f5b34dc7 --- /dev/null +++ b/Import and Export Data/DataTable to Worksheet/.NET/DataTable to Worksheet/README.md @@ -0,0 +1,43 @@ +# How to import data from DataTable to 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +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()) +{ + 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(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/DataView to Worksheet/.NET/DataView to Worksheet/README.md b/Import and Export Data/DataView to Worksheet/.NET/DataView to Worksheet/README.md new file mode 100644 index 00000000..45415d57 --- /dev/null +++ b/Import and Export Data/DataView to Worksheet/.NET/DataView to Worksheet/README.md @@ -0,0 +1,44 @@ +# How to import data from DataView to 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to import data from DataView to 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]; + + #region Import from DataView + //Initialize the DataTable + DataTable table = SampleDataTable(); + //Import DataView to the worksheet + DataView view = table.DefaultView; + worksheet.ImportDataView(view, true, 1, 1); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataView.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/Grouping Options/.NET/Grouping Options/README.md b/Import and Export Data/Grouping Options/.NET/Grouping Options/README.md new file mode 100644 index 00000000..2e41932b --- /dev/null +++ b/Import and Export Data/Grouping Options/.NET/Grouping Options/README.md @@ -0,0 +1,228 @@ +# How to import data from nested collection objects with the collapse group option into 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; +using System.Collections.Generic; +using System.Xml.Serialization; +using System.ComponentModel; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to import data from nested collection objects with the collapse group option. +{% tabs %} +{% highlight c# tabtitle="C#" %} +class Program +{ + static void Main(string[] args) + { + ImportData(); + } + //Main method to import data from nested collection to Excel worksheet. + private static void ImportData() + { + ExcelEngine excelEngine = new ExcelEngine(); + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + IList vehicles = GetVehicleDetails(); + + ExcelImportDataOptions importDataOptions = new ExcelImportDataOptions(); + + //Imports from 4th row. + importDataOptions.FirstRow = 4; + + //Imports column headers. + importDataOptions.IncludeHeader = true; + + //Set layout options. + importDataOptions.NestedDataLayoutOptions = ExcelNestedDataLayoutOptions.Default; + + //Set grouping option. Available GroupingOptions are Collapse and Expand + importDataOptions.NestedDataGroupOptions = ExcelNestedDataGroupOptions.Collapse; + + //Set collapse level. + //GroupingOption must set to ‘Collapse’ before applying ‘CollapseLevel’. + importDataOptions.CollapseLevel = 2; + + //Import data from the nested collection. + worksheet.ImportData(vehicles, importDataOptions); + + //Apply style to headers + worksheet["A1:C2"].Merge(); + worksheet["A1"].Text = "Automobile Brands in the US"; + + worksheet.UsedRange.AutofitColumns(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportData.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + } + //Helper method to load data from XML file and add them in collections. + private static IList GetVehicleDetails() + { + XmlSerializer deserializer = new XmlSerializer(typeof(BrandObjects)); + + //Read data from XML file. + FileStream stream = new FileStream(Path.GetFullPath(@"Data/ExportData.xml"), FileMode.Open, FileAccess.Read); + TextReader textReader = new StreamReader(stream); + BrandObjects brands = (BrandObjects)deserializer.Deserialize(textReader); + + //Initialize parent collection to add data from XML file. + List list = new List(); + + string brandName = brands.BrandObject[0].BrandName; + string vehicleType = brands.BrandObject[0].VahicleType; + string modelName = brands.BrandObject[0].ModelName; + + //Parent class + Brand brand = new Brand(brandName); + brand.VehicleTypes = new List(); + + VehicleType vehicle = new VehicleType(vehicleType); + vehicle.Models = new List(); + + Model model = new Model(modelName); + brand.VehicleTypes.Add(vehicle); + + list.Add(brand); + + foreach (BrandObject brandObj in brands.BrandObject) + { + if (brandName == brandObj.BrandName) + { + if (vehicleType == brandObj.VahicleType) + { + vehicle.Models.Add(new Model(brandObj.ModelName)); + continue; + } + else + { + vehicle = new VehicleType(brandObj.VahicleType); + vehicle.Models = new List(); + vehicle.Models.Add(new Model(brandObj.ModelName)); + brand.VehicleTypes.Add(vehicle); + vehicleType = brandObj.VahicleType; + } + continue; + } + else + { + brand = new Brand(brandObj.BrandName); + vehicle = new VehicleType(brandObj.VahicleType); + vehicle.Models = new List(); + vehicle.Models.Add(new Model(brandObj.ModelName)); + brand.VehicleTypes = new List(); + brand.VehicleTypes.Add(vehicle); + vehicleType = brandObj.VahicleType; + list.Add(brand); + brandName = brandObj.BrandName; + } + } + + textReader.Close(); + return list; + } +} +//Parent Class +public class Brand +{ + private string m_brandName; + + [DisplayNameAttribute("Brand")] + public string BrandName + { + get { return m_brandName; } + set { m_brandName = value; } + } + + //Vehicle Types Collection + private IList m_vehicleTypes; + + public IList VehicleTypes + { + get { return m_vehicleTypes; } + set { m_vehicleTypes = value; } + } + + public Brand(string brandName) + { + m_brandName = brandName; + } +} + +//Child Class +public class VehicleType +{ + private string m_vehicleName; + + [DisplayNameAttribute("Vehicle Type")] + public string VehicleName + { + get { return m_vehicleName; } + set { m_vehicleName = value; } + } + + //Models collection + private IList m_models; + public IList Models + { + get { return m_models; } + set { m_models = value; } + } + + public VehicleType(string vehicle) + { + m_vehicleName = vehicle; + } +} + +//Sub-child Class +public class Model +{ + private string m_modelName; + + [DisplayNameAttribute("Model")] + public string ModelName + { + get { return m_modelName; } + set { m_modelName = value; } + } + + public Model(string name) + { + m_modelName = name; + } +} + +//Helper Classes +[XmlRootAttribute("BrandObjects")] +public class BrandObjects +{ + [XmlElement("BrandObject")] + public BrandObject[] BrandObject { get; set; } +} + +public class BrandObject +{ + public string BrandName { get; set; } + public string VahicleType { get; set; } + public string ModelName { get; set; } +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/HTML Table to Worksheet/.NET/HTML Table to Worksheet/README.md b/Import and Export Data/HTML Table to Worksheet/.NET/HTML Table to Worksheet/README.md new file mode 100644 index 00000000..89e223ed --- /dev/null +++ b/Import and Export Data/HTML Table to Worksheet/.NET/HTML Table to Worksheet/README.md @@ -0,0 +1,42 @@ +# How to import data from an HTML table into 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 import data from an HTML table into 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]; + + //Imports HTML table into the worksheet from first row and first column + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.html"), FileMode.Open, FileAccess.ReadWrite); + worksheet.ImportHtmlTable(inputStream, 1, 1); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HTMLTabletoWorksheet.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/Import Data Options/.NET/Import Data Options/README.md b/Import and Export Data/Import Data Options/.NET/Import Data Options/README.md new file mode 100644 index 00000000..39845478 --- /dev/null +++ b/Import and Export Data/Import Data Options/.NET/Import Data Options/README.md @@ -0,0 +1,81 @@ +# How to import data from Collection Objects to 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; +using System.Collections.Generic; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to import data from Collection Objects to Excel. +{% tabs %} +{% highlight c# tabtitle="C#" %} +class Program +{ + 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]; + + //Import the data to worksheet with Import Data Options + IList reports = GetSalesReports(); + + ExcelImportDataOptions importDataOptions = new ExcelImportDataOptions(); + importDataOptions.FirstRow = 2; + importDataOptions.FirstColumn = 1; + importDataOptions.IncludeHeader = false; + importDataOptions.PreserveTypes = false; + + worksheet.ImportData(reports, importDataOptions); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataOptions.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + } + } + //Gets a list of sales reports + public static List GetSalesReports() + { + List reports = new List(); + reports.Add(new Customer("Andy Bernard", "45000", "58000")); + reports.Add(new Customer("Jim Halpert", "34000", "65000")); + reports.Add(new Customer("Karen Fillippelli", "75000", "64000")); + reports.Add(new Customer("Phyllis Lapin", "56500", "33600")); + reports.Add(new Customer("Stanley Hudson", "46500", "52000")); + return reports; + } +} + +//Customer details +public class Customer +{ + public string SalesPerson { get; set; } + public string SalesJanJun { get; set; } + public string SalesJulDec { get; set; } + + public Customer(string name, string janToJun, string julToDec) + { + SalesPerson = name; + SalesJanJun = janToJun; + SalesJulDec = julToDec; + } +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/Import with Hyperlink/.NET/Import with Hyperlink/README.md b/Import and Export Data/Import with Hyperlink/.NET/Import with Hyperlink/README.md new file mode 100644 index 00000000..75576566 --- /dev/null +++ b/Import and Export Data/Import with Hyperlink/.NET/Import with Hyperlink/README.md @@ -0,0 +1,105 @@ +# How to import data from collection objects with hyperlinks into 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; +using System.Collections.Generic; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to import data from collection objects with hyperlinks into Excel. +{% tabs %} +{% highlight c# tabtitle="C#" %} +class Program +{ + 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]; + + //Import the data to worksheet + IList reports = GetCompanyDetails(); + worksheet.ImportData(reports, 2, 1, false); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportData.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + } + } + //Gets a list of company details + private static List GetCompanyDetails() + { + List companyList = new List(); + + Company company = new Company(); + company.Name = "Syncfusion"; + Hyperlink link = new Hyperlink("https://www.syncfusion.com", "", "", "Syncfusion", ExcelHyperLinkType.Url, null); + company.Link = link; + companyList.Add(company); + + company = new Company(); + company.Name = "Microsoft"; + link = new Hyperlink("https://www.microsoft.com", "", "", "Microsoft", ExcelHyperLinkType.Url, null); + company.Link = link; + companyList.Add(company); + + company = new Company(); + company.Name = "Google"; + link = new Hyperlink("https://www.google.com", "", "", "Google", ExcelHyperLinkType.Url, null); + company.Link = link; + companyList.Add(company); + + return companyList; + } +} +public class Hyperlink : IHyperLink +{ + public IApplication Application { get; } + public object Parent { get; } + public string Address { get; set; } + public string Name { get; } + public IRange Range { get; } + public string ScreenTip { get; set; } + public string SubAddress { get; set; } + public string TextToDisplay { get; set; } + public ExcelHyperLinkType Type { get; set; } + public IShape Shape { get; } + public ExcelHyperlinkAttachedType AttachedType { get; } + public byte[] Image { get; set; } + + public Hyperlink(string address, string subAddress, string screenTip, string textToDisplay, ExcelHyperLinkType type, byte[] image) + { + Address = address; + ScreenTip = screenTip; + SubAddress = subAddress; + TextToDisplay = textToDisplay; + Type = type; + Image = image; + } +} + +public class Company +{ + public string Name { get; set; } + public Hyperlink Link { get; set; } +} + +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/Layout Options/.NET/Layout Options/README.md b/Import and Export Data/Layout Options/.NET/Layout Options/README.md new file mode 100644 index 00000000..f65628b1 --- /dev/null +++ b/Import and Export Data/Layout Options/.NET/Layout Options/README.md @@ -0,0 +1,221 @@ +# How to import data from nested collection objects with default layout options into 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; +using System.Collections.Generic; +using System.Xml.Serialization; +using System.ComponentModel; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to import data from nested collection objects with default layout options into Excel. +{% tabs %} +{% highlight c# tabtitle="C#" %} +class Program +{ + static void Main(string[] args) + { + ImportData(); + } + //Main method to import data from nested collection to Excel worksheet. + private static void ImportData() + { + ExcelEngine excelEngine = new ExcelEngine(); + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + IList vehicles = GetVehicleDetails(); + + ExcelImportDataOptions importDataOptions = new ExcelImportDataOptions(); + + //Imports from 4th row. + importDataOptions.FirstRow = 4; + + //Imports column headers. + importDataOptions.IncludeHeader = true; + + //Set layout options. Available LayoutOptions are Default, Merge and Repeat. + importDataOptions.NestedDataLayoutOptions = ExcelNestedDataLayoutOptions.Default; + + //Import data from the nested collection. + worksheet.ImportData(vehicles, importDataOptions); + + //Apply style to headers + worksheet["A1:C2"].Merge(); + worksheet["A1"].Text = "Automobile Brands in the US"; + + worksheet.UsedRange.AutofitColumns(); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportData.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + } + //Helper method to load data from XML file and add them in collections. + prive static IList GetVehicleDetails() + { + XmlSerializer deserializer = new XmlSerializer(typeof(BrandObjects)); + + //Read data from XML file. + FileStream stream = new FileStream(Path.GetFullPath(@"Data/ExportData.xml"), FileMode.Open, FileAccess.Read); + TextReader textReader = new StreamReader(stream); + BrandObjects brands = (BrandObjects)deserializer.Deserialize(textReader); + + //Initialize parent collection to add data from XML file. + List list = new List(); + + string brandName = brands.BrandObject[0].BrandName; + string vehicleType = brands.BrandObject[0].VahicleType; + string modelName = brands.BrandObject[0].ModelName; + + //Parent class + Brand brand = new Brand(brandName); + brand.VehicleTypes = new List(); + + VehicleType vehicle = new VehicleType(vehicleType); + vehicle.Models = new List(); + + Model model = new Model(modelName); + brand.VehicleTypes.Add(vehicle); + + list.Add(brand); + + foreach (BrandObject brandObj in brands.BrandObject) + { + if (brandName == brandObj.BrandName) + { + if (vehicleType == brandObj.VahicleType) + { + vehicle.Models.Add(new Model(brandObj.ModelName)); + continue; + } + else + { + vehicle = new VehicleType(brandObj.VahicleType); + vehicle.Models = new List(); + vehicle.Models.Add(new Model(brandObj.ModelName)); + brand.VehicleTypes.Add(vehicle); + vehicleType = brandObj.VahicleType; + } + continue; + } + else + { + brand = new Brand(brandObj.BrandName); + vehicle = new VehicleType(brandObj.VahicleType); + vehicle.Models = new List(); + vehicle.Models.Add(new Model(brandObj.ModelName)); + brand.VehicleTypes = new List(); + brand.VehicleTypes.Add(vehicle); + vehicleType = brandObj.VahicleType; + list.Add(brand); + brandName = brandObj.BrandName; + } + } + + textReader.Close(); + return list; + } +} +//Parent Class +public class Brand +{ + private string m_brandName; + + [DisplayNameAttribute("Brand")] + public string BrandName + { + get { return m_brandName; } + set { m_brandName = value; } + } + + //Vehicle Types Collection + private IList m_vehicleTypes; + + public IList VehicleTypes + { + get { return m_vehicleTypes; } + set { m_vehicleTypes = value; } + } + + public Brand(string brandName) + { + m_brandName = brandName; + } +} + +//Child Class +public class VehicleType +{ + private string m_vehicleName; + + [DisplayNameAttribute("Vehicle Type")] + public string VehicleName + { + get { return m_vehicleName; } + set { m_vehicleName = value; } + } + + //Models collection + private IList m_models; + public IList Models + { + get { return m_models; } + set { m_models = value; } + } + + public VehicleType(string vehicle) + { + m_vehicleName = vehicle; + } +} + +//Sub-child Class +public class Model +{ + private string m_modelName; + + [DisplayNameAttribute("Model")] + public string ModelName + { + get { return m_modelName; } + set { m_modelName = value; } + } + + public Model(string name) + { + m_modelName = name; + } +} + +//Helper Classes +[XmlRootAttribute("BrandObjects")] +public class BrandObjects +{ + [XmlElement("BrandObject")] + public BrandObject[] BrandObject { get; set; } +} + +public class BrandObject +{ + public string BrandName { get; set; } + public string VahicleType { get; set; } + public string ModelName { get; set; } +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/Worksheet to CollectionObjects/.NET/Worksheet to CollectionObjects/README.md b/Import and Export Data/Worksheet to CollectionObjects/.NET/Worksheet to CollectionObjects/README.md new file mode 100644 index 00000000..65480167 --- /dev/null +++ b/Import and Export Data/Worksheet to CollectionObjects/.NET/Worksheet to CollectionObjects/README.md @@ -0,0 +1,54 @@ +# How to export data from Excel into collection objects? + +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 export data from Excel into collection objects. +{% tabs %} +{% highlight c# tabtitle="C#" %} +class Program +{ + static void Main(string[] args) + { + 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]; + + //Export worksheet data into Collection Objects + List collectionObjects = worksheet.ExportData(1, 1, 10, 3); + + //Dispose streams + inputStream.Dispose(); + } + } + public class Report + { + [DisplayNameAttribute("Sales Person Name")] + public string SalesPerson { get; set; } + [Bindable(false)] + public string SalesJanJun { get; set; } + public string SalesJulDec { get; set; } + + public Report() + { + + } + } +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/Worksheet to DataTable/.NET/Worksheet to DataTable/README.md b/Import and Export Data/Worksheet to DataTable/.NET/Worksheet to DataTable/README.md new file mode 100644 index 00000000..b31632e8 --- /dev/null +++ b/Import and Export Data/Worksheet to DataTable/.NET/Worksheet to DataTable/README.md @@ -0,0 +1,35 @@ +# How to export data from Excel into a DataTable? + +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 export data from Excel into a DataTable. +{% 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]; + + //Read data from the worksheet and Export to the DataTable + DataTable customersTable = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames | ExcelExportDataTableOptions.ComputedFormulaValues); + + //Dispose streams + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Import and Export Data/Worksheet to Nested Class/.NET/Worksheet to Nested Class/README.md b/Import and Export Data/Worksheet to Nested Class/.NET/Worksheet to Nested Class/README.md new file mode 100644 index 00000000..ec58bdfa --- /dev/null +++ b/Import and Export Data/Worksheet to Nested Class/.NET/Worksheet to Nested Class/README.md @@ -0,0 +1,73 @@ +# How to export data from Excel into nested class objects? + +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 System.Collections.Generic; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to export data from Excel into nested class objects. +{% tabs %} +{% highlight c# tabtitle="C#" %} +class Program +{ + static void Main(string[] args) + { + 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]; + + //Map column headers in worksheet with class properties. + Dictionary mappingProperties = new Dictionary(); + mappingProperties.Add("Customer ID", "CustId"); + mappingProperties.Add("Customer Name", "CustName"); + mappingProperties.Add("Customer Age", "CustAge"); + mappingProperties.Add("Order ID", "CustOrder.Order_Id"); + mappingProperties.Add("Order Price", "CustOrder.Price"); + + //Export worksheet data into nested class Objects. + List nestedClassObjects = worksheet.ExportData(1, 1, 10, 5, mappingProperties); + + //Dispose streams + inputStream.Dispose(); + } + } +} +//Customer details class +public partial class Customer +{ + public int CustId { get; set; } + public string CustName { get; set; } + public int CustAge { get; set; } + public Order CustOrder { get; set; } + public Customer() + { + + } +} + +//Order details class +public partial class Order +{ + public string Order_Id { get; set; } + public double Price { get; set; } + public Order() + { + + } +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Worksheet Features/Access Worksheet/.NET/Access Worksheet/README.md b/Worksheet Features/Access Worksheet/.NET/Access Worksheet/README.md new file mode 100644 index 00000000..40f720be --- /dev/null +++ b/Worksheet Features/Access Worksheet/.NET/Access Worksheet/README.md @@ -0,0 +1,38 @@ +# How to create worksheets within a workbook? + +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 access a worksheet from the worksheet collection. +{% 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); + + #region Access + //Accessing via index + IWorksheet sheet = workbook.Worksheets[0]; + + //Accessing via sheet name + IWorksheet NamedSheet = workbook.Worksheets["Sample"]; + #endregion + + //Dispose streams + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Worksheet Features/Copy Cell Range/.NET/Copy Cell Range/README.md b/Worksheet Features/Copy Cell Range/.NET/Copy Cell Range/README.md new file mode 100644 index 00000000..cadc170f --- /dev/null +++ b/Worksheet Features/Copy Cell Range/.NET/Copy Cell Range/README.md @@ -0,0 +1,45 @@ +# How to create worksheets within a workbook? + +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 copy a cell range from one worksheet to another worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + FileStream sourceStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(sourceStream); + + IWorksheet sourceWorksheet = workbook.Worksheets[0]; + IWorksheet destinationWorksheet = workbook.Worksheets[1]; + + IRange source = sourceWorksheet.Range[1, 1, 4, 3]; + IRange destination = destinationWorksheet.Range[1, 1, 4, 3]; + + //Copy the cell range to the next sheet + source.CopyTo(destination); + + //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(); + sourceStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Worksheet Features/Copy Column/.NET/Copy Column/README.md b/Worksheet Features/Copy Column/.NET/Copy Column/README.md new file mode 100644 index 00000000..c68d169f --- /dev/null +++ b/Worksheet Features/Copy Column/.NET/Copy Column/README.md @@ -0,0 +1,45 @@ +# How to create worksheets within a workbook? + +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 copy a column from one worksheet to another 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 sourceWorksheet = workbook.Worksheets[0]; + IWorksheet destinationWorksheet = workbook.Worksheets[1]; + + IRange sourceColumn = sourceWorksheet.Range[1, 1]; + IRange destinationColumn = destinationWorksheet.Range[1, 1]; + + //Copy the entire column to the next sheet + sourceColumn.EntireColumn.CopyTo(destinationColumn); + + //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/Worksheet Features/Copy Row/.NET/Copy Row/README.md b/Worksheet Features/Copy Row/.NET/Copy Row/README.md new file mode 100644 index 00000000..ef9c477e --- /dev/null +++ b/Worksheet Features/Copy Row/.NET/Copy Row/README.md @@ -0,0 +1,45 @@ +# How to create worksheets within a workbook? + +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 copy a row from one worksheet to another. +{% 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 sourceWorksheet = workbook.Worksheets[0]; + IWorksheet destinationWorksheet = workbook.Worksheets[1]; + + IRange sourceRow = sourceWorksheet.Range[1, 1]; + IRange destinationRow = destinationWorksheet.Range[1, 1]; + + //Copy the entire row to the next sheet + sourceRow.EntireRow.CopyTo(destinationRow); + + //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/Worksheet Features/Copy Workbook/.NET/Copy Workbook/README.md b/Worksheet Features/Copy Workbook/.NET/Copy Workbook/README.md new file mode 100644 index 00000000..d77526df --- /dev/null +++ b/Worksheet Features/Copy Workbook/.NET/Copy Workbook/README.md @@ -0,0 +1,41 @@ +# How to create worksheets within a workbook? + +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 copy an entire workbook to another workbook. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream sourceStream = new FileStream(Path.GetFullPath(@"Data/SourceWorkbookTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook sourceWorkbook = application.Workbooks.Open(sourceStream); + FileStream destinationStream = new FileStream(Path.GetFullPath(@"Data/DestinationWorkbookTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook destinationWorkbook = application.Workbooks.Open(destinationStream); + + //Clone the workbook + destinationWorkbook = sourceWorkbook.Clone(); + + //Saving the workbook as stream + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write); + destinationWorkbook.SaveAs(outputStream); + + //Dispose streams + outputStream.Dispose(); + destinationStream.Dispose(); + sourceStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Worksheet Features/Copy Worksheet/.NET/Copy Worksheet/README.md b/Worksheet Features/Copy Worksheet/.NET/Copy Worksheet/README.md new file mode 100644 index 00000000..a8442592 --- /dev/null +++ b/Worksheet Features/Copy Worksheet/.NET/Copy Worksheet/README.md @@ -0,0 +1,48 @@ +# How to create worksheets within a workbook? + +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 copy a worksheet and its contents to another workbook. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + FileStream sourceStream = new FileStream(Path.GetFullPath(@"Data/SourceTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook sourceWorkbook = application.Workbooks.Open(sourceStream); + + FileStream destinationStream = new FileStream(Path.GetFullPath(@"Data/DestinationTemplate.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook destinationWorkbook = application.Workbooks.Open(destinationStream); + + #region Copy Worksheet + //Copy first worksheet from the source workbook to the destination workbook + destinationWorkbook.Worksheets.AddCopy(sourceWorkbook.Worksheets[0]); + destinationWorkbook.ActiveSheetIndex = 1; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CopyWorksheet.xlsx"), FileMode.Create, FileAccess.Write); + destinationWorkbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + destinationStream.Dispose(); + sourceStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Worksheet Features/Create Worksheet/.NET/Create Worksheet/README.md b/Worksheet Features/Create Worksheet/.NET/Create Worksheet/README.md new file mode 100644 index 00000000..4d0f7f34 --- /dev/null +++ b/Worksheet Features/Create Worksheet/.NET/Create Worksheet/README.md @@ -0,0 +1,43 @@ +# How to create worksheets within a workbook? + +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 create a worksheets within a workbook. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + #region Create + //The new workbook is created with 5 worksheets + IWorkbook workbook = application.Workbooks.Create(5); + //Creating a new sheet + IWorksheet worksheet = workbook.Worksheets.Create(); + //Creating a new sheet with name “Sample” + IWorksheet namedSheet = workbook.Worksheets.Create("Sample"); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/CreateWorksheet.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 Features/FitToPagesTall/.NET/FitToPagesTall/README.md b/Worksheet Features/FitToPagesTall/.NET/FitToPagesTall/README.md new file mode 100644 index 00000000..eb0271ec --- /dev/null +++ b/Worksheet Features/FitToPagesTall/.NET/FitToPagesTall/README.md @@ -0,0 +1,51 @@ +# How to ensure all rows are displayed on a single printed page? + +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 ensure all rows are displayed on a single printed page. +{% 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 sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + //Sets the fit to page tall as true. + sheet.PageSetup.FitToPagesTall = 1; + sheet.PageSetup.FitToPagesWide = 0; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/FitToPagesTall.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 Features/FitToPagesWide/.NET/FitToPagesWide/README.md b/Worksheet Features/FitToPagesWide/.NET/FitToPagesWide/README.md new file mode 100644 index 00000000..110c6465 --- /dev/null +++ b/Worksheet Features/FitToPagesWide/.NET/FitToPagesWide/README.md @@ -0,0 +1,51 @@ +# How to ensure all columns are displayed on a single printed page? + +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 ensure all columns are displayed on a single printed page. +{% 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 sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + //Sets the fit to page wide as true. + sheet.PageSetup.FitToPagesWide = 1; + sheet.PageSetup.FitToPagesTall = 0; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/FitToPagesWide.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 Features/Freeze Columns/.NET/Freeze Columns/README.md b/Worksheet Features/Freeze Columns/.NET/Freeze Columns/README.md new file mode 100644 index 00000000..1ae0e9ab --- /dev/null +++ b/Worksheet Features/Freeze Columns/.NET/Freeze Columns/README.md @@ -0,0 +1,42 @@ +# How to freeze columns in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to freeze columns in a 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]; + + //Applying freeze columns to the sheet by specifying a cell + worksheet.Range["C1"].FreezePanes(); + + //Set first visible column in the right pane + worksheet.FirstVisibleColumn = 4; + + //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/Worksheet Features/Freeze Rows/.NET/Freeze Rows/README.md b/Worksheet Features/Freeze Rows/.NET/Freeze Rows/README.md new file mode 100644 index 00000000..0699339d --- /dev/null +++ b/Worksheet Features/Freeze Rows/.NET/Freeze Rows/README.md @@ -0,0 +1,42 @@ +# How to freeze rows in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to freeze rows in a 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]; + + //Applying freeze rows to the sheet by specifying a cell + worksheet.Range["A3"].FreezePanes(); + + //Set first visible row in the bottom pane + worksheet.FirstVisibleRow = 3; + + //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/Worksheet Features/Header and Footer/.NET/Header and Footer/README.md b/Worksheet Features/Header and Footer/.NET/Header and Footer/README.md new file mode 100644 index 00000000..cc667946 --- /dev/null +++ b/Worksheet Features/Header and Footer/.NET/Header and Footer/README.md @@ -0,0 +1,47 @@ +# How to add headers and footers to the printed pages? + +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 add headers and footers to the printed pages. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Excel2013; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Adding values in worksheet + worksheet.Range["A1:A600"].Text = "HelloWorld"; + + //Adding text with formatting to page headers + worksheet.PageSetup.LeftHeader = "&KFF0000 Left Header"; + worksheet.PageSetup.CenterHeader = "&KFF0000 Center Header"; + worksheet.PageSetup.RightHeader = "&KFF0000 Right Header"; + + //Adding text with formatting and image to page footers + worksheet.PageSetup.LeftFooter = "&B &18 &K0000FF Left Footer"; + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/image.jpg"), FileMode.Open); + worksheet.PageSetup.CenterFooter = "&G"; + worksheet.PageSetup.CenterFooterImage = Image.FromStream(imageStream); + worksheet.PageSetup.RightFooter = "&P &K0000FF Right Footer"; + + //Saving the workbook as stream + FileStream stream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create); + workbook.SaveAs(stream); + stream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Worksheet Features/Hide Gridlines/.NET/Hide Gridlines/README.md b/Worksheet Features/Hide Gridlines/.NET/Hide Gridlines/README.md new file mode 100644 index 00000000..35fcccfa --- /dev/null +++ b/Worksheet Features/Hide Gridlines/.NET/Hide Gridlines/README.md @@ -0,0 +1,42 @@ +# How to hide the gridlines in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to hide the gridlines in a worksheet. +{% 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 sheet = workbook.Worksheets[0]; + sheet.Range["A1:M20"].Text = "Gridlines"; + + #region Hide Gridlines + //Hide grid line + sheet.IsGridLinesVisible = false; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HideGridlines.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 Features/Hide Row and Column Headers/.NET/Hide Row and Column Headers/README.md b/Worksheet Features/Hide Row and Column Headers/.NET/Hide Row and Column Headers/README.md new file mode 100644 index 00000000..ca7eaba3 --- /dev/null +++ b/Worksheet Features/Hide Row and Column Headers/.NET/Hide Row and Column Headers/README.md @@ -0,0 +1,42 @@ +# How to hide the row and column headings in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to hide the row and column headings in a worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + sheet.Range["A1:M20"].Text = "RowColumnHeader"; + + #region Hide Row and Column Headers + sheet.IsRowColumnHeadersVisible = false; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HideRowandColumnHeaders.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 Features/Hide Row and Column/.NET/Hide Row and Column/README.md b/Worksheet Features/Hide Row and Column/.NET/Hide Row and Column/README.md new file mode 100644 index 00000000..794fc1b5 --- /dev/null +++ b/Worksheet Features/Hide Row and Column/.NET/Hide Row and Column/README.md @@ -0,0 +1,40 @@ +# How to hide rows and columns in an Excel 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to hide rows and columns in an Excel 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]; + + //Hide row and column + worksheet.HideRow(2); + worksheet.HideColumn(2); + + //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/Worksheet Features/Hide Worksheet Tabs/.NET/Hide Worksheet Tabs/README.md b/Worksheet Features/Hide Worksheet Tabs/.NET/Hide Worksheet Tabs/README.md new file mode 100644 index 00000000..c12de084 --- /dev/null +++ b/Worksheet Features/Hide Worksheet Tabs/.NET/Hide Worksheet Tabs/README.md @@ -0,0 +1,44 @@ +# How to hide the worksheet tabs in a workbook? + +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 hide the worksheet tabs in a workbook. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(3); + IWorksheet sheet = workbook.Worksheets[0]; + sheet.Range["A1:M20"].Text = "Tabs"; + + #region Hide Worksheet Tabs + //Hide the tab + workbook.DisplayWorkbookTabs = false; + //set the display tab + workbook.DisplayedTab = 2; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HideWorksheetTabs.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 Features/Hide Worksheet/.NET/Hide Worksheet/README.md b/Worksheet Features/Hide Worksheet/.NET/Hide Worksheet/README.md new file mode 100644 index 00000000..071090c1 --- /dev/null +++ b/Worksheet Features/Hide Worksheet/.NET/Hide Worksheet/README.md @@ -0,0 +1,43 @@ +# How to hide worksheets within a workbook? + +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 hide worksheets within a workbook. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(2); + IWorksheet sheet = workbook.Worksheets[0]; + + sheet.Range["A1:M20"].Text = "visibility"; + + #region Hide Worksheet + //Set visibility + sheet.Visibility = WorksheetVisibility.Hidden; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HideWorksheet.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 Features/Highlight Worksheet Tab/.NET/Highlight Worksheet Tab/README.md b/Worksheet Features/Highlight Worksheet Tab/.NET/Highlight Worksheet Tab/README.md new file mode 100644 index 00000000..56f0502e --- /dev/null +++ b/Worksheet Features/Highlight Worksheet Tab/.NET/Highlight Worksheet Tab/README.md @@ -0,0 +1,41 @@ +# How to highlight worksheet tabs? + +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 highlight worksheet tabs. +{% 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 sheet = workbook.Worksheets[0]; + + #region Highlight Worksheet Tab + //Highlighting sheet tab + sheet.TabColor = ExcelKnownColors.Green; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/HighlightSheetTab.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 Features/IsFitToPage/.NET/IsFitToPage/README.md b/Worksheet Features/IsFitToPage/.NET/IsFitToPage/README.md new file mode 100644 index 00000000..49bbbee6 --- /dev/null +++ b/Worksheet Features/IsFitToPage/.NET/IsFitToPage/README.md @@ -0,0 +1,50 @@ +# How to fit the page content before printing? + +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 fit the page content before printing. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Excel2013; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + // True to fit the content before printing + sheet.PageSetup.IsFitToPage = true; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/IsFitToPage.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 Features/IsSummaryColumnRight/.NET/IsSummaryColumnRight/README.md b/Worksheet Features/IsSummaryColumnRight/.NET/IsSummaryColumnRight/README.md new file mode 100644 index 00000000..d08e5f20 --- /dev/null +++ b/Worksheet Features/IsSummaryColumnRight/.NET/IsSummaryColumnRight/README.md @@ -0,0 +1,53 @@ +# How to display summary data in the rightmost column of 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to display summary data in the rightmost column of the worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + //True to summary columns will appear right of the detail in outlines + sheet.PageSetup.IsSummaryColumnRight = true; + sheet.PageSetup.Orientation = ExcelPageOrientation.Portrait; + sheet.PageSetup.FitToPagesTall = 0; + sheet.PageSetup.IsFitToPage = true; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/SummaryColumnRight.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 Features/IsSummaryRowBelow/.NET/IsSummaryRowBelow/README.md b/Worksheet Features/IsSummaryRowBelow/.NET/IsSummaryRowBelow/README.md new file mode 100644 index 00000000..c9f70d16 --- /dev/null +++ b/Worksheet Features/IsSummaryRowBelow/.NET/IsSummaryRowBelow/README.md @@ -0,0 +1,53 @@ +# How to display summary data in the bottom row of 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to display summary data in the bottom row of the worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + //True to summary rows will appear below detail in outlines + sheet.PageSetup.IsSummaryRowBelow = true; + sheet.PageSetup.FitToPagesWide = 0; + sheet.PageSetup.Orientation = ExcelPageOrientation.Portrait; + sheet.PageSetup.IsFitToPage = true; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/SummaryRowBelow.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 Features/Move Cell Range/.NET/Move Cell Range/README.md b/Worksheet Features/Move Cell Range/.NET/Move Cell Range/README.md new file mode 100644 index 00000000..9cb1e49f --- /dev/null +++ b/Worksheet Features/Move Cell Range/.NET/Move Cell Range/README.md @@ -0,0 +1,44 @@ +# How to move a cell range from one worksheet to another 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to move a cell range from one worksheet to another worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + + IWorksheet sourceWorksheet = workbook.Worksheets[0]; + IWorksheet destinationWorksheet = workbook.Worksheets[1]; + + IRange source = sourceWorksheet.Range[1, 1, 4, 3]; + IRange destination = destinationWorksheet.Range[1, 1, 4, 3]; + + //Move the cell range to the next sheet + source.MoveTo(destination); + + //Saving the workbook as stream + FileStream outputStream = new FileStream("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/Worksheet Features/Move Column/.NET/Move Column/README.md b/Worksheet Features/Move Column/.NET/Move Column/README.md new file mode 100644 index 00000000..1e6d44b9 --- /dev/null +++ b/Worksheet Features/Move Column/.NET/Move Column/README.md @@ -0,0 +1,44 @@ +# How to move a column from one worksheet to another 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to move a column from one worksheet to another worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream ); + + IWorksheet sourceWorksheet = workbook.Worksheets[0]; + IWorksheet destinationWorksheet = workbook.Worksheets[1]; + + IRange source= sourceWorksheet.Range[1, 2]; + IRange destination = destinationWorksheet.Range[1, 2]; + + //Move the entire column to the next sheet + source.EntireColumn.MoveTo(destination); + + //Saving the workbook as stream + FileStream outputStream = new FileStream("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/Worksheet Features/Move Row/.NET/Move Row/README.md b/Worksheet Features/Move Row/.NET/Move Row/README.md new file mode 100644 index 00000000..2d2ca2c1 --- /dev/null +++ b/Worksheet Features/Move Row/.NET/Move Row/README.md @@ -0,0 +1,44 @@ +# How to to move a row from one worksheet to another 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to move a row from one worksheet to another worksheet. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream sourceStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(sourceStream); + + IWorksheet sourceWorksheet = workbook.Worksheets[0]; + IWorksheet destinationWorksheet = workbook.Worksheets[1]; + + IRange sourceRow = sourceWorksheet.Range[2, 1]; + IRange destinationRow = destinationWorksheet.Range[2, 1]; + + //Move the entire row to the next sheet + sourceRow.EntireRow.MoveTo(destinationRow); + + //Saving the workbook as stream + FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + + //Dispose streams + outputStream.Dispose(); + sourceStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Worksheet Features/Move Worksheet/.NET/Move Worksheet/README.md b/Worksheet Features/Move Worksheet/.NET/Move Worksheet/README.md new file mode 100644 index 00000000..071a35ed --- /dev/null +++ b/Worksheet Features/Move Worksheet/.NET/Move Worksheet/README.md @@ -0,0 +1,35 @@ +# How to create worksheets within a workbook? + +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 move a worksheet along with its contents. +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(3); + IWorksheet sheet = workbook.Worksheets[0]; + + //Move the Sheet + sheet.Move(1); + + //Saving the workbook as stream + FileStream stream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite); + workbook.SaveAs(stream); + stream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Worksheet Features/PrintArea/.NET/PrintArea/README.md b/Worksheet Features/PrintArea/.NET/PrintArea/README.md new file mode 100644 index 00000000..cceaab6f --- /dev/null +++ b/Worksheet Features/PrintArea/.NET/PrintArea/README.md @@ -0,0 +1,50 @@ +# How to define a specific range to print? + +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 define a specific range to print. +{% 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 sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + //Sets the range to be printed + sheet.PageSetup.PrintArea = "A1:M20"; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/PrintArea.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 Features/PrintGridlines/.NET/PrintGridlines/README.md b/Worksheet Features/PrintGridlines/.NET/PrintGridlines/README.md new file mode 100644 index 00000000..3540c7e4 --- /dev/null +++ b/Worksheet Features/PrintGridlines/.NET/PrintGridlines/README.md @@ -0,0 +1,50 @@ +# How to print the gridlines of 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to print the gridlines of the worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + //True to cell gridlines are printed on the page + sheet.PageSetup.PrintGridlines = true; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/PrintGridlines.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 Features/PrintHeadings/.NET/PrintHeadings/README.md b/Worksheet Features/PrintHeadings/.NET/PrintHeadings/README.md new file mode 100644 index 00000000..ec0172d3 --- /dev/null +++ b/Worksheet Features/PrintHeadings/.NET/PrintHeadings/README.md @@ -0,0 +1,50 @@ +# How to print row and column headings on each page? + +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 print row and column headings on each page. +{% 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 sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + //True to row and column headings are printed on page + sheet.PageSetup.PrintHeadings = true; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/PrintHeadings.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 Features/PrintTitleColumns/.NET/PrintTitleColumns/README.md b/Worksheet Features/PrintTitleColumns/.NET/PrintTitleColumns/README.md new file mode 100644 index 00000000..991b35fb --- /dev/null +++ b/Worksheet Features/PrintTitleColumns/.NET/PrintTitleColumns/README.md @@ -0,0 +1,50 @@ +# How to set title columns to repeat on each printed page? + +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 set title columns to repeat on each printed page. +{% 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 sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + //Sets the columns to be repeated on the left side of each page + sheet.PageSetup.PrintTitleColumns = "C1:C50"; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/PrintTitleColumns.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 Features/PrintTitleRows/.NET/PrintTitleRows/README.md b/Worksheet Features/PrintTitleRows/.NET/PrintTitleRows/README.md new file mode 100644 index 00000000..d0ba4255 --- /dev/null +++ b/Worksheet Features/PrintTitleRows/.NET/PrintTitleRows/README.md @@ -0,0 +1,50 @@ +# How to set title rows to repeat on each printed page? + +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 set title rows to repeat on each printed page. +{% 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 sheet = workbook.Worksheets[0]; + + for (int i = 1; i <= 50; i++) + { + for (int j = 1; j <= 50; j++) + { + sheet.Range[i, j].Text = sheet.Range[i, j].AddressLocal; + } + } + + #region PageSetup Settings + //Sets the rows to be repeated at the top of each page + sheet.PageSetup.PrintTitleRows = "A1:AX1"; + + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/PrintTitleRows.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 Features/Remove Worksheet/.NET/Remove Worksheet/README.md b/Worksheet Features/Remove Worksheet/.NET/Remove Worksheet/README.md new file mode 100644 index 00000000..3bbecc3f --- /dev/null +++ b/Worksheet Features/Remove Worksheet/.NET/Remove Worksheet/README.md @@ -0,0 +1,42 @@ +# How to create worksheets within a workbook? + +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 remove a worksheet from an Excel workbook. +{% 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); + + #region Remove + //Removing the sheet + workbook.Worksheets[0].Remove(); + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveWorksheet.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/Worksheet Features/Set Zoom Level/.NET/Set Zoom Level/README.md b/Worksheet Features/Set Zoom Level/.NET/Set Zoom Level/README.md new file mode 100644 index 00000000..ee881ca7 --- /dev/null +++ b/Worksheet Features/Set Zoom Level/.NET/Set Zoom Level/README.md @@ -0,0 +1,42 @@ +# How to set the zoom level of a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to set the zoom level of a worksheet. +{% 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 sheet = workbook.Worksheets[0]; + sheet.Range["A1:M20"].Text = "Zoom level"; + + #region Set Zoom Level + //set zoom percentage + sheet.Zoom = 70; + #endregion + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/SetZoomLevel.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 Features/Show Row and Column/.NET/Show Row and Column/README.md b/Worksheet Features/Show Row and Column/.NET/Show Row and Column/README.md new file mode 100644 index 00000000..78e7fc61 --- /dev/null +++ b/Worksheet Features/Show Row and Column/.NET/Show Row and Column/README.md @@ -0,0 +1,40 @@ +# How to show hidden rows and columns in an Excel 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to show hidden rows and columns in an Excel 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]; + + //Show row and column + worksheet.ShowRow(2, true); + worksheet.ShowColumn(2, true); + + //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/Worksheet Features/Split Panes/.NET/Split Panes/README.md b/Worksheet Features/Split Panes/.NET/Split Panes/README.md new file mode 100644 index 00000000..cf36c112 --- /dev/null +++ b/Worksheet Features/Split Panes/.NET/Split Panes/README.md @@ -0,0 +1,46 @@ +# How to split the panes in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to split the panes in a worksheet. +{% 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 sheet = workbook.Worksheets[0]; + + #region Split Panes + //split panes + sheet.FirstVisibleColumn = 2; + sheet.FirstVisibleRow = 5; + sheet.VerticalSplit = 5000; + sheet.HorizontalSplit = 5000; + #endregion + + sheet.ActivePane = 1; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output/SplitPanes.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 Features/UnFreeze Panes/.NET/UnFreeze Panes/README.md b/Worksheet Features/UnFreeze Panes/.NET/UnFreeze Panes/README.md new file mode 100644 index 00000000..2a27e8a0 --- /dev/null +++ b/Worksheet Features/UnFreeze Panes/.NET/UnFreeze Panes/README.md @@ -0,0 +1,39 @@ +# How to unfreeze panes in a 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 Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 5: Include the below code snippet in **Program.cs** to unfreeze panes in a 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]; + + //Unfreeze panes in the worksheet + worksheet.RemovePanes(); + + //Saving the workbook as stream + FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.ReadWrite); + workbook.SaveAs(outputStream); + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +{% endhighlight %} +{% endtabs %} \ No newline at end of file