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

Conditional format depend on another column range #2322

Open
3 tasks
BOIOpenBanking opened this issue Apr 4, 2024 · 0 comments
Open
3 tasks

Conditional format depend on another column range #2322

BOIOpenBanking opened this issue Apr 4, 2024 · 0 comments

Comments

@BOIOpenBanking
Copy link

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?

  • [] 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 first.

Version of ClosedXML

e.g. 0.95.3

What is the current behavior?

I tried to add a conditional format to a range of cells (column X) that means:
Color all the cells in column X that their value is different than the value on the same row in column Y.
I need to do it in C# , dynamically, without a loop.

What is the expected behavior or new feature?

I expect that will be a way to do something like this:

                    int StatusX = worksheet.FirstRowUsed().CellsUsed().First(c => c.Value.ToString() == "StatusX ").Address.ColumnNumber;
                    var StatusXRange= worksheet.Column(StatusX);

                    int StatusY= worksheet.FirstRowUsed().CellsUsed().First(c => c.Value.ToString() == "StatusY").Address.ColumnNumber;
                    var StatusYRange = worksheet.Column(StatusY);

                    StatusYRange.AddConditionalFormat().WhenIsTrue(StatusY.Value!=StatusX.value).Fill.SetBackgroundColor(XLColor.Cyan); //How should I do it?

What is the best way to do it?

Is this a regression from the previous version?

I dont know

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. Sample spreadsheets should be attached whenever applicable. Remove sensitive information.

Code to reproduce problem:

public void Main()
{
  IXLWorksheet worksheet;
            if (workbook.Worksheets.TryGetWorksheet(sheetName, out worksheet))
            {
                // Worksheet with that name already exists
                
                ws.Clear();
            }
            else
            {
                worksheet= workbook.AddWorksheet(sheetName);
            }
            
            DataTable dt = ToDataTable(itemList);

            worksheet.Cell(1, 1).InsertTable(dt);

int StatusX = worksheet.FirstRowUsed().CellsUsed().First(c => c.Value.ToString() == "StatusX ").Address.ColumnNumber;
                        var StatusXRange= worksheet.Column(StatusX);

                        int StatusY= worksheet.FirstRowUsed().CellsUsed().First(c => c.Value.ToString() == "StatusY").Address.ColumnNumber;
                        var StatusYRange = worksheet.Column(StatusY);

                        StatusYRange.AddConditionalFormat().WhenIsTrue(StatusY.Value!=StatusX.value).Fill.SetBackgroundColor(XLColor.Cyan);


}
  • I attached a sample spreadsheet. (You can drag files on to this issue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant