Need to undo the values of the sheet programatically

Posted by: Anmol.Khandelwal on 29 November 2017, 2:13 am EST

    • Post Options:
    • Link

    Posted 29 November 2017, 2:13 am EST

    Created a sheet where ctrl+z is working fine whenever we edit the data. But if i am change the text to italic,bold,underline the data doesn;t get undo.

    How do i do that?

    $scope.keycharcode = function(e) {

    $scope.keyCode = e.which;

    if (e.ctrlKey && $scope.keyCode == 66){

    buttonShortcut(“bold”);

    }

    else if (e.ctrlKey && $scope.keyCode == 73){

    buttonShortcut(“italic”);

    }

    else if (e.ctrlKey && $scope.keyCode == 90){

    var sheet = spreadsheet.activeSheet();

    var range = sheet.selection();

    var values = range.values();

    buttonShortcut(“undo”);

    }

    This is how trying to call the spread.allowUndo(True) method in js file.

    function buttonShortcut(shortcutname) {

    var $element = $(this),

    name = shortcutname,

    container;

    var sheet = spread.getActiveSheet();

        switch (name) {
            case "bold":
            	setStyleFont(sheet, "font-weight", ["700", "bold"], "normal");
                break;
            case "italic":
                setStyleFont(sheet, "font-style", ["italic"], "normal");
                break;
            case "underline":
                setTextDecoration(sheet, spreadNS.TextDecorationType.Underline);
                break;
            case "strikethrough":
                setTextDecoration(sheet, spreadNS.TextDecorationType.LineThrough);
                break;
            case "overline":
                setTextDecoration(sheet, spreadNS.TextDecorationType.Overline);
                break;
    
            case "increaseIndent":
                setTextIndent(sheet, 1);
                break;
    
            case "decreaseIndent":
                setTextIndent(sheet, -1);
                break;
    
            case "percentStyle":
                setFormatter(uiResource.cellTab.format.percentValue);
                break;
    
            case "commaStyle":
                setFormatter(uiResource.cellTab.format.commaValue);
                break;
    
            case "increaseDecimal":
                increaseDecimal();
                break;
    
            case "decreaseDecimal":
                decreaseDecimal();
                break;
                
            case "undo":
            	undo();    //this function calls the below function.
                break;   
    



    function undo()

    {

    spread.allowUndo(true);

    //var sheet = spread.getActiveSheet();

    // GcSpread.Sheets.SpreadActions.undo.apply(sheettest);

    }

    How do i hold the value of the cell before editing it and after changing the value i get back once i press ctrl+z.

  • Posted 29 November 2017, 10:40 am EST

    Hello,

    You can customize the Undo behavior by implementing the formatting with Undo manager. For example:

    http://help.grapecity.com/spread/SpreadSheets10/webframe.html#JavascriptLibrary~GC.Spread.Commands.CommandManager~register.html

    You can also save the ‘ssjson’ using toJson() method before applying the formatting and load that back using fromJson() method to give an effect of undo.

    Thanks,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels