question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SetCellValue with DateOnly does not work on .NET 7 project

See original GitHub issue

Doing 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 image

Version 2.6.1 image

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:open
  • Created 2 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tonyquscommented, Aug 3, 2023

@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.

1reaction
lahmacommented, Aug 3, 2023

Packages coming from GitHub actions seem to have correct targets so I guess this has something to do with the release process.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add NET6_0_OR_GREATER preprocessor directive #22625
I'm trying to define some code that will use NET >= 6 features, however I noticed that there is no NET6_0_OR_GREATER preprocessor directive ......
Read more >
Problem binding DateOnly in ASP.NET Core 6 MVC
I am working with an API that only requires the date and did not want to go through the hassle of getting the...
Read more >
What's New in NPOI 2.6.0. With the community help ... - Tony Qu
However, some users complains that this is a Java style interface design. 3. Support DateOnly type (introduced by . NET 6) parameter for...
Read more >
How to use the DateOnly and TimeOnly structures
DateOnly can be parsed from a string, just like the DateTime structure. All of the standard .NET date-based parsing tokens work with DateOnly...
Read more >
Learn DateOnly & TimeOnly
In this article learn how to work with DateOnly and TimeOnly with SqlClient data provider, Newtonsoft Json.net and Entity Framework Core 7.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found