.NET API Names
The class names of the TX Sheet Control .NET API are short. The package name and the namespace already identify server processing, so the document API uses concise names such as Workbook, Worksheet, TableCollection, Cell and Range.
Read on for the processing entry point, the classes you use for document work, the naming of asynchronous methods and the difference between the spreadsheet Range and System.Range.
How the Names Are Chosen
- The entry point. The .NET processing entry point is ServerSheetControl in the namespace TXTextControl.TXSheetControl.Server.
- The
Asyncsuffix. TheAsyncsuffix of a method name identifies an asynchronous operation. Await these operations. - No aliases. There are no legacy API aliases.
Process a Workbook
The following code writes two amounts and their sum into the first worksheet and saves the workbook as invoice.pdf:
using TXTextControl.TXSheetControl.Server;
await using var control = new ServerSheetControl();
Workbook book = control.Workbook;
Worksheet sheet = await book.Sheets.AtAsync(0);
Cell amount = sheet.Cell("B8");
await amount.SetValueAsync(120);
await sheet.Cell("B9").SetValueAsync(80);
await sheet.Cell("B10").SetFormulaAsync("=SUM(B8:B9)");
await control.SaveAsync("invoice.pdf", StreamType.PDF);
The code works as follows:
new ServerSheetControl()creates a control that owns an independent workbook. Withawait using, DisposeAsync releases the document and its resources at the end.- ServerSheetControl.Workbook returns the workbook. Workbook.Sheets and SheetCollection.AtAsync return the first worksheet, at index 0.
- Worksheet.Cell returns a handle for the cell at an A1 address of the worksheet.
- Cell.SetValueAsync writes a literal value. Cell.SetFormulaAsync writes a formula, which requires the leading equals sign.
- ServerSheetControl.SaveAsync saves the workbook to a file, in the format the StreamType value
PDFselects.
Which Classes You Work With
Use Workbook, Worksheet, Cell, Range and their owned collections for document work:
| Class | Purpose |
|---|---|
| Workbook | Asynchronous workbook editing, formatting, calculation, loading and saving |
| Worksheet | A handle bound to a worksheet ID and an opaque document generation |
| Cell | A worksheet-bound cell handle that separates literal text, formulas, values, formatting and pictures |
| Range | A worksheet-bound rectangular range for atomic reads, writes, formatting and copy operations |
| TableCollection | The Excel tables of a worksheet, with workbook-unique names and stable identities |
| DocumentObject | The base for sheet-bound handles. Its methods perform asynchronous I/O; creating a cell or range handle performs none |
ServerSheetControlOptions, the document limits, locale and font settings for server spreadsheet operations, and ServerSheetControlException describe the processing entry point.
Distinguish Range From System.Range
The spreadsheet Range class and System.Range are different types. Prefer var when you obtain worksheet ranges, or add an alias when you declare the type explicitly:
using Range = TXTextControl.TXSheetControl.Server.Range;
using TXTextControl.TXSheetControl.Server;
async Task SetAmountsAsync(Worksheet sheet)
{
Range amounts = sheet.Range("B8:B9");
await amounts.SetValuesAsync(new object?[][] { [120], [80] });
}
The code works as follows:
- The alias
using Range = TXTextControl.TXSheetControl.Server.Range;makesRangename the spreadsheet class, notSystem.Range. - Worksheet.Range returns a handle for the range
B8:B9. - Range.SetValuesAsync writes 120 into
B8and 80 intoB9.
What the Reference Describes
All signatures, examples and routes of the reference describe the current TX Sheet Control packages. Earlier product namespaces, package names and reference routes are not supported.
Next Steps
- .NET: install the Server package and process a first workbook in .NET.
- Workbooks and Worksheets: workbook ownership, worksheet handles and document replacement.
- Tables: Excel-style tables with named columns and calculated columns.
- .NET API: the namespaces, classes and members of the .NET API.