ClosedXML / ClosedXML/ClosedXML

If cell contains formula then cell's DataType is not properly recognized

Open
#1,495 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
5.7k
Forks
936
Avg merge
1d 10h
Merged PRs (30d)
5

Description

## Read and complete the full issue template

Do not randomly delete sections. They are here for a reason.

**Do you want to request a *feature* or report a *bug*?**
- [x] Bug
- [ ] Feature
- [x] Question

**Did you test against the latest CI build?**
- [x] Yes
- [ ] No

If you answered `No`, please test with [the latest development build](https://ci.appveyor.com/project/ClosedXML/ClosedXML/branch/develop/artifacts) first.

**Version of ClosedXML**
0.95.999.2073
e.g. 0.95.3

**What is the current behavior?**
If cell contains formula(1+ 2) then cell's DataType property shows as Text even though cell datatype set on UI is Number.

Complete this.

**What is the expected behavior or new feature?**
If cell contains formula(1+ 2) then cell's DataType property should show Number as it is set on UI.

Complete this.

**Is this a regression from the previous version?**
No

Regressions get higher priority. Test against the latest build of the previous minor version. For example, if you experience a problem on v0.95.3, check whether it the problem occurred in v0.94.2 too.

## Reproducibility
**This is an important section. Read it carefully. Failure to do so will cause a 'RTFM' comment.**

Without a code sample, it is unlikely that your issue will get attention. Don't be lazy. Do the effort and assist the developers to reproduce your problem. Code samples should be [minimal complete and verifiable](https://stackoverflow.com/help/mcve). Sample spreadsheets should be attached whenever applicable. Remove sensitive information.

**Code to reproduce problem:**
```c#
public void Main()
{
string fileName = @"";
var xlworkBook = new XLWorkbook(fileName);
if (xlworkBook != null)
{
var sheet1 = xlworkBook.Worksheet("Sheet1");
if (sheet1 != null)
{
var rows = sheet1.RangeUsed().RowsUsed().Skip(1);
foreach (var row in rows)
{
var rowCell = row.Cell(1);
var cellDataType = rowCell.DataType;

Debug.WriteLine("Cell Position: " + rowCell.Address.ToString() +
", Cell Datatype: " + rowCell.DataType.ToString() +
", Cell Has formula: " + rowCell.HasFormula.ToString());

}
}
}
}
```

- [
[CellDataTypeProblem.xlsx](https://github.com/ClosedXML/ClosedXML/files/5084127/CellDataTypeProblem.xlsx)
x] I attached a sample spreadsheet. (You can drag files on to this issue)

Contributor guide

Open the contributing guide

Research direction

Start with the attached CellDataTypeProblem.xlsx and the XLWorkbook, Worksheet, RangeUsed, Cell, DataType, and HasFormula entry points shown in the reproduction. Trace how a formula cell's data type is loaded, then verify that the formula cell reports the numeric type set in Excel and add a regression test covering the workbook.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.