Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I edit or unprotect a single cell in a protected Excel sheet from C#?
    primarykey
    data
    text
    <p>I'm trying to manipulate an excel file with C# by using Microsoft.Office.Interop.Excel. The workbook I'm trying to manipulate has shared protection between users.</p> <p>I have the file password and I have the password of the cells which I want to access and edit.</p> <p>If I try to do that from Excel, I do the following:</p> <ul> <li>open the file, type the password</li> <li>go to a cell, double click on a cell to edit.</li> <li>a dialogue appears, asking me to provide the password, I provide the password and then I can edit.</li> </ul> <p>I want to do this from a C# application.</p> <p>My current code is as following:</p> <pre><code>xl.Application excelApp = new xl.Application(); excelApp.Visible = true; xl.Workbook newworkbook = excelApp.Workbooks.Open(@"C:\1.xls", 0, false, 5, "password", "", false, xl.XlPlatform.xlWindows, "", true, false, 0, true, false, false); xl.Sheets excelSheets = newworkbook.Worksheets; xl.Worksheet excelWorksheet = (xl.Worksheet)excelSheets.get_Item("Sign On_Off"); excelWorksheet.Select(true); xl.Range myrange = excelWorksheet.get_Range("b16", "b16"); myrange.Value2 = "testing"; </code></pre> <p>The last line gives me this error message:</p> <blockquote> <p>The cell or chart that you are trying to change is protected and therefore read-only.</p> </blockquote> <p>I can't unprotect the whole sheet cause that would mean I will have the file opened exclusively for me only and other users can't save changes.</p> <p>So my question: Is is there is way I can unprotect a cell only?</p> <p>I imagine something like:</p> <pre><code>myrange.unprotect("pw"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload