ClosedXML / ClosedXML/ClosedXML

FormatCode not saved to conditional style

Open
#2,165 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
5.7k
Forks
933
Avg merge
12h 14m
Merged PRs (30d)
1

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
- [ ] 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.102.1

**What is the current behavior?**

When loading and saving file, the number formatting of a conditional style is lost:
Original file has commas
![image](https://github.com/ClosedXML/ClosedXML/assets/7634052/31cc6215-ed4a-4b15-8b5e-0456b3733ae5)

Resaved file doesn't
![image](https://github.com/ClosedXML/ClosedXML/assets/7634052/1d5da707-c87c-4427-8cf0-e48c1875fd0d)

The cause is missing format code from dxf when saving:
It's a different issue. In the original file, the conditional style refered to a differential style with a numFmt and the resaved file has just a `` with the format code

Original:
```xml



$A3<>"PCT"


$A3="PCT"







```

Resaved one
```xml


$A3<>"PCT"


$A3="PCT"





```

**What is the expected behavior or new feature?**

Format is kept across resaves.

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

No

## 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()
{
using var wbook = new XLWorkbook(@"C:\temp\test_format.xlsx");
wbook.SaveAs(@"C:\temp\test_format_error.xlsx");
}
```

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

Contributor guide

Open the contributing guide

Research direction

Start with the supplied C# reproduction using XLWorkbook.SaveAs and compare the conditional-formatting differential styles before and after saving. Trace how the dxf number format is loaded and serialized, then verify that the format code is retained across a load-and-save cycle for the attached 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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.