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

Correctly propagate worksheet style to cells from a worksheet #1134

Merged
merged 2 commits into from
Feb 21, 2019

Conversation

Pankraty
Copy link
Member

@Pankraty Pankraty commented Jan 15, 2019

As @b0bi79 has discovered, ClosedXML does not assign the worksheet style to empty cells that belong to columns or rows which had been initialized before the worksheet style was set.

        [TestCase("A1", TestName = "First cell")] // OK
        [TestCase("A2", TestName = "Cell from initialized row")]  // Fails
        [TestCase("B1", TestName = "Cell from initialized column")]  // Fails
        [TestCase("D4", TestName = "Initialized cell")]  // OK
        [TestCase("F6", TestName = "Non-initialized cell")]  // OK
        public void CellTakesWorksheetStyle(string cellAddress)
        {
            using (var wb = new XLWorkbook())
            {
                var ws = wb.AddWorksheet("Sheet1");
                ws.Column(2);
                ws.Row(2);
                ws.Cell("D4").Value = "Non empty";
                ws.Style.Font.SetFontName("Arial");
                ws.Style.Font.SetFontSize(9);

                var cell = ws.Cell(cellAddress);
                Assert.AreEqual("Arial", cell.Style.Font.FontName);
                Assert.AreEqual(9, cell.Style.Font.FontSize);
            }
        }

@Pankraty Pankraty changed the title WIP Correctly propagate worksheet style to cells from a worksheet Correctly propagate worksheet style to cells from a worksheet Jan 15, 2019
@Pankraty Pankraty requested a review from igitur January 15, 2019 17:51
@Pankraty Pankraty added bug .Report Issues affecting ClosedXML.Report project labels Jan 15, 2019
@b0bi79
Copy link
Member

b0bi79 commented Jan 26, 2019

Alexey, I noticed that the problem recurs if the document was loaded from a file.

@Pankraty
Copy link
Member Author

Please check the #1135. It addresses styles loading and may help.

@b0bi79
Copy link
Member

b0bi79 commented Jan 27, 2019

It did not help. I think it need to fix this code in XLWorkbook_Load.cs method LoadColumns, line 1913:

Int32 styleIndex = col.Style != null ? Int32.Parse(col.Style.InnerText) : -1;
if (styleIndex > 0)
{
    ApplyStyle(xlColumns, styleIndex, s, fills, borders, fonts, numberingFormats);
}
else
{
    xlColumns.Style = DefaultStyle;
}

For columns that do not have their own style, the DefaultStyle is set, but there must be a sheet style.

@Pankraty
Copy link
Member Author

Sounds reasonable. Will take a look at this.

@igitur igitur merged commit bed7e9b into ClosedXML:develop Feb 21, 2019
@igitur igitur added this to the v0.95 milestone Feb 21, 2019
@igitur
Copy link
Member

igitur commented Feb 21, 2019

selfie-6
GitHub Selfies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug .Report Issues affecting ClosedXML.Report project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants