Aspose.Cells change style of cell

It was possible in previous versions of Aspose Cells to apply changes directly to cell.
Starting from version 7.0 you have to call first GetStyle() method and then call SetStyle(s) method.

You can use simple extension method to mimic old behavior.


public static class AsposeCellsExt
    {
        public static void ChangeStyle(this Cell cell, Action<Style> applyChangesTo)
        {
            Style s = cell.GetStyle();
            applyChangesTo(s);
            cell.SetStyle(s);
        }
    }

and now to fill A1 cell with green background you can execute just single line

cells[0, 0].ChangeStyle(s => { s.ForegroundColor = GREEN; s.Pattern = Aspose.Cells.BackgroundType.Solid; });


Enjoy!

No comments:

Asterisk AST_SORCERY function

 AST_SORCERY gets a field from a sorcery object. Sorcery is always created for PJSIP aors, endpoints and identifies in asterisk. It allows y...