Aspose.Cells.AI
26.11.0
Prefix Reserved
Requires NuGet 5.10.0 or higher.
dotnet add package Aspose.Cells.AI --version 26.11.0
NuGet\Install-Package Aspose.Cells.AI -Version 26.11.0
<PackageReference Include="Aspose.Cells.AI" Version="26.11.0" />
<PackageVersion Include="Aspose.Cells.AI" Version="26.11.0" />
<PackageReference Include="Aspose.Cells.AI" />
paket add Aspose.Cells.AI --version 26.11.0
#r "nuget: Aspose.Cells.AI, 26.11.0"
#:package Aspose.Cells.AI@26.11.0
#addin nuget:?package=Aspose.Cells.AI&version=26.11.0
#tool nuget:?package=Aspose.Cells.AI&version=26.11.0
Aspose.Cells.AI
.NET library that brings large language models (LLMs) into spreadsheet workflows: summarize a workbook, ask questions about its data, inspect it for problems, explain or generate formulas, edit it, compare two versions, or route a natural-language request to the right operation automatically.
It works with OpenAI, Anthropic, Aspose.LLM local models, and any provider that implements
Microsoft.Extensions.AI.IChatClient (Azure OpenAI, Gemini, Bedrock, self-hosted gateways, ...).
Installation
dotnet add package Aspose.Cells.AI
For local, on-device inference with Aspose.LLM, including license setup and the IChatClient
adapter, see the
AI-powered Features guide.
Aspose.Cells.AI targets .NET 8.0. It depends on Aspose.Cells, which needs a license for
production use; without one the output carries the evaluation watermark.
Quick start
1. Create the AI client once
CellsAI is a long-lived, reusable object. Create one instance per provider/model/credential
configuration at application startup and pass it to your business methods. Do not create a new
instance for every workbook.
using Aspose.Cells;
using Aspose.Cells.AI;
using var ai = CellsAI.CreateOpenAI(
modelId: Environment.GetEnvironmentVariable("CELLSAI_OPENAI_MODEL")!,
apiKey: Environment.GetEnvironmentVariable("CELLSAI_OPENAI_API_KEY")!,
endpoint: new Uri(
Environment.GetEnvironmentVariable("CELLSAI_OPENAI_ENDPOINT")!));
using var workbook = new Workbook("Sales.xlsx");
WorkbookSummaryResult summary = await ai.SummarizeAsync(workbook);
Console.WriteLine(summary.Summary);
endpoint is optional and defaults to https://api.openai.com/v1/. If that host is blocked or
unreachable from your network, the call fails with CellsAIException (ProviderFailure,
"The provider endpoint could not be reached"). Point CELLSAI_OPENAI_ENDPOINT at a reachable
OpenAI-compatible endpoint (a gateway, Azure OpenAI, DeepSeek, ...), or configure an HTTP
proxy as described in Troubleshooting.
2. Process the workbook
WorkbookAnswerResult answer = await ai.AskAsync(
workbook,
"Which products had the largest revenue decline?");
Console.WriteLine(answer.Answer);
foreach (WorkbookCitation citation in answer.Citations)
{
Console.WriteLine($"{citation.Location.Reference}: {citation.Description}");
}
The same CellsAI instance can be used concurrently for unrelated workbooks. A single Workbook
must not be used by two calls at the same time unless you synchronize access yourself.
Configure a model
OpenAI
using var ai = CellsAI.CreateOpenAI(
modelId: "gpt-4o-mini",
apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")!);
endpoint is optional and expects an absolute base URI:
using var ai = CellsAI.CreateOpenAI(
modelId: "gpt-4o-mini",
apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")!,
endpoint: new Uri("https://llm.example.com/v1"));
Anthropic
using var ai = CellsAI.CreateAnthropic(
modelId: Environment.GetEnvironmentVariable("ANTHROPIC_MODEL")!,
apiKey: Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY")!);
Aspose.LLM (local inference)
Aspose.LLM runs a model inside your process. It is intentionally not part of the
Aspose.Cells.AI package, so applications that do not need local inference do not ship its native
runtime, model files, or license.
Aspose.LLM does not run inference in evaluation mode. It requires its own temporary or commercial Aspose.LLM license; an Aspose.Cells license does not cover it.
For the complete IChatClient adapter, license setup, and preset configuration, see the
AI-powered Features guide.
Any OpenAI-compatible endpoint
CreateOpenAI also works with providers that expose an OpenAI-compatible chat completions API. Pass
the base URI; /chat/completions is appended when needed, or pass the full chat completions URL.
// DeepSeek
using var ai = CellsAI.CreateOpenAI(
modelId: "deepseek-chat",
apiKey: Environment.GetEnvironmentVariable("DEEPSEEK_API_KEY")!,
endpoint: new Uri("https://api.deepseek.com/v1"));
// Gemini via its OpenAI-compatible endpoint
using var gemini = CellsAI.CreateOpenAI(
modelId: "gemini-2.0-flash",
apiKey: Environment.GetEnvironmentVariable("GEMINI_API_KEY")!,
endpoint: new Uri(
"https://generativelanguage.googleapis.com/v1beta/openai/chat/completions"));
Any other provider via IChatClient
CellsAI only depends on the standard Microsoft.Extensions.AI.IChatClient. For providers not
covered by CreateOpenAI/CreateAnthropic (Azure OpenAI, Bedrock, a custom gateway, ...), use that
provider's IChatClient adapter, or write a small one, and pass it in:
using Microsoft.Extensions.AI;
using IChatClient chatClient = CreateMyChatClient();
using var ai = new CellsAI(chatClient);
The constructor borrows the client and the caller disposes it. Use
CellsAI.CreateBuilder().UseOwnedChatClientFactory(...) to let CellsAI own it instead.
Features
Every CellsAIResult exposes Warnings, Usage, Operation, and Text.
Text is a human-readable answer you can display directly, and Operation identifies the operation
that produced it, so you rarely need to inspect the concrete result type. Collections are never
null; they are empty when there is nothing to report. ToString() returns the same text as Text.
| Operation | Method | Result |
|---|---|---|
| Summarize | SummarizeAsync |
WorkbookSummaryResult |
| Ask | AskAsync |
WorkbookAnswerResult |
| Inspect | InspectAsync |
WorkbookInspectionResult |
| Explain formula | ExplainFormulaAsync |
FormulaExplanationResult |
| Generate formula | GenerateFormulaAsync |
FormulaGenerationResult |
| Edit | EditAsync |
WorkbookEditResult |
| Compare (summary) | CompareAsync |
WorkbookComparisonResult |
| Compare (colored workbook) | GenerateComparisonWorkbookAsync |
Workbook |
| Route a request | ProcessAsync |
CellsAIResult (concrete subtype) |
Summarize a workbook
WorkbookSummaryResult result = await ai.SummarizeAsync(workbook);
Console.WriteLine(result.Summary);
foreach (string point in result.KeyPoints)
{
Console.WriteLine($"- {point}");
}
foreach (WorkbookCitation citation in result.Citations)
{
Console.WriteLine(citation.Location.Reference);
}
Limit the readable scope to a table:
var options = new WorkbookContentOptions(
WorkbookLocation.FromTable("Sales", "Orders"));
WorkbookSummaryResult result = await ai.SummarizeAsync(workbook, options);
Ask a question
WorkbookAnswerResult result = await ai.AskAsync(
workbook,
"Which region grew fastest last quarter?");
Console.WriteLine(result.Answer);
AskAsync answers against one workbook or an explicit range. It keeps no conversation history;
each call is independent.
Inspect for problems
Inspection is deterministic and runs locally against the workbook structure and formulas.
WorkbookInspectionResult result = await ai.InspectAsync(workbook);
foreach (WorkbookFinding finding in result.Findings)
{
string location = finding.Location?.Reference ?? "(workbook)";
Console.WriteLine(
$"{finding.Code} [{finding.Severity}] {location}: {finding.Message}");
}
Stable finding codes include FORMULA_ERROR, INCONSISTENT_FORMULA, HARDCODED_VALUE, OUTLIER,
MISSING_VALUE, STRUCTURE_ISSUE, EXTERNAL_LINK, and RISKY_FORMULA.
Limit the categories with WorkbookInspectionOptions.Scope:
var options = new WorkbookInspectionOptions
{
Scope = WorkbookInspectionScope.Formulas | WorkbookInspectionScope.Data
};
Explain a formula
Cell formulaCell = workbook.Worksheets["Forecast"].Cells["F12"];
FormulaExplanationResult result =
await ai.ExplainFormulaAsync(formulaCell);
Console.WriteLine(result.Formula);
Console.WriteLine(result.Explanation);
foreach (WorkbookCitation dependency in result.Dependencies)
{
Console.WriteLine(dependency.Location.Reference);
}
The target cell must contain a formula. Its cell is always included in the model context. Hidden
dependencies are only disclosed when IncludeHiddenContent = true.
Generate a formula
Cell targetCell = workbook.Worksheets["Forecast"].Cells["F12"];
FormulaGenerationResult result = await ai.GenerateFormulaAsync(
targetCell,
"Calculate gross margin from Revenue and Cost.");
Console.WriteLine(result.Formula);
Console.WriteLine(result.Explanation);
Generation does not modify the workbook. Only formulas that pass the Aspose.Cells parser are
returned. The generated formula may reference visible cells in the target worksheet or explicitly
authorized locations; otherwise the operation fails with ContentAccessDenied.
Edit a workbook
EditAsync never modifies the input workbook. It edits a copy and returns it. Writable locations
are an explicit safety boundary chosen by your code, never by the model. Within those locations,
edits can set text, numeric, or Boolean cell values, write formulas, and apply formatting.
var options = new WorkbookEditOptions(
WorkbookLocation.FromTable("Sales", "Orders"));
options.ContextLocations.Add(
WorkbookLocation.FromRange("Sales", "A1:H200"));
using WorkbookEditResult result = await ai.EditAsync(
workbook,
"Add a Total column using a validated formula.",
options);
foreach (WorkbookChange change in result.Changes)
{
Console.WriteLine(
$"{change.Kind}: {change.Location.Reference} - {change.Description}");
}
result.UpdatedWorkbook.Save("Sales.updated.xlsx");
WorkbookEditResult owns UpdatedWorkbook; disposing the result also disposes the workbook. Save
the new workbook to accept the edit.
Highlighting is normal formatting, so it also uses EditAsync; there is no separate
HighlightAsync. When the rule should recalculate as data changes, ask for native conditional
formatting:
var options = new WorkbookEditOptions(
WorkbookLocation.FromTable("Sales", "Orders"));
using WorkbookEditResult result = await ai.EditAsync(
workbook,
"In the Orders table, add conditional formatting: when Actual is less than Target, "
+ "fill only the matching data rows (excluding the header and totals) with "
+ "light red #FCE8E6 and dark red text #B3261E. The highlight must update "
+ "automatically when data changes.",
options);
result.UpdatedWorkbook.Save("Sales.highlighted.xlsx");
If you only want a one-time snapshot highlight, state that explicitly and do not request conditional formatting.
Charts, pictures, shapes, and pivot tables are not sent to the model in v1. An edit request that
targets one of these objects fails with CellsAIException(UnsupportedCapability) before the model
is called; use the Aspose.Cells object model directly for those changes.
Compare two workbooks
Summarize the differences:
using var before = new Workbook("Sales-Previous.xlsx");
using var after = new Workbook("Sales-Current.xlsx");
WorkbookComparisonResult result =
await ai.CompareAsync(before, after);
Console.WriteLine(result.Summary);
foreach (WorkbookDifference difference in result.Differences)
{
WorkbookLocation? location =
difference.AfterLocation ?? difference.BeforeLocation;
Console.WriteLine(
$"{difference.Kind}: {location?.Reference ?? "(workbook)"}");
}
Added content has a null BeforeLocation; removed content has a null AfterLocation. Values,
formulas, formatting, worksheets, tables, and defined names are compared. Restrict the comparison
with WorkbookComparisonOptions.Locations, Dimensions, and IncludeHiddenContent.
Generate a marked-up workbook the way document comparison tools do:
using Workbook comparison =
await ai.GenerateComparisonWorkbookAsync(before, after);
comparison.Save("Sales.comparison.xlsx");
The returned workbook is a copy of after with visual markup:
- Inserted content is shown in blue.
- Deleted content is shown in red at its original location.
- Changed values show the new value in blue followed by the old value in red in the same cell.
- Formatting-only changes leave the text unchanged but colored green.
Route a natural-language request
ProcessAsync classifies a request and dispatches it to one of the operations above. The caller
never chooses the operation, and does not need to switch on the result type to display the answer:
CellsAIResult result = await ai.ProcessAsync(
workbook,
"Check this sheet for problems");
Console.WriteLine(result.Text);
Console.WriteLine(result.Operation); // Inspect
Text is for display. Structured data stays on the concrete result type, so cast only when you need
it:
if (result is WorkbookInspectionResult inspection)
{
foreach (WorkbookFinding finding in inspection.Findings)
{
Console.WriteLine($"{finding.Code} [{finding.Severity}]: {finding.Message}");
}
}
WorkbookEditResult.Text summarizes the applied changes. The edited workbook is available through
UpdatedWorkbook, and the result still owns it:
if (result is WorkbookEditResult edit)
{
using (edit)
{
edit.UpdatedWorkbook.Save("Sales.updated.xlsx");
}
}
Two workbooks enable comparison routing:
CellsAIResult result = await ai.ProcessAsync(
new[] { before, after },
"Compare these two versions");
Routing does not relax safety boundaries. Edit requests still require writable locations, and the classifier only sees worksheet names, table names, and the request text, never workbook content.
var routerOptions = new WorkbookRouterOptions
{
AllowedOperations = new[]
{
WorkbookOperationKind.Summarize,
WorkbookOperationKind.Ask,
WorkbookOperationKind.Inspect
},
FailOnAmbiguous = true
};
routerOptions.WritableLocations.Add(
WorkbookLocation.FromRange("Sales", "D2:D200"));
CellsAIResult result = await ai.ProcessAsync(
workbook,
"Add a ranking column",
routerOptions);
If an edit is routed but WritableLocations is empty, ProcessAsync throws ArgumentException.
Combined or chained requests are not supported in a single call: they fall back to an answer unless
FailOnAmbiguous = true, in which case they throw CellsAIException with AmbiguousRequest.
Control what the model can see
WorkbookLocation is a structured value object for worksheets, cells, ranges, tables, and defined
names. Locations are validated before any content is sent to the model.
WorkbookLocation sheet = WorkbookLocation.FromWorksheet("Sales");
WorkbookLocation cell = WorkbookLocation.FromCell("Sales", "C4");
WorkbookLocation range = WorkbookLocation.FromRange("Sales", "A1:H200");
WorkbookLocation table = WorkbookLocation.FromTable("Sales", "Orders");
WorkbookLocation name = WorkbookLocation.FromDefinedName("TaxRate");
WorkbookLocation localName = WorkbookLocation.FromDefinedName("Sales", "TaxRate");
Read operations accept locations through their options:
var options = new WorkbookContentOptions(
WorkbookLocation.FromRange("Sales", "A1:H200"),
WorkbookLocation.FromTable("Sales", "Orders"));
Hidden worksheets, rows, and columns, and filtered rows are not disclosed by default. Set
IncludeHiddenContent = true only when the operation is allowed to read them:
var options = new WorkbookContentOptions
{
IncludeHiddenContent = true
};
For edits, WritableLocations is the write boundary and ContextLocations is read-only context.
Grant only what the request needs.
Usage and warnings
Console.WriteLine(result.Usage.ProviderName);
Console.WriteLine(result.Usage.ModelId);
Console.WriteLine(result.Usage.InputTokenCount);
Console.WriteLine(result.Usage.OutputTokenCount);
Console.WriteLine(result.Usage.Duration);
foreach (CellsAIWarning warning in result.Warnings)
{
Console.WriteLine($"{warning.Code}: {warning.Message}");
}
Token counts and model ids are null when the provider does not report them; they are never
fabricated.
Error handling
All operation failures use CellsAIException with a stable CellsAIErrorCode:
try
{
WorkbookSummaryResult result = await ai.SummarizeAsync(workbook);
}
catch (CellsAIException ex)
{
Console.WriteLine(ex.ErrorCode);
if (ex.ErrorCode == CellsAIErrorCode.ContentTooLarge)
{
Console.WriteLine(ex.ContentLimitKind);
Console.WriteLine($"{ex.ObservedValue} / {ex.LimitValue}");
}
}
| Error code | Meaning |
|---|---|
InvalidLocation |
The location does not exist, belongs to another workbook, or has the wrong type. |
ContentAccessDenied |
The operation needs hidden or unauthorized content. |
ContentTooLarge |
The content exceeds a field, serialized-size, cell-count, or token limit. |
InvalidModelOutput |
The model output violated the internal structured protocol or local validation. |
UnsupportedCapability |
The provider, model, or v1 scope cannot perform the operation. |
ProviderFailure |
Timeout, network, authentication, rate-limit, or other provider failure. |
AmbiguousRequest |
Routing could not select one operation and FailOnAmbiguous is enabled. |
Provider raw exceptions and credentials are never exposed through the exception.
Troubleshooting
"The provider endpoint could not be reached"
This is a transport failure (DNS, TLS, timeout, connection reset), not an API-key or request problem. Check reachability first:
Invoke-WebRequest https://api.openai.com/v1/models -Method Head -TimeoutSec 10
If the default https://api.openai.com/v1/ host is blocked, use a reachable OpenAI-compatible
endpoint:
using var ai = CellsAI.CreateOpenAI(
modelId: "deepseek-chat",
apiKey: Environment.GetEnvironmentVariable("DEEPSEEK_API_KEY")!,
endpoint: new Uri("https://api.deepseek.com/v1"));
Or configure an HTTP proxy for the process. The built-in clients use HttpClient's default proxy,
which honors system proxy settings and the HTTP_PROXY / HTTPS_PROXY environment variables:
$env:HTTP_PROXY = "http://127.0.0.1:7890" # replace with your proxy port
$env:HTTPS_PROXY = "http://127.0.0.1:7890"
There is no CellsAI.Proxy property in vNext. For full control, create an IChatClient backed by
an HttpClient with your own proxy and pass it to new CellsAI(chatClient).
Requirements
- .NET 8.0 or later.
- A valid Aspose.Cells license for production use.
- An LLM endpoint: OpenAI, Anthropic, an OpenAI-compatible service, Aspose.LLM, or any
IChatClientimplementation. - For Aspose.LLM, a separate temporary or commercial Aspose.LLM license (inference does not run in evaluation mode) and the local model runtime.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Aspose.Cells (>= 26.11.0)
- Microsoft.Extensions.AI.Abstractions (>= 10.9.0)
- Newtonsoft.Json (>= 13.0.3)
- System.Drawing.Common (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.