Quantcast
Viewing all articles
Browse latest Browse all 637

New Post: Worksheet protection. IsLocked=false not working

Hi all,

I'm new to npoi, and i'm trying to protect a worksheet while leaving certain cells open for editing. I've tried everything i can think of.

The sample below is a merger of two of the npoi tutorials

I then tried setting IsLocked = false, but the whole sheet is still protected.

Your help is greatly appreciated

I'm using NPOI v 2.1.1.0
        IWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet1=(XSSFSheet)workbook.CreateSheet("Sheet A1");

        sheet1.CreateRow(0).CreateCell(0).SetCellValue("This is a Sample");
        int x = 1;
        for (int i = 1; i <= 15; i++)
        {
            IRow row = sheet1.CreateRow(i);
            for (int j = 0; j < 15; j++)
            {
                var cell = row.CreateCell(j);
                //cell.CellStyle.IsLocked = false;
                var unlockedstyle = workbook.CreateCellStyle();
                unlockedstyle.IsLocked = false;

                //((Range)xlWorkSheet.Cells[y + 1, x + 1]).Locked = false;
                cell.CellStyle = unlockedstyle;

                cell.SetCellValue(x++);

            }
        }

        sheet1.LockFormatRows();
        sheet1.LockFormatCells();
        sheet1.LockFormatColumns();
        sheet1.LockDeleteColumns();
        sheet1.LockDeleteRows();
        sheet1.LockInsertHyperlinks();
        sheet1.LockInsertColumns();
        sheet1.LockInsertRows();
        sheet1.ProtectSheet("password");


        FileStream sw = File.Create("test.xlsx");
        workbook.Write(sw);
        sw.Close();
I'm using NPOI v 2.1.1.0

Viewing all articles
Browse latest Browse all 637

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>