copyTo function doesn't copy locked property

Posted by: mserban on 26 February 2018, 10:06 am EST

    • Post Options:
    • Link

    Posted 26 February 2018, 10:06 am EST

    Hi,

    On my sheet I want to copy all the style, formulas, conditional format etc. to another newly added row. I am using the copyTo function on the active sheet object to achieve that but the locked property doesn’t seem to copy, therefore I have to iterate through all the columns and set the locked property accordingly, causing performance issues.

    This is a snippet of code:

    
    sheet.copyTo(dataRange.row,
                0,
                dataRange.endRow,
                0,
                1,
                sheet.getColumnCount(),
                (GC.Spread.Sheets.CopyToOptions.formula |
                    GC.Spread.Sheets.CopyToOptions.outline |
                    GC.Spread.Sheets.CopyToOptions.span |
                    GC.Spread.Sheets.CopyToOptions.tag |
                    GC.Spread.Sheets.CopyToOptions.conditionalFormat |
                    GC.Spread.Sheets.CopyToOptions.style));
    
    

    How can I copy the locked property?

    Thanks,

    Mircea

  • Posted 27 February 2018, 5:29 pm EST

    Hello,

    Any news on this mater?

    Thank you

  • Posted 28 February 2018, 3:25 am EST

    Hi Mircea,

    I couldn’t reproduce the issue at my end. When copying cells with their Locked property set to true, I could see that the locked property also gets copied. I have attached a gif image which demonstrates this. In the video notice that the cells in Row 9 have locked property set to false and row 6 (the row to be copied) has locked property set to true. On copying row 6 to row 9 using the CopyTo method, the locked property also gets copied. I’ve tested this with v11.SpreadJScopyTo.zip

  • Posted 28 February 2018, 8:15 am EST

    I just figured it out. By default, our sheet is protected and it rang a bell when, looking at your gif, I saw that yours is not. So all I had to do was to unprotect the sheet, use the copyTo method and protect back the sheet. Apparently it can’t copy the locked property when the sheet is protected.

    Thank you!!

  • Posted 1 March 2018, 5:24 am EST

    Glad you figured it out. You’re right in understanding that spread can’t copy the locked property if the sheet is protected.

Need extra support?

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

Learn More

Forum Channels