### VB.NET Example: Inserting and Applying Template Markers Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/working-with-template-markers This VB.NET snippet demonstrates how to insert simple text, cell-based, and array-based template markers into an Excel sheet and then process them. It shows the setup for marker variables and the application of these markers to generate an output file. ```vbnet Using excelEngine As ExcelEngine = New ExcelEngine() Dim workbook As IWorkbook = excelEngine.Excel.Workbooks.Open("Sample.xlsx") IWorksheet sheet = workbook.Worksheets(0) 'Insert Simple marker sheet.Range("B2").Text = "%Marker" 'Insert marker which gets value of Author name sheet.Range("C2").Text = "%Marker2.Worksheet.Workbook.Author" 'Insert marker which gets cell address sheet.Range("H2").Text = "%ArrayProperty.Cells.Address" 'Create Template Marker Processor Dim marker As ITemplateMarkersProcessor = workbook.CreateTemplateMarkersProcessor() 'Add collections to the marker variables where the name should match with input template marker.AddVariable("Marker", "First test of markers") marker.AddVariable("Marker2", sheet.Range("B2")) marker.AddVariable("ArrayProperty", sheet.Range("B2:G2")) 'Process the markers in the template marker.ApplyMarkers() workbook.Version = ExcelVersion.Excel2013 workbook.SaveAs("TemplateMarker.xlsx") End Using ``` -------------------------------- ### VB.NET Example: Pie Chart Data Labels Setup Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/charts/chart-data-labels This VB.NET code snippet sets up data for a pie chart and configures basic chart properties. It includes assigning data to cells, adding a chart, setting its data range and type, and defining its title and legend position. ```vbnet Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Xlsx Dim workbook As IWorkbook = application.Workbooks.Create(1) Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Assigning data to cells worksheet.Range("A1").Text = "Category" worksheet.Range("B1").Text = "Value" worksheet.Range("A2").Text = "Apples" worksheet.Range("B2").Number = 30 worksheet.Range("A3").Text = "Bananas" worksheet.Range("B3").Number = 45 worksheet.Range("A4").Text = "Cherries" worksheet.Range("B4").Number = 25 'Add a pie chart to the worksheet Dim chart As IChartShape = worksheet.Charts.Add() 'Set data range for the chart chart.DataRange = worksheet.Range("A1:B4") 'Specify chart type chart.ChartType = ExcelChartType.Pie 'Set chart properties chart.IsSeriesInRows = false chart.ChartTitle = "Fruit Distribution" chart.HasLegend = true chart.Legend.Position = ExcelLegendPosition.Right 'Position the chart within the worksheet chart.TopRow = 6 chart.LeftColumn = 1 chart.BottomRow = 20 chart.RightColumn = 10 'Customize data label for the first data point Dim series As IChartSerie = chart.Series(0) series.DataPoints(0).DataLabels.IsCategoryName = True series.DataPoints(0).DataLabels.IsValue = True 'Enable data label callouts for the first data point series.DataPoints(0).DataLabels.ShowLeaderLines = True 'Manually resizing data label area using Manual Layout chart.Series(0).DataPoints(0).DataLabels.Layout.ManualLayout.Left = 0.09 chart.Series(0).DataPoints(0).DataLabels.Layout.ManualLayout.Top = 0.01 'Save the workbook workbook.SaveAs("Output.xlsx") End Using ``` -------------------------------- ### Complete Example: Merge and Unmerge Cells (C# Cross-platform) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/working-with-cell-or-range-formatting A comprehensive C# example demonstrating the merging and unmerging of cells, including workbook creation and saving. ```csharp 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 workbook.SaveAs(Path.GetFullPath("Output/MergeandUnMerge.xlsx")); #endregion } ``` -------------------------------- ### C# Example: Inserting and Applying Template Markers Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/working-with-template-markers This C# snippet demonstrates how to insert simple text, cell-based, and array-based template markers into an Excel sheet and then process them. It shows the setup for marker variables and the application of these markers to generate an output file. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IWorkbook workbook = excelEngine.Excel.Workbooks.Open("Sample.xlsx"); IWorksheet sheet = workbook.Worksheets[0]; //Insert Simple marker sheet.Range["B2"].Text = "%Marker"; //Insert marker which gets value of Author name sheet.Range["C2"].Text = "%Marker2.Worksheet.Workbook.Author"; //Insert marker which gets cell address sheet.Range["H2"].Text = "%ArrayProperty.Cells.Address"; //Create Template Marker Processor ITemplateMarkersProcessor marker = workbook.CreateTemplateMarkersProcessor(); //Add collections to the marker variables where the name should match with input template marker.AddVariable("Marker", "First test of markers"); marker.AddVariable("Marker2", sheet.Range["B2"]); marker.AddVariable("ArrayProperty", sheet.Range["B2:G2"]); //Process the markers in the template marker.ApplyMarkers(); workbook.Version = ExcelVersion.Excel2013; workbook.SaveAs("TemplateMarker.xlsx"); } ``` -------------------------------- ### Install Syncfusion and SkiaSharp NuGet Packages Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-read-edit-excel-files-in-blazor-c-sharp Install the necessary Syncfusion and SkiaSharp NuGet packages for Blazor WASM using the dotnet CLI. ```bash dotnet add package SkiaSharp.Views.Blazor dotnet add package Syncfusion.XlsIORenderer.Net.Core ``` -------------------------------- ### Complete Example: Merge and Unmerge Cells (C# Windows-specific) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/working-with-cell-or-range-formatting A C# example for Windows demonstrating merging and unmerging cells, setting the Excel version, and saving the workbook. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Excel2013; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; //Merging cells worksheet.Range["A16:C16"].Merge(); //Un-Merging merged cells worksheet.Range["A16:C16"].UnMerge(); workbook.SaveAs("MergingUnMerging.xlsx"); } ``` -------------------------------- ### Complete Example: Merge and Unmerge Cells (VB.NET Windows-specific) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/working-with-cell-or-range-formatting A VB.NET example for Windows demonstrating merging and unmerging cells, setting the Excel version, and saving the workbook. ```vbnet Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Excel2013 Dim workbook As IWorkbook = application.Workbooks.Create() Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Merging cells worksheet.Range("A16:C16").Merge() 'Un-Merging merged cells worksheet.Range("A16:C16").UnMerge() workbook.SaveAs("MergingUnMerging.xlsx") End Using ``` -------------------------------- ### Enable Summary Row Below with Page Setup Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/worksheet/page-setup-options Use this code to set IsSummaryRowBelow to true. Ensure page orientation is Portrait, FitToPagesWide is 0, and IsFitToPage is true. This example populates a sheet with data before applying page setup. ```csharp 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(); } ``` ```csharp 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; } } //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; //Saving the workbook workbook.SaveAs("Output.xlsx"); } ``` ```vb.net Using excelEngine As New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Xlsx Dim workbook As IWorkbook = application.Workbooks.Create(1) Dim sheet As IWorksheet = workbook.Worksheets(0) For i As Integer = 1 To 50 For j As Integer = 1 To 50 sheet.Range(i, j).Text = sheet.Range(i, j).AddressLocal Next Next '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 'Saving the workbook workbook.SaveAs("Output.xlsx") End Using ``` -------------------------------- ### Navigate to the sample application directory Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/loading-and-saving/loading-and-saving-excel-files-in-google-app-engine Use the 'cd' command to change the current directory to your sample application's folder. This is necessary before running the application. ```c# cd LoadingandSaving ``` -------------------------------- ### Complete Excel Border Settings Example Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/working-with-cell-or-range-formatting A full example demonstrating the initialization of an Excel application, workbook, and worksheet, followed by applying various border settings and saving the workbook. Ensure the ExcelEngine is properly disposed of. ```vb.net Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Excel2013 Dim workbook As IWorkbook = application.Workbooks.Create(1) Dim worksheet As IWorksheet = workbook.Worksheets(0) '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 'Inside Horizontal Border worksheet.Range("G2:I5").CellStyle.Borders(ExcelBordersIndex.InsideHorizontal).LineStyle = ExcelLineStyle.Thick 'Inside Vertical Border worksheet.Range("G6:I8").CellStyle.Borders(ExcelBordersIndex.InsideVertical).LineStyle = ExcelLineStyle.Thick 'Apply border color worksheet.Range("A2").CellStyle.Borders.Color = ExcelKnownColors.Blue 'Setting the Border as Range worksheet.Range("G10:I16").BorderAround() worksheet.Range("G10:I16").BorderInside(ExcelLineStyle.Dash_dot, ExcelKnownColors.Red) workbook.SaveAs("BorderSettings.xlsx") End Using ``` -------------------------------- ### Get Calculated Value of a Formula Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/cells-manipulation/list-of-apis-under-irange Demonstrates how to get the evaluated value of a formula in a cell. It's crucial to enable sheet calculations before accessing the CalculatedValue property. The example shows setting numbers, a formula, enabling calculations, retrieving the value, and then disabling calculations. ```APIDOC ## Get Calculated Value of a Formula ### Description Retrieves the evaluated value of a formula within a specified range. ### Method Accessing the `CalculatedValue` property of an `IRange` object. ### Parameters This operation does not take explicit parameters but relies on the `IRange` object it is called upon and the worksheet's calculation state. ### Important Note Sheet calculations must be enabled using `worksheet.EnableSheetCalculations();` before accessing `CalculatedValue`. Failure to do so will result in `CalculatedValue` returning `null`. ### Request Example ```csharp // Assuming 'worksheet' is an IWorksheet object and calculations are enabled string value = worksheet.Range["A3"].CalculatedValue; ``` ### Response #### Success Response - **value** (string) - The calculated value of the formula as a string. #### Response Example ```json { "value": "30" } ``` ``` -------------------------------- ### Create Blazor Server Project Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-read-edit-excel-files-in-blazor-c-sharp Use the dotnet CLI to create a new Blazor Server project and navigate into the project directory. ```bash dotnet new blazorserver -o CreateExcel cd CreateExcel ``` -------------------------------- ### Get Cell Color RGB Value (C# Cross-platform) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-get-the-rgb-color-value-for-the-applied-cell-color Use this C# code to apply a custom color to a cell and then retrieve its RGB values. This example is cross-platform. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; //Create a workbook IWorkbook workbook = application.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; //Apply cell background color worksheet.Range["A1"].CellStyle.ColorIndex = ExcelKnownColors.Custom50; //Get the RGB values of the cell color Color color = worksheet.Range["A1"].CellStyle.Color; byte red = color.R; byte green = color.G; byte blue = color.B; Console.WriteLine($"Red: {red}, Green: {green}, Blue: {blue}"); } ``` -------------------------------- ### Initialize ExcelEngine and Application Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-excel-file-csharp-vbnet Creates a new instance of ExcelEngine and IApplication, similar to launching Microsoft Excel with no workbooks open. This is the first step for creating or manipulating Excel documents. ```csharp //New instance of ExcelEngine is created equivalent to launching Microsoft Excel with no workbooks open //Instantiate the spreadsheet creation engine ExcelEngine excelEngine = new ExcelEngine(); //Instantiate the Excel application object IApplication application = excelEngine.Excel; ``` ```csharp //New instance of ExcelEngine is created equivalent to launching Microsoft Excel with no workbooks open //Instantiate the spreadsheet creation engine ExcelEngine excelEngine = new ExcelEngine(); //Instantiate the Excel application object IApplication application = excelEngine.Excel; ``` -------------------------------- ### Activate Worksheet in C# [Cross-platform] Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/working-with-excel-worksheet Activates a specific worksheet within an Excel workbook. This example includes setup for application and workbook creation, followed by worksheet activation and saving. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Create(2); IWorksheet sheet = workbook.Worksheets[1]; sheet.Range["A1:M20"].Text = "Activate"; #region Activate Worksheet //Activate the sheet sheet.Activate(); #endregion #region Save //Saving the workbook FileStream outputStream = new FileStream(Path.GetFullPath("Output/ActivateWorksheet.xlsx"), FileMode.Create, FileAccess.Write); workbook.SaveAs(outputStream); #endregion //Dispose streams outputStream.Dispose(); } ``` -------------------------------- ### Fit Columns to One Page (VB.NET Windows-specific) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/worksheet/page-setup-options This VB.NET example shows how to fit all columns onto a single page by setting FitToPagesWide to 1 and FitToPagesTall to 0 in the page setup. ```vbnet Using excelEngine As New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Xlsx Dim workbook As IWorkbook = application.Workbooks.Create(1) Dim sheet As IWorksheet = workbook.Worksheets(0) For i As Integer = 1 To 50 For j As Integer = 1 To 50 sheet.Range(i, j).Text = sheet.Range(i, j).AddressLocal Next Next ' Sets the fit to page wide sheet.PageSetup.FitToPagesWide = 1 sheet.PageSetup.FitToPagesTall = 0 'Saving the workbook workbook.SaveAs("Output.xlsx") End Using ``` -------------------------------- ### Initialize ExcelEngine and Application (VB.NET) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-excel-file-csharp-vbnet Creates a new instance of ExcelEngine and IApplication in VB.NET, similar to launching Microsoft Excel with no workbooks open. This is the first step for creating or manipulating Excel documents. ```vbnet 'New instance of ExcelEngine is created equivalent to launching Microsoft Excel with no workbooks open 'Instantiate the spreadsheet creation engine Dim excelEngine As ExcelEngine = New ExcelEngine 'Instantiate the Excel application object Dim application As IApplication = excelEngine.Excel ``` -------------------------------- ### Access Direct Dependent Cells in VB.NET Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/worksheet-cells-manipulation Demonstrates how to get direct dependent cells from a specified cell within a worksheet and save the workbook. This example requires the Excel file 'FormulaExcel.xlsx' to exist. ```vbnet Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Xlsx Dim workbook As IWorkbook = application.Workbooks.Open("FormulaExcel.xlsx") Dim sheet As IWorksheet = workbook.Worksheets(0) 'Getting dependent cells from the worksheet Dim results1() As IRange = sheet("A1").GetDirectDependents() 'Getting dependent cells from the workbook Dim results2() As IRange = sheet("A1").GetDirectDependents(True) Dim fileName As String = "DirectDependents.xlsx" workbook.SaveAs(fileName) End Using ``` -------------------------------- ### C# Hyperlink Examples (Cross-platform) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-does-xlsio-handle-empty-string-display-text-in-hyperlinks Demonstrates creating hyperlinks with and without explicit display text in C#. When TextToDisplay is not set, the Address is used as the display text. ```csharp //Case 1: Without TextToDisplay - address itself is used as display text IHyperLink hyperlink1 = sheet.HyperLinks.Add(sheet.Range["A1"]); hyperlink1.Type = ExcelHyperLinkType.Url; hyperlink1.Address = "http://www.syncfusion.com"; //Display text will be "http://www.syncfusion.com" //Case 2: With TextToDisplay - provided text is used as display text IHyperLink hyperlink2 = sheet.HyperLinks.Add(sheet.Range["A2"]); hyperlink2.Type = ExcelHyperLinkType.Url; hyperlink2.Address = "http://www.syncfusion.com"; hyperlink2.TextToDisplay = "syncfusion"; //Display text will be "syncfusion" ``` -------------------------------- ### Enter Product and Price Details Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-excel-files-in-asp-net-core-web-api Enters product descriptions, quantities, unit prices, and calculates amounts. Ensure data types (text, number) are correctly assigned. ```csharp //Enter details of products and prices worksheet.Range["A15"].Text = " DESCRIPTION"; worksheet.Range["C15"].Text = "QTY"; worksheet.Range["D15"].Text = "UNIT PRICE"; worksheet.Range["E15"].Text = "AMOUNT"; worksheet.Range["A16"].Text = "Cabrales Cheese"; worksheet.Range["A17"].Text = "Chocos"; worksheet.Range["A18"].Text = "Pasta"; worksheet.Range["A19"].Text = "Cereals"; worksheet.Range["A20"].Text = "Ice Cream"; worksheet.Range["C16"].Number = 3; worksheet.Range["C17"].Number = 2; worksheet.Range["C18"].Number = 1; worksheet.Range["C19"].Number = 4; worksheet.Range["C20"].Number = 3; worksheet.Range["D16"].Number = 21; worksheet.Range["D17"].Number = 54; worksheet.Range["D18"].Number = 10; worksheet.Range["D19"].Number = 20; worksheet.Range["D20"].Number = 30; worksheet.Range["D23"].Text = "Total"; ``` -------------------------------- ### Access Direct Dependent Cells in C# Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/worksheet-cells-manipulation Demonstrates how to get direct dependent cells from a specified cell within a worksheet and save the workbook. This example requires the Excel file 'FormulaExcel.xlsx' to exist. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Open("FormulaExcel.xlsx"); IWorksheet sheet = workbook.Worksheets[0]; //Getting dependent cells from the worksheet IRange[] results1 = sheet["A1"].GetDirectDependents(); //Getting dependent cells from the workbook IRange[] results2 = sheet["A1"].GetDirectDependents(true); string fileName = "DirectDependents.xlsx"; workbook.SaveAs(fileName); } ``` -------------------------------- ### Create a new .NET Core Console Application Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-read-edit-excel-files-in-linux-c-sharp Execute this command in the Linux terminal to initialize a new .NET Core console project. ```KCONFIG dotnet new console ``` -------------------------------- ### Accessing Precedents and Dependents (C# Cross-platform) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/worksheet-cells-manipulation Demonstrates how to get precedents and dependents for a cell, both within the worksheet and across the entire workbook. This example uses cross-platform C# and requires input data. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); 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 } ``` -------------------------------- ### Install Syncfusion XlsIO Package Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-read-edit-excel-files-in-asp-net-core-c-sharp Run this command in your project to add the Syncfusion.XlsIO.Net.Core NuGet package. ```bash dotnet add package Syncfusion.XlsIO.Net.Core ``` -------------------------------- ### Get the Last Cell of a Range (C#) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/cells-manipulation/list-of-apis-under-irange Use the `End` property on an `IRange` object to retrieve the last cell within that range. This example demonstrates its usage in C# for both cross-platform and Windows-specific applications. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; //Last cell in the range IRange lastCell = worksheet.Range["A1:E5"].End; workbook.SaveAs("Output.xlsx"); } ``` ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; //Last cell in the range IRange lastCell = worksheet.Range["A1:E5"].End; workbook.SaveAs("Output.xlsx"); } ``` -------------------------------- ### Create app.yaml Configuration File Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-read-edit-excel-files-in-google-app-engine This command appends the necessary content to create the app.yaml file, configuring the application for the App Engine flexible environment. ```bash cat <> app.yaml env: flex runtime: custom EOT ``` -------------------------------- ### Get First Column Index in VB.NET (Windows-specific) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/cells-manipulation/list-of-apis-under-irange Retrieves the one-based index of the first column in the range "E1:R3" of a worksheet. This example uses the Windows-specific VB.NET API. ```vbnet Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Xlsx Dim workbook As IWorkbook = application.Workbooks.Create(1) Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Get first column in the range Dim firstColumn As Integer = worksheet.Range("E1:R3").Column workbook.SaveAs("Output.xlsx") End Using ``` -------------------------------- ### Create Macro as Document (C# Cross-platform) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/working-with-macros This comprehensive C# example shows how to create a macro-enabled workbook. It includes setting up the Excel engine, creating a workbook, accessing VBA project and modules, adding a simple VBA subroutine, and saving the workbook as a macro-enabled file (.xlsm). ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet sheet = workbook.Worksheets[0]; //Creating Vba project IVbaProject project = workbook.VbaProject; //Accessing vba modules collection IVbaModules vbaModules = project.Modules; // Accessing sheet module IVbaModule vbaModule = vbaModules[sheet.CodeName]; //Adding vba code to the module vbaModule.Code = "Sub Auto_Open\n MsgBox \" Workbook Opened \" \n End Sub"; #region Save //Saving the workbook FileStream outputStream = new FileStream(Path.GetFullPath("Output/MacroAsDocument.xlsm"), FileMode.Create, FileAccess.Write); workbook.SaveAs(outputStream, ExcelSaveType.SaveAsMacro); #endregion //Dispose streams outputStream.Dispose(); } ``` -------------------------------- ### Get First Column Index in C# (Cross-platform) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/cells-manipulation/list-of-apis-under-irange Retrieves the one-based index of the first column in the range "E1:R3" of a worksheet. This example uses the cross-platform C# API. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; //Get first column in the range int firstColumn = worksheet.Range["E1:R3"].Column; workbook.SaveAs("Output.xlsx"); } ``` -------------------------------- ### Blazor Server Page Setup with Syncfusion XlsIO Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-read-edit-excel-files-in-blazor-c-sharp Includes necessary namespaces and service injection for creating Excel files in a Blazor Server application. Ensure the Syncfusion.XlsIO.Net.Core NuGet package is installed. ```csharp @page "/Excel" @using System.IO; @using CreateExcel; @inject CreateExcel.Data.CreateExcel service @inject Microsoft.JSInterop.IJSRuntime JS ``` -------------------------------- ### Create .NET MAUI Project via CLI Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-read-edit-excel-files-in-maui-c-sharp Creates a new .NET MAUI application project using the dotnet CLI and navigates into the project directory. This is an alternative to using Visual Studio. ```bash dotnet new maui -o MAUISample cd MAUISample ``` -------------------------------- ### Freeze Rows in Excel Worksheet (C#) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/worksheet/freeze-panes Use the FreezePanes method on a specified cell to freeze rows above it. Set FirstVisibleRow to define the starting row of the unfrozen area. This example uses cross-platform .NET. ```csharp 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(); } ``` -------------------------------- ### iOS Preview Controller Data Source Implementation Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/loading-and-saving/loading-and-saving-excel-files-in-xamarin-c-sharp Provides the implementation for QLPreviewControllerDataSource to display documents in iOS. Includes helper classes for file system and bundle items. ```csharp using Foundation; using QuickLook; using System; using System.IO; public class PreviewControllerDS : QLPreviewControllerDataSource { //Document cache private QLPreviewItem _item; //Setting the document public PreviewControllerDS(QLPreviewItem item) { _item = item; } //Setting document count to 1 public override nint PreviewItemCount (QLPreviewController controller) { return 1; } //Return the document public override IQLPreviewItem GetPreviewItem (QLPreviewController controller, nint index) { return _item; } } public class QLPreviewItemFileSystem : QLPreviewItem { string _fileName, _filePath; //Setting file name and path public QLPreviewItemFileSystem(string fileName, string filePath) { _fileName = fileName; _filePath = filePath; } //Return file name public override string ItemTitle { get { return _fileName; } } //Retun file path as NSUrl public override NSUrl ItemUrl { get { return NSUrl.FromFilename(_filePath); } } } public class QLPreviewItemBundle : QLPreviewItem { string _fileName, _filePath; //Setting file name and path public QLPreviewItemBundle(string fileName, string filePath) { _fileName = fileName; _filePath = filePath; } //Return file name public override string ItemTitle { get { return _fileName; } } //Retun file path as NSUrl public override NSUrl ItemUrl { get { var documents = NSBundle.MainBundle.BundlePath; var lib = Path.Combine(documents, _filePath); var url = NSUrl.FromFilename(lib); return url; } } } ``` -------------------------------- ### C# [Windows-specific] PivotTable Setup Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/can-pivot-tables-share-calculate-field-names Sets up sample data and workbook structure for demonstrating PivotTable behavior with Syncfusion XlsIO. This code is specific to Windows environments. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Create(3); IWorksheet dataSheet = workbook.Worksheets[0]; IWorksheet pivotSheet1 = workbook.Worksheets[1]; IWorksheet pivotSheet2 = workbook.Worksheets[2]; //Add sample data dataSheet.Range["A1"].Text = "Product"; dataSheet.Range["B1"].Text = "Sales"; dataSheet.Range["C1"].Text = "Cost"; dataSheet.Range["A2"].Text = "Laptop"; dataSheet.Range["B2"].Number = 5000; dataSheet.Range["C2"].Number = 3000; dataSheet.Range["A3"].Text = "Tablet"; dataSheet.Range["B3"].Number = 3000; dataSheet.Range["C3"].Number = 2000; dataSheet.Range["A4"].Text = "Phone"; dataSheet.Range["B4"].Number = 4000; dataSheet.Range["C4"].Number = 2500; ``` -------------------------------- ### Get Hidden Worksheet Names in C# (Cross-platform) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-get-the-list-of-worksheet-names-in-an-excel-workbook Use this snippet to retrieve only the names of hidden worksheets from an Excel workbook. Ensure the 'Syncfusion.XlsIO.NET' NuGet package is installed. The input file path should be correctly specified. ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); //Get the worksheets collection WorksheetsCollection worksheets = workbook.Worksheets as WorksheetsCollection; //Print hidden worksheet names foreach (IWorksheet worksheet in worksheets) { if (worksheet.Visibility == WorksheetVisibility.Hidden) Console.WriteLine(worksheet.Name); } } ``` -------------------------------- ### Create Hello World Excel File in VB.NET (Windows-specific) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-excel-file-csharp-vbnet This VB.NET code demonstrates how to create an Excel file and populate cell A1 with 'Hello World'. This example is intended for Windows environments. ```vbnet Imports Syncfusion.XlsIO 'New instance of ExcelEngine is created equivalent to launching Microsoft Excel with no workbooks open 'Instantiate the spreadsheet creation engine Using excelEngine As ExcelEngine = New ExcelEngine() 'Instantiate the Excel application object Dim application As IApplication = excelEngine.Excel 'Assigns default application version application.DefaultVersion = ExcelVersion.Xlsx 'A new workbook is created equivalent to creating a new workbook in Excel 'Create a workbook with 1 worksheet Dim workbook As IWorkbook = application.Workbooks.Create(1) 'Access first worksheet from workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Adding text to a cell worksheet.Range("A1").Text = "Hello World" 'Saving the workbook to disk in XLSX format workbook.SaveAs("Sample.xlsx") End Using ``` -------------------------------- ### Get Frozen Rows and Columns in VB.NET (Windows-specific) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-get-the-frozen-rows-and-columns-in-an-excel-document Retrieve frozen row and column counts from an Excel document using this VB.NET code. This example is tailored for Windows environments and requires the Syncfusion Excel library. ```vbnet Using excelEngine As ExcelEngine = New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Xlsx Dim workbook As IWorkbook = application.Workbooks.Open("../../Data/InputTemplate.xlsx") Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Get the pane record Dim paneRecord As PaneRecord = CType(worksheet, WorksheetImpl).Pane 'Get the first visible row Dim rowValue As Integer = paneRecord.FirstRow 'Get the first visible column Dim columnValue As Integer = paneRecord.FirstColumn 'Get the number of frozen rows Dim frozenRows As Integer = paneRecord.HorizontalSplit 'Get the number of frozen columns Dim frozenColumns As Integer = paneRecord.VerticalSplit End Using ``` -------------------------------- ### Detect Hidden Column in VB.NET (Windows-specific) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-detect-whether-a-column-is-hidden-in-an-excel-file-using-xlsio This VB.NET example shows how to hide a column and then determine if it is hidden using the ColumnInformation collection. This code is intended for Windows-specific .NET development. Ensure proper Syncfusion XlsIO setup. ```vbnet Using excelEngine As New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Xlsx Dim workbook As IWorkbook = application.Workbooks.Create(1) ' Use the concrete WorksheetImpl when you need access to implementation-specific members Dim sheet As WorksheetImpl = TryCast(workbook.Worksheets(0), WorksheetImpl) ' Hide column 1 sheet.ShowColumn(1, False) ' Detect whether column 1 is hidden Dim hidden As Boolean = sheet.ColumnInformation(1) IsNot Nothing AndAlso sheet.ColumnInformation(1).IsHidden Console.WriteLine($"Column 1 hidden: {hidden}") workbook.SaveAs("Output.xlsx") End Using ``` -------------------------------- ### Create .NET Core Console App Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/create-read-edit-excel-files-in-mac-c-sharp Use the dotnet CLI to create a new console application and navigate into its directory. ```bash dotnet new console -o MacSample cd MacSample ``` -------------------------------- ### Import Collection Objects with Options Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/import-export/import-to-excel This C# example demonstrates importing a list of custom objects into an Excel worksheet using ImportData with ExcelImportDataOptions. It specifies the starting row and column, disables header import, and sets preserve types to false. ```csharp 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 workbook.SaveAs(Path.GetFullPath("Output/ImportDataOptions.xlsx")); #endregion } ``` ```csharp using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Excel2013; 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); workbook.SaveAs("ImportData.xlsx"); } ``` -------------------------------- ### Import Data with Column Formatting (VB.NET) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-apply-the-formatting-for-a-particular-column-while-importing-data-from-collection-objects Demonstrates importing a list of customer data into an Excel worksheet and applying currency formatting to sales columns using DisplayFormatAttribute in VB.NET. ```vbnet Using excelEngine As New ExcelEngine() Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Xlsx Dim workbook As IWorkbook = application.Workbooks.Create(1) Dim worksheet As IWorksheet = workbook.Worksheets(0) ' Import the data to worksheet Dim reports As IList(Of Customer) = GetSalesReports() worksheet.ImportData(reports, 2, 1, False) ' Saving the workbook workbook.SaveAs(Path.GetFullPath("Output/ImportCollectionObjects.xlsx")) End Using ' Gets a list of sales reports Public Function GetSalesReports() As List(Of Customer) Dim reports As New List(Of Customer)() 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 End Function ' Customer details Public Class Customer Public Property SalesPerson As String Public Property SalesJanJun As Integer Public Property SalesJulDec As Integer Public Sub New(name As String, janToJun As Integer, julToDec As Integer) SalesPerson = name SalesJanJun = janToJun SalesJulDec = julToDec End Sub End Class ``` -------------------------------- ### VB.NET Hyperlink Examples (Windows-specific) Source: https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-does-xlsio-handle-empty-string-display-text-in-hyperlinks Demonstrates creating hyperlinks with and without explicit display text in VB.NET for Windows. When TextToDisplay is not set, the Address is used as the display text. ```vbnet 'Case 1: Without TextToDisplay - address itself is used as display text Dim hyperlink1 As IHyperLink = sheet.HyperLinks.Add(sheet.Range("A1")) hyperlink1.Type = ExcelHyperLinkType.Url hyperlink1.Address = "http://www.syncfusion.com" 'Display text will be "http://www.syncfusion.com" 'Case 2: With TextToDisplay - provided text is used as display text Dim hyperlink2 As IHyperLink = sheet.HyperLinks.Add(sheet.Range("A2")) hyperlink2.Type = ExcelHyperLinkType.Url hyperlink2.Address = "http://www.syncfusion.com" hyperlink2.TextToDisplay = "syncfusion" 'Display text will be "syncfusion" ```