Getting Started with Spread.NET: Installation, Components, and ExamplesSpread.NET is a powerful spreadsheet component library for .NET developers that enables building Excel-like experiences inside desktop, web, and mobile applications. It provides a rich API for creating, manipulating, and displaying spreadsheets with advanced features such as formulas, charts, data binding, styling, protection, import/export, and more. This article walks through installation, core components, and practical examples to help you get started quickly.
What is Spread.NET and when to use it
Spread.NET is a commercial spreadsheet control created to let .NET developers embed full-featured spreadsheet functionality into applications without requiring Microsoft Excel. Use Spread.NET when you need:
- An Excel-like UI embedded in WinForms, WPF, ASP.NET, or ASP.NET Core applications.
- Programmatic creation and manipulation of spreadsheets, formulas, and styles.
- Import/export to/from Excel files (XLS/XLSX) with good fidelity.
- Advanced features such as data binding, charts, pivot tables, protection, and custom cell types.
Spread.NET supports several host platforms and .NET runtimes. Typical delivery includes:
- WinForms control — for classic desktop apps.
- WPF control — for modern desktop apps with WPF UI.
- ASP.NET / ASP.NET Core controls — for web apps (server-side rendering or client-side via WebAssembly/JS interop in some editions).
- .NET Framework and .NET (Core/.NET 5+/6/7/8+) compatibility varies by version; check the specific Spread.NET release notes for exact supported runtimes.
Installation
There are two common ways to install Spread.NET: via the vendor installer (or NuGet packages) and manual assembly references. Below are general steps; consult the Spread.NET documentation for version-specific details.
-
Obtain Spread.NET:
- Download from the vendor website after purchasing or using an evaluation license.
- Or, install via NuGet if packages are published to NuGet.org or a private feed.
-
Install the package:
-
Using NuGet (Package Manager Console):
Install-Package FarPoint.Spread -Version <version>
Replace with the desired Spread.NET package version name (package ID may vary by vendor/edition).
-
Using Visual Studio:
- Open the Solution, right-click References → Manage NuGet Packages → Browse → search for Spread.NET or the vendor package name → Install.
-
Using vendor installer:
- Run the installer, which registers assemblies and installs design-time components and samples into Visual Studio.
-
Add references:
- If not using NuGet, manually add references to the Spread.NET assemblies in your project (DLL files installed by the vendor).
-
Licensing:
- Enter your license key if required. Many commercial controls require adding a license key file or registering a license within Visual Studio or at runtime.
-
Design-time tooling:
- After installation, Spread.NET often installs Visual Studio toolbox components so you can drag controls onto forms or XAML designers.
Core components and concepts
Understanding Spread.NET’s core objects and concepts will make development faster.
- Workbook / WorkbookControl: Represents an entire spreadsheet file/workbook containing one or more sheets (worksheets). In UI controls, this may be exposed as a Workbook object property.
- Worksheet (SheetView / Sheet): Represents a single worksheet. A workbook contains a collection of sheets.
- Cells / Ranges: Individual cells identified by row/column indices. Ranges represent rectangular selections of cells and support batch operations.
- Formulas: Support for Excel-compatible formulas with calculation engine.
- Styles and formatting: Cell styles (fonts, borders, fills, number formats) can be applied to cells, rows, columns, or ranges.
- Data binding: Connect sheets to data sources (DataTable, IList, custom objects) for two-way binding or one-way display.
- Charts: Create embedded charts based on sheet data.
- Import/export: Read and write XLS/XLSX files, CSV, and other formats with varying fidelity.
- Protection and validation: Protect sheets/workbooks, lock cells, and add data validation rules.
- Events and editing: Rich event model for changes, selections, editing, and UI interactions.
- Custom cell types: Buttons, checkboxes, comboboxes, images, and custom renderers/editors.
Basic usage examples
Below are concise examples demonstrating common tasks. APIs vary by Spread.NET version; adapt names to your installed library.
Note: Replace namespaces and class names according to your installed package.
using FarPoint.Win.Spread; using FarPoint.Win.Spread.CellType; // create control (or use designer) /* var spread = new FpSpread(); */ var workbook = new Workbook(); var sheet = workbook.Sheets.Add("Sheet1"); // set values sheet.Cells[0, 0].Value = "Name"; sheet.Cells[0, 1].Value = "Score"; sheet.Cells[1, 0].Value = "Alice"; sheet.Cells[1, 1].Value = 95; sheet.Cells[2, 0].Value = "Bob"; sheet.Cells[2, 1].Value = 82; // apply header style var headerStyle = workbook.CreateStyle(); headerStyle.Font = new Font("Segoe UI", 9, FontStyle.Bold); headerStyle.BackColor = Color.LightGray; sheet.Range["A1:B1"].Style = headerStyle;
2) Loading and saving Excel files
var workbook = new Workbook(); workbook.Open("input.xlsx"); // loads XLSX/XLS depending on API // modify workbook... workbook.Save("output.xlsx");
sheet.Cells[0, 0].Value = "Value"; sheet.Cells[1, 0].Value = 10; sheet.Cells[2, 0].Value = 20; sheet.Cells[3, 0].Formula = "=SUM(A2:A3)"; // or use 1-based Excel referencing if API expects workbook.Calculate(); // trigger calculation if required var sum = sheet.Cells[3, 0].Value;
4) Data binding to a list
var list = new List<Person> { new Person { Name = "Alice", Age = 30 }, new Person { Name = "Bob", Age = 25 } }; sheet.DataSource = list; sheet.SetColumnsFromDataSource(); // illustrative API call; actual method varies
5) Adding a checkbox or combobox cell
var checkBox = new CheckBoxCellType(); sheet.Cells[1, 2].CellType = checkBox; sheet.Cells[1, 2].Value = true; var combo = new ComboBoxCellType(); combo.Items = new string[] { "Red", "Green", "Blue" }; sheet.Cells[1, 3].CellType = combo; sheet.Cells[1, 3].Value = "Green";
Apply fonts, borders, fills, and number formats to ranges. Most APIs provide a Style or CellStyle object you can reuse across cells to improve performance.
Example (pseudocode):
var style = workbook.CreateStyle(); style.Font = new Font("Arial", 10); style.ForeColor = Color.DarkBlue; style.Format = "#,##0.00"; // numeric format sheet.Range["B2:B10"].Style = style;
Charts, images, and drawing objects
Spread.NET supports embedding charts linked to sheet data. Typical steps:
- Create chart object.
- Specify series and data ranges.
- Position chart on the sheet or in a separate chart object layer.
It also supports images and drawing shapes inserted into worksheets.
Events, validation, and protection
- Hook CellChanged, EditModeOn/Off, SelectionChanged, and other events to enforce business rules or update UI.
- Add data validation rules to restrict input (lists, numeric ranges, date ranges).
- Protect sheets/workbooks with passwords and selectively lock/unlock cells.
Example: lock header row and protect sheet:
sheet.RowHeader.Rows[0].Locked = true; sheet.Protect("password");
- Batch updates: suspend painting or begin update/end update while making many changes.
- Reuse Style objects rather than creating new styles for each cell.
- Use range operations to set values/formats for large blocks instead of cell-by-cell loops.
- Disable automatic recalculation during bulk edits, then recalculate once.
Common pitfalls
- API differences: Spread.NET has changed class and method names across versions; consult the specific version’s API docs.
- Formula compatibility: Most Excel formulas are supported, but some advanced or very new Excel functions may behave differently.
- Threading: UI controls must be accessed on the UI thread; perform heavy processing on background threads and marshal results back to UI.
Where to find documentation and samples
- Official vendor documentation and API reference (installed with the product or available on vendor site).
- Sample projects included with the installer that demonstrate WinForms, WPF, and web scenarios.
- Forums and knowledge base articles for migration, troubleshooting, and best practices.
Example mini-project: Simple invoicing sheet
Steps overview:
- Create a workbook with sheets: Invoice, Items, Lookup.
- Bind Items sheet to a list of invoice line items.
- Use formulas to calculate line totals and invoice subtotal/tax/total.
- Add styling for printable layout and header/footer.
- Export to XLSX and PDF.
Key code pieces:
- Data model for line items.
- Binding items to the sheet.
- Formulas like =SUM(LineTotalRange), =Subtotal*TaxRate.
- Print settings and page setup.
Final notes
Spread.NET is a versatile tool for embedding spreadsheet capabilities into .NET applications. Start with the provided samples, follow version-specific docs for API details, and apply performance best practices for large data sets. With styles, data binding, formulas, charts, and import/export features, Spread.NET can replace the need for end-user Excel in many application scenarios.