ClipboardPaste not working

Posted by: tegbir.singh on 27 November 2017, 7:48 am EST

    • Post Options:
    • Link

    Posted 27 November 2017, 7:48 am EST

    Hi,

    We have used below code (ClipboardCopy/ClipboardPaste function) to copy formulas from one cell to another. it works fine for windows spread. The same code does not work for web sheet.

    public void CopyFormulas(int sheetno, int fromrow, int torow, int col)

    {

    var sheet = form.InpRptSpread.Sheets[sheetno];

    sheet.AddSelection(fromrow, col, 1, 1);

    sheet.[b]ClipboardCopy/b;

            sheet.ActiveColumnIndex = col;
            sheet.ActiveRowIndex = torow;
            sheet.[b]ClipboardPaste[/b](ClipboardPasteOptions.Formulas);
            
        }
    

    Could you please help in this?

  • Posted 28 November 2017, 10:24 am EST

    Hello,

    It looks that you are working with Spread for ASP.NET which is a server side control. You can not access the clipboard server side.

    To copy formula from one cell to another cell you can use the GetFormula and SetFormula methods client side.

    For example:

    
     <script type="text/javascript">    
            function CopyFormula()
            {
                var eqnt = FpSpread1.GetFormula(0, 1);
                FpSpread1.SetFormula(1, 1, eqnt);
            }
    </script>
    
     <input id="Button2" type="button" value="Copy Formula from cell B1, to cell B2" onclick="CopyFormula()" />
    
    

    I hope it helps.

    Thanks,

    Deepak Sharma

  • Posted 29 November 2017, 1:12 am EST

    Hi Deepak,

    We are working on Angularjs site (with frontend-backend model). In the frontend, we only bind the spread with json (which we get from backend through webapi call).

    In the backend, spread sheet is filled with data and converted into json and passed to the frontend for binding. In this way, we can access the clipboard functionality in the backend.

    The above code is used for copying in both windows application and web application(angular).

    Thanks,

    Tegbir

  • Posted 29 November 2017, 3:32 am EST

    Hello Tegbir,

    The code you used in your example:

    
    public void CopyFormulas(int sheetno, int fromrow, int torow, int col)
    {
    var sheet = form.InpRptSpread.Sheets[sheetno];
    sheet.AddSelection(fromrow, col, 1, 1);
    sheet.ClipboardCopy();
    
    sheet.ActiveColumnIndex = col;
    sheet.ActiveRowIndex = torow;
    sheet.ClipboardPaste(ClipboardPasteOptions.Formulas);
    
    }
    

    is in the code behind. I am not sure if you are working with SpreadJS or Spread for ASP.NET?

    The code which I have given works for Spread for ASP.NET.

    With SpreadJS you can write code in JavaScript to copy only formulas for a range or cell and paste it to desired range or cell.

    
    $("#button1").click(function () {
        spread.commandManager().execute({cmd: "clipboardPaste", sheetName: "Sheet1", fromSheet: sheet, fromRanges: fromRange, pastedRanges: toRanges, isCutting: false, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.formulas});
    });
    
    

    I hope it helps.

    Thanks,

    Deepak Sharma

  • Posted 6 December 2017, 1:07 am EST

    Hi Deepak,

    We are creating a spread/sheet object in C# using the above given code. Clipboard copy and paste is written in C# code. Sheet object is created successfully and works fine.

    For our web version which is in angular 4, we are just calling the C# code and returning the object as JSON.

    Now this JSON object which is returned to angular, the copied cells do not have the formula.

    Even when we are debugging the C# code called from angular, the formula is not there but when debugged alone from desktop app the formula is present.

    P.S:- For desktop(C#) we are using spread 9 and for web(angular 4) we are using spreadJS 10.

    Thanks,

    Tegbir

  • Posted 6 December 2017, 12:35 pm EST

    Hello,

    Could you please provide me the JSON file which does not include the formulas? And also the application which you are using to create this JSON file for SpreadJS(in Angular app).

    Thanks,

    Deepak Sharma

  • Posted 13 December 2017, 7:33 am EST

    Hi,

    We have found a solution for clipboardpaste issue.

    Below is the code for that.

    var cellRange = new CellRange(fromrow, col, 1, 1);

    var dataObject = sheet.GetClipDataObject(false, cellRange, ClipboardCopyOptions.Formulas);

    sheet.ClipboardPaste(ClipboardPasteOptions.Formulas, dataObject);

    Thanks,

    Tegbir

  • Posted 13 December 2017, 10:45 am EST

    Thanks for sharing.

    Regards,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels