# .NET

> Process workbooks in .NET with ServerSheetControl: load an XLSX file, set cell values, export PDF with PdfOptions and create a workbook with a SUM formula.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Getting Started > Document Processing > .NET
- **2205 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/document-processing/dotnet/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/document-processing/dotnet/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/document-processing/dotnet/llms-full.txt

---

`ServerSheetControl` loads, edits, calculates and saves workbooks in a .NET application, without a browser. Two short programs cover the basics: the first changes two cells of an XLSX file and exports it as PDF, the second creates a workbook with a formula and saves it as XLSX.

Set `TX_SHEET_LICENSE` to the contents of your license file, `tx-sheet-control.license`, which the Text Control Account issues for your Trial, Developer or OEM serial number, before running the examples. The server reads this environment setting when the explicit license option is omitted.

### Install the Package

Install `TXTextControl.TXSheetControl.Server` 2.0.0 into a .NET 10 or newer application; [Install the NuGet Packages](https://docs.textcontrol.com/tx-sheet-control/installation/nuget/llms-full.txt) shows how to install it from the Text Control Private NuGet Feed or the `nuget` folder of the download. No browser editor package is required.

The package copies its required processing assets and fonts into both the build and publish output.

> Warning
>
> **Deploy the Complete Output.** Deploy the complete output, rather than selecting only the main assembly.

### Convert an XLSX File to PDF

The following program loads `sales.xlsx`, writes two values and exports the workbook as `sales.pdf`. [Sample Documents](https://docs.textcontrol.com/tx-sheet-control/overview/sample-documents/llms-full.txt) offers a sales spreadsheet named `sales.xlsx` to try it with.

```csharp
using TXTextControl.TXSheetControl.Server;

await using var control = new ServerSheetControl();
await control.LoadAsync("sales.xlsx", StreamType.SpreadsheetML);

var sheet = await control.Workbook.Sheets.AtAsync(0);
await sheet.Cell("D2").SetValueAsync(12);
await sheet.Cell("E2").SetValueAsync(19.5);
await control.SaveAsync("sales.pdf", StreamType.PDF, new SaveOptions
{
    Pdf = new PdfOptions { Locale = "en-US", TimeZone = "UTC" }
});

Console.WriteLine($"Saved {control.LastPdfPageCount} pages.");
```

The code works as follows:

- The [ServerSheetControl](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/llms-full.txt) [constructor](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/constructor/llms-full.txt) creates a control that owns an independent workbook. With `await using`, [DisposeAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/disposeasync-method/llms-full.txt) releases the document and its resources when the control goes out of scope.
- [LoadAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/loadasync-method/llms-full.txt) loads `sales.xlsx`. `StreamType.SpreadsheetML`, a value of [StreamType](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/streamtype/llms-full.txt), is the XLSX format.
- [Workbook](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/workbook-property/llms-full.txt), [Sheets](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbook/sheets-property/llms-full.txt) and [AtAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/sheetcollection/atasync-method/llms-full.txt) return the first worksheet.
- [Cell](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/worksheet/cell-method/llms-full.txt) returns the cells D2 and E2, and [SetValueAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/cell/setvalueasync-method/llms-full.txt) writes the literal values 12 and 19.5 into them.
- [SaveAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/saveasync-method/llms-full.txt) exports the workbook to `sales.pdf` as `StreamType.PDF`. Its [SaveOptions](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/saveoptions/llms-full.txt) hold [PdfOptions](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pdfoptions/llms-full.txt) in the [Pdf](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/saveoptions/pdf-property/llms-full.txt) property, with the [Locale](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pdfoptions/locale-property/llms-full.txt) `en-US` and the [TimeZone](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/pdfoptions/timezone-property/llms-full.txt) `UTC`.
- [LastPdfPageCount](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/lastpdfpagecount-property/llms-full.txt) is the number of pages of the exported PDF, which the program writes to the console.

Set `TX_SHEET_LICENSE` to the contents of your license file before running the program. Developer and OEM server exports have no licensing notices; Trial exports carry trial branding.

### Create a Workbook

The following program creates a workbook from scratch: it fills a range, adds a formula and saves the result as `report.xlsx`.

```csharp
await using var control = new ServerSheetControl();
var sheet = await control.Workbook.Sheets.AtAsync(0);
await sheet.Range("A1:B3").SetValuesAsync(new object?[][]
{
    ["Item", "Amount"], ["Hardware", 120], ["Software", 80]
});

await sheet.Cell("B4").SetFormulaAsync("=SUM(B2:B3)");
await control.SaveAsync("report.xlsx", StreamType.SpreadsheetML);
```

The code works as follows:

- [Range](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/worksheet/range-method/llms-full.txt) returns the range A1:B3, and [SetValuesAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/range/setvaluesasync-method/llms-full.txt) writes the headings `Item` and `Amount` and two items into it, one array per row.
- [SetFormulaAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/cell/setformulaasync-method/llms-full.txt) writes the formula `=SUM(B2:B3)` into B4. The leading equals sign is required.
- `SaveAsync` saves the workbook as `report.xlsx` in the XLSX format, `StreamType.SpreadsheetML`.

### How Addresses and Values Work

- **Cell addresses.** A1 addresses identify cells, such as `"B4"`, and ranges, such as `"A1:B3"`.
- **Indices.** Collection indices are zero-based: `AtAsync(0)` returns the first worksheet.
- **Reading values.** [GetValueAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/cell/getvalueasync-method/llms-full.txt) reads the calculated value of a cell: `GetValueAsync()` returns a `JsonElement` representing the calculated scalar. Use an accessor appropriate to its actual value kind.
- **Numbers.** Supply numeric values rather than localized number strings.

### Handle Requests

For a control that serves requests:

- **Awaiting.** Await every operation before you use its result or dispose its owner.
- **Separate jobs.** Give independent jobs separate documents or controls, or explicitly managed sessions.
- **Reuse.** Reuse can reduce initialization costs, but reload the original input for unrelated requests.
- **Cancellation and failures.** Propagate cancellation tokens, inspect import warnings and report failures, rather than treating canceled exports as success.

### Next Steps

- [Backend Services](https://docs.textcontrol.com/tx-sheet-control/document-processing/backend-services/llms-full.txt): build a request flow that loads a template, applies data and returns the bytes.
- [Lifetime and Concurrency](https://docs.textcontrol.com/tx-sheet-control/document-processing/lifetime/llms-full.txt): plan document ownership, sessions and concurrent jobs.
- [Mail Merge With JSON](https://docs.textcontrol.com/tx-sheet-control/mail-merge/overview/llms-full.txt): fill workbook templates from JSON records.
- [.NET Server Applications](https://docs.textcontrol.com/tx-sheet-control/deployment/dotnet/llms-full.txt): build, publish and deploy the complete application output.
- [Loading and Saving Workbooks](https://docs.textcontrol.com/tx-sheet-control/document-processing/load-save/llms-full.txt): choose the stream type for XLSX, TXWB, PDF, CSV, XML and JSON.

---

## Nearby

- **Previous:** [Document Processing](https://docs.textcontrol.com/tx-sheet-control/getting-started/document-processing/llms-full.txt)
- **Next:** [Node.js](https://docs.textcontrol.com/tx-sheet-control/getting-started/document-processing/nodejs/llms-full.txt)
