SetCellValue with DateOnly does not work on .NET 7 project
See original GitHub issueDoing this code:
cell.SetCellValue(DateOnly.FromDateTime(dateTimeValue));
was working on NPOI 2.6.0, in NPOI 2.6.1 this is failing.
Looking at the source code for Cell.cs interface you have the conditional symbol NET6_0_OR_GREATER but this is not being defined so we get a compilation error.
In this issue (https://github.com/dotnet/sdk/issues/22625) is mentioned that the NET6_0_OR_GREATER symbol is only there if the project is targeting .net 6 or greater.
I’m using NPOI in a class library that targets .NET7 so I don’t understand why this could be an issue. In the nuget package manager in visual studio it only shows the dependencies for .netstandard 2.0 and .netstandard 2.1. If I choose version 2.6.0 it shows the dependencies for .netstandard 2.0, .netstandard 2.1, .netframework 4.7.2 and net6.0 thus defining the NET6_0_OR_GREATER symbol (see images below)
Version 2.6.0
Version 2.6.1
Could this be related to the way you deployed the packaged in nuget?
If anybody wants a workaround while this is not fixed you can use the code it does internally:
cell.SetCellValue(DateUtil.GetExcelDate(dateTimeValue, workbook.IsDate1904()));
Issue Analytics
- State:
- Created 2 months ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
@lahma Sorry, it’s my fault. I manually released 2.6.1 as what I did before. I don’t know your GithubAction setup can do it automatically.
The main purpose of getting rid of 6.0 and 4.7.2 version is to reduce the size of the nuget package. I suppose .NET Standard 2.1 can be fully compatible with .NET 6. And all .NET 6.0 feature are usable (such as DateOnly)
I’m thinking releasing a new version. I’m still evaluating the impact of mis-release of NPOI 2.6.1. But it looks not many developers are really using DateOnly feature.
Packages coming from GitHub actions seem to have correct targets so I guess this has something to do with the release process.