Spreadsheet - SetCellValue with prevous style

Feb 6, 2014 at 9:57 AM
Edited Feb 6, 2014 at 10:38 AM
I have an XLSX template, where I added styles not to the cells, but to the rows and columns.
If I use WorksheetAccessor.SetCellValue, the style for this cell disappears.

Does anybody know, if it is possible to keep the style for this cell?
At the moment - to solve this for a special template, I've updated the WorksheetAccessor.SetCellValue method by this code.
If the current cell had a style, it uses this for the new text as well. If not, I try to get the style of one of the prevous rows - which works quite well, but it's not always correct.
if (newCell == null)
    throw new ArgumentException("Invalid cell type.");
    // Get the needed cell style
    XElement oldCell = GetCell(worksheetXDocument, column, row);
    // Save the old style id
    XAttribute style = null;
    if (oldCell != null)
        style = oldCell.Attributes(NoNamespace.s).SingleOrDefault();

    // If style wasn't found, look for the style in the last rows
    if (style == null)
        int rowIndex = row;
        XElement prevElement = null;
        while ((prevElement == null) && rowIndex >= 1)
            prevElement = GetCell(worksheetXDocument, column, rowIndex);
            if (prevElement != null)
                style = prevElement.Attributes(NoNamespace.s).SingleOrDefault();
                if (style != null)


    // Set the cell style to the cell
    if (style != null)
        newCell.Add(new XAttribute(NoNamespace.s, style.Value));