This project has moved and is read-only. For the latest updates, please go here.

Passing style-able objects

Nov 12, 2014 at 7:49 PM
Hi, everyone.

I'm working on a project where I am applying the same styling to various things. Sometimes a row, sometimes a cell, sometimes a range. I've been trying to find a way to write a single method that would accept all of those things.

Is there an interface that they all implement, or some other way to maybe do it?

private void applyFormatting(something target)
// etc. etc.
Nov 12, 2014 at 8:48 PM
var style = XLWorkbook.DefaultStyle;
// Change style
cell/range/whatever.Style = style;
Marked as answer by nmadison on 11/12/2014 at 1:48 PM
Nov 12, 2014 at 9:33 PM
That is a cool idea, and I can definitely use that for some things. However, there's often variations between section styles, with MOST of it the same, but a few things different. So I'd still like to use methods to apply groupings of style options to various items.

For instance, if I want to add center alignment, font size, and bolding to a cell, but I want it to maintain its previously set colors, borders, etc.
Nov 12, 2014 at 9:46 PM
        var alignment = style.Alignment;
        cell.Style.Alignment = alignment;
More granular than that and you have to go to the individual properties themselves.
Marked as answer by nmadison on 11/12/2014 at 1:48 PM