إعدادات الحماية المتقدمة منذ Excel XP

مقدمة

تقييد أو السماح للمستخدمين بـ:

  • حذف الصفوف أو الأعمدة.
  • تحرير المحتويات أو الكائنات أو السيناريوهات.
  • تنسيق الخلايا أو الصفوف أو الأعمدة.
  • إدراج الصفوف أو الأعمدة أو الروابط الفرعية.
  • تحديد الخلايا المقفلة أو غير المقفلة.
  • استخدام الجداول المحورية وأكثر من ذلك بكثير.

تدعم Aspose.Cells جميع إعدادات الحماية المتقدمة المقدمة من Excel XP أو الإصدارات اللاحقة.

إعدادات الحماية المتقدمة باستخدام Excel XP والإصدارات اللاحقة

لعرض إعدادات الحماية المتاحة في Excel XP:

  1. من القائمة أدوات, اختر الحماية ثم حماية الورقة. سيتم عرض مربع الحوار.

لاستعراض إعدادات الحماية المتوفرة في Excel 2016

  1. من القائمة ملف, اختر حماية الدفتر ثم حماية الورقة الحالية.
  2. حدد حماية الورقة في قائمة مراجعة.

باتباع الخطوات المذكورة أعلاه ستظهر مربع حوار حيث يمكنك السماح أو تقييد ميزات ورقات العمل أو تطبيق كلمة مرور على ورقة العمل.

إعدادات الحماية المتقدمة باستخدام Aspose.Cells

تدعم Aspose.Cells جميع إعدادات الحماية المتقدمة.

توفر Aspose.Cells فئة Workbook تمثل ملف Microsoft Excel. فئة Workbook تحتوي على مجموعة Worksheets تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطة فئة Worksheet.

توفر فئة Worksheet الخاصية Protection المستخدمة لتطبيق هذه الإعدادات المتقدمة للحماية. الخاصية Protection في الواقع هي كائن من فئة Protection الذي يغلف العديد من الخصائص المنطقية لتعطيل أو تمكين القيود.

فيما يلي مثال تطبيقي صغير. يفتح ملف Excel ويستخدم معظم إعدادات الحماية المتقدمة المدعومة من Excel XP والإصدارات اللاحقة.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook excel = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = excel.Worksheets[0];
// Restricting users to delete columns of the worksheet
worksheet.Protection.AllowDeletingColumn = false;
// Restricting users to delete row of the worksheet
worksheet.Protection.AllowDeletingRow = false;
// Restricting users to edit contents of the worksheet
worksheet.Protection.AllowEditingContent = false;
// Restricting users to edit objects of the worksheet
worksheet.Protection.AllowEditingObject = false;
// Restricting users to edit scenarios of the worksheet
worksheet.Protection.AllowEditingScenario = false;
// Restricting users to filter
worksheet.Protection.AllowFiltering = false;
// Allowing users to format cells of the worksheet
worksheet.Protection.AllowFormattingCell = true;
// Allowing users to format rows of the worksheet
worksheet.Protection.AllowFormattingRow = true;
// Allowing users to insert columns in the worksheet
worksheet.Protection.AllowFormattingColumn = true;
// Allowing users to insert hyperlinks in the worksheet
worksheet.Protection.AllowInsertingHyperlink = true;
// Allowing users to insert rows in the worksheet
worksheet.Protection.AllowInsertingRow = true;
// Allowing users to select locked cells of the worksheet
worksheet.Protection.AllowSelectingLockedCell = true;
// Allowing users to select unlocked cells of the worksheet
worksheet.Protection.AllowSelectingUnlockedCell = true;
// Allowing users to sort
worksheet.Protection.AllowSorting = true;
// Allowing users to use pivot tables in the worksheet
worksheet.Protection.AllowUsingPivotTable = true;
// Saving the modified Excel file
excel.Save(dataDir + "output.xls", SaveFormat.Excel97To2003);
// Closing the file stream to free all resources
fstream.Close();

مشكلة قفل الخلية

إذا كنت ترغب في تقييد المستخدمين من تحرير الخلايا يجب أن تكون الخلايا مقفلة قبل تطبيق أي إعدادات حماية. وإلا يمكن تحرير الخلايا حتى لو تم حماية ورقة العمل. في Microsoft Excel XP، يمكن قفل الخلايا من خلال المربع الحوار التالي:

مربع الحوار لقفل الخلايا في Excel XP
todo:image_alt_text

من الممكن قفل الخلايا باستخدام واجهة برمجة التطبيقات لـ Aspose.Cells أيضًا. يمكن أن تأخذ كل خلية تنسيقًا يحتوي على خاصية منطقية، Style. ضبط خاصية IsLocked على صحيح أو خطأ لقفل أو فتح الخلية.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Workbook workbook = new Workbook(dataDir + "Book1.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells["A1"].GetStyle().IsLocked = true;
// Finally, Protect the sheet now.
worksheet.Protect(ProtectionType.All);
workbook.Save(dataDir + "output.xlsx");