Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Which .NET project can programmatically validate a cell's value out of the box based on Excel data validation constraints?

+2
−0

Are any of the popular Excel .NET projects have a functionality similar to Apache POI's DataValidationEvaluator class?

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+0
−0

Here's a list of popular Excel .NET projects that don't have this functionality:

Has built-in cell validation?
Open XML SDK no*
NPOI no*
EPPlus no? (see section 3. below)
ClosedXML no*

* Non-authoritative answer (i.e., post author couldn't find proof for support)

1. Open XML SDK for Microsoft Office

Can only be used to get or set data validation rules. (See DataValidation class.)

2. NPOI

Couldn't find anything except NPOI.SS.Formula.DataValidationEvaluator (see NOTE below).

NOTE
NPOI was inspired Apache POI, and NPOI.SS.Formula.DataValidationEvaluator seems to mirror Apache POI's DataValidationEvaluator class. However, as of 11/20/2023, NPOI's version only has one method, IsType (whose specs are the same as isType's though).

Also, Apache POIDataValidationEvaluator class' isValidCell method:

public boolean isValidCell(CellReference cellRef)

Use the validation returned by getValidationForCell(CellReference) if you want the error display details. This is the validation checked by this method, which attempts to replicate Excel's data validation rules.

Note that to properly apply some validations, care must be taken to offset the base validation formula by the relative position of the current cell, or the wrong value is checked.

Parameters:
cellRef - The reference of the cell to evaluate

Returns:
true if the cell has no validation or the cell value passes the defined validation, false if it fails

QUESTION
Apache POI's XSSFDataValidationConstraint class also has a validate method, but can't decide based on the docs whether it is germane to this discussion.

3. EPPlus

Found the InternalValidationEnabled property (see below), but I think it is only meant to check the consistency of the data validation rules themselves, and not if the cells conform to them.

class ExcelDataValidationCollection

InternalValidationEnabled
Epplus validates that all data validations are consistent and valid when they are added and when a workbook is saved. Since this takes some resources, it can be disabled for improve performance.

Declaration
public bool InternalValidationEnabled { get; set; }

4. ClosedXML

Based on the sources below, it does not have built-in cell validation.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »