حماية وعدم حماية المصنفات

حماية مصنف

لفتح ملف Excel Microsoft موجود ، قم بحماية المصنف بالهيكل والخصائص Windows واحفظ الملف.

فيما يلي مقتطفات التعليمات البرمجية المتوازية لـ VSTO (C# ، VB) و Aspose.Cells for .NET (C# ، VB) التي توضح كيفية حماية مصنف.

VSTO

C#

 .......

using Microsoft.VisualStudio.Tools.Applications.Runtime;

using Excel = Microsoft.Office.Interop.Excel;

using Office = Microsoft.Office.Core;

using System.Reflection;

.......

//Instantiate the Application object.

Excel.Application excelApp = new Excel.ApplicationClass();

//Specify the template excel file path.

string myPath = @"d:\test\MyBook.xls";

//Open the excel file.

excelApp.Workbooks.Open(myPath, Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value);

//Protect the workbook specifying a password with Structure and Windows attributes.

excelApp.ActiveWorkbook.Protect("007", true, true);

//Save the file.

excelApp.ActiveWorkbook.Save();

//Quit the Application.

excelApp.Quit();

Aspose.Cells for .NET

C#

 .......

using Aspose.Cells;

.......


//Specify the template excel file path.

string myPath = @"d:\test\MyBook.xls";

//Instantiate a new Workbook.

//Open the excel file.

Workbook workbook = new Workbook(myPath);

//Protect the workbook specifying a password with Structure and Windows attributes.

workbook.Protect(ProtectionType.All,"007");

//Save As the excel file.

workbook.Save(@"d:\test\MyBook.xls");

غير حماية مصنف

لإلغاء حماية مصنف ، استخدم سطور التعليمات البرمجية التالية لـ VSTO (C#، VB) و Aspose.Cells for .NET (C#، VB).

VSTO

C#

 //Unprotect the workbook specifying its password.

excelApp.ActiveWorkbook.Unprotect("007");

Aspose.Cells for .NET

C#

 //Unprotect the workbook specifying its password.

workbook.Unprotect("007");