Lock image (or picture) or Get image (or picture) from excel using EPPlus

落爺英雄遲暮 提交于 2019-12-08 15:36:34

问题


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();

回答1:


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.



来源:https://stackoverflow.com/questions/20544041/lock-image-or-picture-or-get-image-or-picture-from-excel-using-epplus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!