Protect cell contents and formatting for the exported excel

Posted by: eager2knw on 8 September 2017, 1:34 pm EST

  • Posted 8 September 2017, 1:34 pm EST

    Hi,


    How can I prevent the user from making any  cell content changes to exported excel.


    I tried using


    fpSpread1.ActiveSheet.Protect = true;


    fpSpread1.SaveExcel(FileName,


    FarPoint.Excel.ExcelSaveFlags.SaveAsViewed);


    MessageBox.Show("Report Saved Successfully");


    But even this wont work. The user is able to edit the contents in the exported excel sheet.


    Thanks,


    Eager2Knw

  • Replied 8 September 2017, 1:34 pm EST

    Hi,


    Actually Im cloning a spread and the cloned spread Im exporting to excel. 


    I have noticed that the Cloned spread has certain cells which are not locked at the cell level , row level , and column level.


    So the locking the spread at the sheetlevel doesnot helpSmile


    I will have to unlock those cells and then try. Does it make sense.


    Thanks,


    Eager2knw

  • Replied 8 September 2017, 1:34 pm EST

    Setting the Protect property only affects certain aspects of the exported sheet.  You will need to use the Locked property of the cells.
  • Replied 8 September 2017, 1:34 pm EST

    Hi, Im still not able to completely prevent the user from editing the cells in the expoerted excel sheet.


    My Code:


    //Protect the spread


    fpSpread1.ActiveSheet.Protect = true;


    //Lock the whole spread


    fpSpread1.ActiveSheet.DefaultStyle.Locked = true;


    fpTosReportWithCalculations.SaveExcel(FileName,


    FarPoint.Excel.ExcelSaveFlags.SaveAsViewed);


     


    What can I be doing wrong ?


    Pls help


    Thanks ,


    Eager2knw

  • Replied 8 September 2017, 1:34 pm EST

    This code is working perfectly fine for me.
  • Replied 8 September 2017, 1:34 pm EST

    Yes it does.
  • Replied 8 September 2017, 1:34 pm EST

    But I have a problem here. Unlocking the cells in the cloned spread changes the color of those cells to a dark graySad


    I tried setting the


    fpSpread1.ActiveSheet.LockBackColor = Color.Transparent;


    But then, Im not able to see the new backcolor set to these cells.


    fpSpread1.ActiveSheet.Cells [rowIndex, colIndex].BackColor = Color.OldLace;


    Pl help


    Thanks,


    Eager2knw


     

  • Replied 8 September 2017, 1:34 pm EST

    Unlocking the cells should not turn their color to dark gray unless you have set the backcolor somewhere.
  • Replied 8 September 2017, 1:34 pm EST

    Hi,


    I found out the cause for the flaw. All along , I had initially set the LockbackColor as LightSteelBlue . I had set the Sheet's Lock property to true , just before exporting to excel.So whenever , I exported to excel, the sheet would inherit the lockbackcolor. Once, I removed the LockBackColor . There was no problem in locking the Sheet, anymoreSmile


    Thanks,


    Eager2knw 


     

Need extra support?

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

Learn More

Forum Channels