How to copy format of a cell into another cell in Spread JS

Posted by: mobitahir on 13 November 2017, 6:50 am EST

    • Post Options:
    • Link

    Posted 13 November 2017, 6:50 am EST

    Requirement:

    I have a button for format painting. When that button is pressed on a selected cell, i want its format to be copied to the clipboard, and when i select any other cell(s) after that, i want the format of the first cell applyied to the selection. After the format is applyied to the selection i want the clipboard to be cleared. Can anyone provide JavaScript code for achieving this?

  • Posted 14 November 2017, 2:50 am EST

    Hello,

    You can use the code below to copy on a button click

    
    window.onload = function(){
                          var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
                          var sheet = spread.getActiveSheet();
    sheet.setValue(0, 0, 1, GC.Spread.Sheets.SheetArea.viewport);
    sheet.setValue(1, 0, 2, GC.Spread.Sheets.SheetArea.viewport);
    sheet.setFormula(2, 0, "=A1+A2", GC.Spread.Sheets.SheetArea.viewport);
    sheet.setValue(0, 1, 3, GC.Spread.Sheets.SheetArea.viewport);
    sheet.setValue(1, 1, 4, GC.Spread.Sheets.SheetArea.viewport);
    sheet.setFormula(2, 1, "=B1+B2", GC.Spread.Sheets.SheetArea.viewport);
    var fromRange = [new GC.Spread.Sheets.Range(0, 0, 3, 2)];
    var toRanges = [new GC.Spread.Sheets.Range(5, 0, 3, 2)];
    
    $("#button1").click(function () {
        //Cut Paste Action
        spread.commandManager().execute({cmd: "clipboardPaste", sheetName: "Sheet1", fromSheet: sheet, fromRanges: fromRange, pastedRanges: toRanges, isCutting: true, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.all});
    });
    $("#button2").click(function () {
        spread.commandManager().execute({cmd: "clipboardPaste", sheetName: "Sheet1", fromSheet: sheet, fromRanges: fromRange, pastedRanges: toRanges, isCutting: false, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.formatting});
    });
    
    

    Thanks,

    Deepak Sharma

  • Posted 14 November 2017, 3:45 am EST

    I was able to manage it on my own but this helps too. Thanks

Need extra support?

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

Learn More

Forum Channels