Click here to Skip to main content
14,970,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this code excel cell are auto fill through database now i want to those cell are fill only they are locked

C#
function CreateExcel() {

            document.all.OA1.CreateNew("Excel.Application");
            var testNo = document.getElementById("<%=txttestno.ClientID %>");
            var PlantCD = document.getElementById("<%=cmbPlant.ClientID %>");

            var sExcelData = Modules_masters_TestMethodMaster_TestMethodMaster.ReExcelScreen(testNo.value, PlantCD.value); // Take excel date to database

            var objExcel = document.OA1.GetApplication();
            var worksheet = objExcel.ActiveSheet; //Excel sheet
            var sdata = sExcelData.value;
            var aRow = sdata.split(',');//Data split

            for (i = 0; i < aRow.length; i++) {
                var aCol = aRow[i].split('#'); //Data split
                for (j = 0; j < aCol.length; j++) {
                    var result = worksheet.cells(i + 1, j + 1).Formula = aCol[j + 1]; // Data fill in excel cell
                  
  if (result != "") {
//For check cell data for locking, here i want to protect or lock my cell data those are fill, they are not change in fill cell only change in blank cell
                        worksheet.cells(i + 1, j + 1).Style.Locked = true; // this code is not work
                                              
                    }
                }
            }
        }
Posted
Updated 14-Mar-13 10:37am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900