Overwriting Styles

I extracted a method to apply a series of borders to a given range for a client but the centering of the text was not working and we just realized that if we move the code that centers the cells after the border code the centering comes back.

Right now the method does this

Code:
    Range range = worksheet.Cells.CreateRange(firstRow, firstColumn, totalRows, totalColumns);
    Aspose.CellsStyle borderStyle = workbook.CreateStyle();
<span class="keyword">if</span> (TopBorder || AllBorders)
  borderStyle.Borders[<span class="type">BorderType</span>.TopBorder].LineStyle = CellBorderType.Thin;
<span class="keyword">if</span> (BottomBorder || AllBorders)
  borderStyle.Borders[<span class="type">BorderType</span>.BottomBorder].LineStyle = CellBorderType.Thin;
<span class="keyword">if</span> (LeftBorder || AllBorders)
  borderStyle.Borders[<span class="type">BorderType</span>.LeftBorder].LineStyle = CellBorderType.Thin;
<span class="keyword">if</span> (RightBorder || AllBorders)
  borderStyle.Borders[<span class="type">BorderType</span>.RightBorder].LineStyle = CellBorderType.Thin;

borderStyle.Borders.SetColor(<span class="type">Color</span>.Black);
range.SetStyle(borderStyle);<!--[if IE]>

<![endif]–>

And then applies that to a given range - is there a way to get the current format of each cell and simply "add" to it instead of overwriting it when applying a style to a range or would I need to go cell by cell?

Hi,


I think you may choose Range.ApplyStyle (style, styleFlag) method instead. You may define StyleFlag object and only set the relevant options on related to the style object attributes, then apply the style to the range, it should work fine for your needs. Please see the document for your complete reference (see the example code and description text under the sub topic “Format Ranges…Setting Background Color and Font Attributes to a Named Range” especially):
http://www.aspose.com/docs/display/cellsnet/Named+Ranges

Hope, this helps a bit.

Thank you.




worked perfectly, thanks.

Hi,


Good to know that your issue is sorted out now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.