Using Undo to Restore Formatting

Posted by: justino98 on 8 September 2017, 1:32 pm EST

  • Posted 8 September 2017, 1:32 pm EST

    I'm working on implementing an undo action for the delete row function.  I'm removing the row using the Remove function, saving the contents using GetArray and saving the formatting using GetCompositeInfo as follows:

                contents = sheetView.GetArray(index, 0, count, 10)

                Dim ssm As FarPoint.Win.Spread.Model.ISheetStyleModel = sheetView.Models.Style

                contentStyle = ssm.GetCompositeInfo(index, -1, -1, Nothing)

                sheetView.Rows.Remove(index, count)

    This approch does not appear to save cell formatting.  I've tried using the GetClip/SetClip and GetArray/SetArray functions but both of these restore values but not formatting (font style, color, etc).  As you can see, I've tried using GetDirectInfo/SetDirectInfo to get and set the formatting seperately but these do not appear to have any affect.

            sheetView.Rows.Add(index, count)

            sheetView.SetArray(index, 0, contents)

            Dim ssm As FarPoint.Win.Spread.Model.ISheetStyleModel = sheetView.Models.Style

            ssm.SetDirectInfo(index, -1, contentStyle) 


    The above restores the cell values correctly, but any cell attributes (formulas, formatting, style, etc) are lost.  I thought of looping through all cells in each deleted row and saving/restoring their attributes individually, but want to make sure there's not a better way.



  • Replied 8 September 2017, 1:32 pm EST


    If you had set the formatting at the row level, then your code to get the StyleInfo for the row should work correctly. If you set the formatting at the Column level or Cell level, then this code will not work and you would need to loop all cells in the row to get the composited formatting at each cell.

  • Replied 8 September 2017, 1:32 pm EST


    Thanks for the reply.  This method (SetArray/SetDirectInfo) works great for restoring values and style info but does not seem to restore formulas. Is there another function I should use to save/restore formula information?  I've looked over the documentation but didn't see anything.

    Thanks again,


  • Replied 8 September 2017, 1:32 pm EST


    If you programatically select the cells you want to copy (in one block) and call the ClipboardCopy method on the SheetView, there is a CellInfoRange object that will be put on the Clipboard that has all the style, data and formulas for the cells that you just copied. You could then store this object for use for the undo action. The SheetView object has a SetClipSpecial, that you can pass in the block of cells and the CellInfoRange object to put the cells (data, styles, and formulas) back in the Spread.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels