Skip to content
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

SetCellValue with DateOnly does not work on .NET 7 project #1118

Closed
antonioatom opened this issue Jul 12, 2023 · 5 comments
Closed

SetCellValue with DateOnly does not work on .NET 7 project #1118

antonioatom opened this issue Jul 12, 2023 · 5 comments
Assignees
Milestone

Comments

@antonioatom
Copy link

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 (dotnet/sdk#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()));

@tonyqus tonyqus added the bug label Jul 13, 2023
@tonyqus tonyqus added this to the NPOI 2.6.1 milestone Jul 13, 2023
@tonyqus tonyqus self-assigned this Jul 13, 2023
@tonyqus
Copy link
Member

tonyqus commented Jul 13, 2023

What do you mean this is failing? What kind of exception do you receive?

@antonioatom
Copy link
Author

antonioatom commented Jul 13, 2023

Sorry, I explained badly... the SetCellValue(DateOnly....) does not exist in the interface for version 2.6.1.
My code is failing because it uses that method. In 2.6.0 it was working fine because the NET6_0_OR_GREATER is defined and the method shows in the interface.

@lahma
Copy link
Collaborator

lahma commented 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

@tonyqus
Copy link
Member

tonyqus commented 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.

@lahma
Copy link
Collaborator

lahma commented Aug 4, 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.

Currently the package is created for each build and follows the version number in VersionPrefix which is located in root Directory.Build.props. With your permission I can configure a preview feed for feedz.io like have for Quartz.NET. Quartz.NET also handles release process by detecting pushed tags to GitHub and then does to automatic release to GitHub. feedz.io would be start for people getting some previews before new releases.

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)

This might not be such an issue. Downloaded package resides in global NuGet packages directory and only target frameworks DLLs are pulled into user's solution build and release artifacts.

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.

👍🏻

@tonyqus tonyqus closed this as completed Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants