Skip to content

Added new kb article spreadprocessing-list-data-validation-cell-range #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions knowledge-base/spreadprocessing-list-data-validation-cell-range.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: Setting List DataValidation Rule to Reference Cell Range in SpreadProcessing
description: Learn how to set up List Data Validation rules in Telerik Document Processing's SpreadProcessing library to reference a cell range instead of using a comma-delimited list.
type: how-to
page_title: Creating List Data Validation Rules Using Cell Ranges in SpreadProcessing
meta_title: Creating List Data Validation Rules Using Cell Ranges in SpreadProcessing
slug: spreadprocessing-list-data-validation-cell-range
tags: spreadprocessing, datavalidation, listdatavalidationrule, cellrange, telerik-document-processing
res_type: kb
ticketid: 1695747
---

## Environment

<table>
<tbody>
<tr>
<td> Product </td>
<td> SpreadProcessing for Telerik Document Processing </td>
</tr>
<tr>
<td> Version </td>
<td> 2025.2.521 </td>
</tr>
</tbody>
</table>

## Description

I want to set a List DataValidation rule in the SpreadProcessing library that uses a cell range as the validation source instead of a comma-delimited list of values. This avoids the 256-character limit imposed by Excel for comma-separated values. How can I achieve this?

This knowledge base article also answers the following questions:
- How to define validation rules with a cell range in SpreadProcessing?
- How to bypass the character limit in validation rules by using cell ranges?
- How to set up list validation using cell ranges in Telerik's SpreadProcessing?

## Solution

To set a List DataValidation rule that references a cell range, use the `ListDataValidationRule` and specify the cell range as the `Argument1`. Follow the steps below:

1. Import the workbook using the `XlsxFormatProvider`.
2. Specify the cell where the validation rule will apply using `CellIndex`.
3. Define the validation parameters, including the cell range for allowed values.
4. Create and assign the `ListDataValidationRule` to the target cell.
5. Export the updated workbook.

Here is an example:

```csharp
// Import the workbook
Workbook workbook;
IWorkbookFormatProvider xlsxFormatProvider = new XlsxFormatProvider();

using (Stream input = new FileStream("input.xlsx", FileMode.Open))
{
workbook = xlsxFormatProvider.Import(input, TimeSpan.FromSeconds(10));
}

// Access the worksheet
var worksheet = workbook.Worksheets[0];

// Define the cell to apply validation
CellIndex dataValidationRuleCellIndex = new CellIndex(4, 4);

// Configure the validation rule context
ListDataValidationRuleContext context = new ListDataValidationRuleContext(worksheet, dataValidationRuleCellIndex);
context.InputMessageTitle = "Restricted input";
context.InputMessageContent = "The input is restricted to the week days.";
context.ErrorStyle = ErrorStyle.Stop;
context.ErrorAlertTitle = "Wrong value";
context.ErrorAlertContent = "The entered value is not valid. Allowed values are the week days!";
context.InCellDropdown = true;

// Set the cell range as the validation source
context.Argument1 = "=$A$1:$A$26";

// Create and apply the validation rule
ListDataValidationRule rule = new ListDataValidationRule(context);
worksheet.Cells[dataValidationRuleCellIndex].SetDataValidationRule(rule);

// Export the workbook
string xlsxOutputPath = "output.xlsx";
using (Stream output = new FileStream(xlsxOutputPath, FileMode.Create))
{
xlsxFormatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
}
```

## See Also

- [Data Validation](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/features/data-validation#data-validation)
- [List Rule](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/features/data-validation#list-rule)
- [SpreadProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/overview)