Pergunta

I'm using EPPlus for excel export. In that, I've locked image. Through code before insert some values to cells, I've unprotect sheet data or cells.

After unprotect, I've inserted values and locked those cells and then applied protection. For the cells which have data are locked. But the image has unlocked.

Now I'm having only two solution.

  1. How to keep the image (or picture) has locked in sheet.
  2. How to get the image (or picture) from excel and insert that image as embedded.

How to do that ? Here i've given my code.

// If worksheet has protection already, then need to unprotect
                    if (workSheet.Protection.IsProtected)
                        workSheet.Protection.IsProtected = false;
                    else
                        workSheet.Cells.Style.Locked = false;


workSheet.Cells[rowIndex, columnIndex].value="Test";
workSheet.Cells[rowIndex, columnIndex].Style.Locked=true;

// Protect the sheet after cells locked
                    workSheet.Protection.IsProtected = true;
                    workSheet.Protection.SetPassword(BasReportPassword);
                    workSheet.Protection.AllowSelectLockedCells = true;
                    workSheet.Protection.AllowSelectUnlockedCells = true;
                    excelPackage.Save();
Foi útil?

Solução

For already protected sheet no need to give sheet as unprotected. so Leave the sheet as it as protected and make newly created cells as locked . Then it'll work. It doesn't follow as we do manually in the excel sheet.

Remove the following code. Then it'll work.

   if (workSheet.Protection.IsProtected)
          workSheet.Protection.IsProtected = false;

I've checked. Please try this.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top