Class
SingleWorkbookRepository

Repository for single-document analysis scenarios. Wraps an existing Workbook instance and does not support document creation.

Definition

Namespace:Telerik.Documents.AI.AgentTools.Spreadsheet

Assembly:Telerik.Documents.AI.AgentTools.Spreadsheet.dll

Syntax:

cs-api-definition
public class SingleWorkbookRepository : IWorkbookRepository, IDocumentRepository<Workbook>, IDocumentRepository, ISupportPdfExport

Inheritance: objectSingleWorkbookRepository

Implements: IDocumentRepositoryIDocumentRepository<Workbook>ISupportPdfExportIWorkbookRepository

Constructors

SingleWorkbookRepository(Workbook, string)

Initializes a new instance wrapping an existing workbook.

Declaration

cs-api-definition
public SingleWorkbookRepository(Workbook workbook, string documentName = null)

Parameters

workbook

Workbook

The workbook to wrap.

documentName

string

Optional display name for the document.

Exceptions

ArgumentNullException

Thrown when workbook is null.

Properties

DocumentType

Gets the type of the document represented by this instance.

Declaration

cs-api-definition
public DocumentType DocumentType { get; }

Property Value

DocumentType

Implements IDocumentRepository.DocumentType

SupportsCreation

Gets a value indicating whether this repository supports creating new documents. Single-document repositories typically return false.

Declaration

cs-api-definition
public bool SupportsCreation { get; }

Property Value

bool

Implements IDocumentRepository.SupportsCreation

SupportsMultipleDocuments

Gets a value indicating whether this repository supports managing multiple documents. Single-document repositories return false.

Declaration

cs-api-definition
public bool SupportsMultipleDocuments { get; }

Property Value

bool

Implements IDocumentRepository.SupportsMultipleDocuments

Methods

Clear()

Removes all documents from the repository.

Declaration

cs-api-definition
public void Clear()

Implements IDocumentRepository.Clear()

CreateDocument(string, string[])

Creates a document using the specified document identifier and arguments.

Declaration

cs-api-definition
public string CreateDocument(string documentId, string[] worksheetNames)

Parameters

documentId

string

The unique identifier for the document to be created. Cannot be null or empty.

worksheetNames

string[]

Returns

string

A string containing the contents of the created document.

Implements IDocumentRepository.CreateDocument(string, string[])

Export(string, DocumentFormat, Stream)

Exports a document to a byte array in the specified format.

Declaration

cs-api-definition
public void Export(string documentId, DocumentFormat format, Stream destinationStream)

Parameters

documentId

string

The document identifier to export. If null, exports the default/current document.

format

DocumentFormat

The target format for export.

destinationStream

Stream

The stream to which the document will be exported.

Exceptions

NotSupportedException

Thrown when the specified format is not supported.

KeyNotFoundException

Thrown when the specified document ID does not exist.

Implements IDocumentRepository.Export(string, DocumentFormat, Stream)

ExportToPdf(string, Stream)

Exports the specified document to PDF format and writes the result to the provided stream.

Declaration

cs-api-definition
public void ExportToPdf(string documentId, Stream destinationStream)

Parameters

documentId

string

The unique identifier of the document to export. Cannot be null or empty.

destinationStream

Stream

The stream to which the generated PDF will be written. Must be writable and remain open for the duration of the operation.

Implements ISupportPdfExport.ExportToPdf(string, Stream)

GetDocument(string)

Gets a document by its identifier.

Declaration

cs-api-definition
public Workbook GetDocument(string documentId = null)

Parameters

documentId

string

The document identifier. If null, returns the default/current document. In single-document mode, this parameter is ignored.

Returns

Workbook

The requested document instance.

Exceptions

KeyNotFoundException

Thrown when the specified document ID does not exist.

InvalidOperationException

Thrown when no documents are available and documentId is null.

Implements IDocumentRepository<Workbook>.GetDocument(string)

GetDocumentAsObject(string)

Gets a document by its identifier.

Declaration

cs-api-definition
public object GetDocumentAsObject(string documentId = null)

Parameters

documentId

string

The document identifier. If null, returns the default/current document. In single-document mode, this parameter is ignored.

Returns

object

The requested document instance.

Exceptions

KeyNotFoundException

Thrown when the specified document ID does not exist.

InvalidOperationException

Thrown when no documents are available and documentId is null.

Implements IDocumentRepository.GetDocumentAsObject(string)

Import(Stream, DocumentFormat, string)

Imports a document from a byte array and adds it to the repository.

Declaration

cs-api-definition
public string Import(Stream data, DocumentFormat format, string documentName = null)

Parameters

data

Stream

The document content as a byte array.

format

DocumentFormat

The format of the document being imported.

documentName

string

Optional name for the imported document.

Returns

string

The document ID assigned to the imported document.

Exceptions

NotSupportedException

Thrown when the repository does not support creation or the format is not supported.

Implements IDocumentRepository.Import(Stream, DocumentFormat, string)

ListDocuments()

Lists all documents currently managed by this repository.

Declaration

cs-api-definition
public IEnumerable<DocumentInfo> ListDocuments()

Returns

IEnumerable<DocumentInfo>

Collection of document metadata.

Implements IDocumentRepository.ListDocuments()

MergeAndExport(string[], Stream, DocumentFormat)

Merges the specified source documents and exports the combined result to the provided stream in the specified format.

Declaration

cs-api-definition
public void MergeAndExport(string[] sourceFileIds, Stream stream, DocumentFormat exportFormat)

Parameters

sourceFileIds

string[]

An array of identifiers for the source documents to merge. The order of identifiers determines the order in which documents are merged. Cannot be null or empty.

stream

Stream

The stream to which the merged document will be written. Must be writable and remain open for the duration of the operation.

exportFormat

DocumentFormat

The format in which to export the merged document.

Implements IDocumentRepository.MergeAndExport(string[], Stream, DocumentFormat)

RemoveDocument(string)

Removes a document from the repository.

Declaration

cs-api-definition
public bool RemoveDocument(string documentId)

Parameters

documentId

string

The identifier of the document to remove.

Returns

bool

True if the document was removed; false if not found.

Implements IDocumentRepository.RemoveDocument(string)