تحقق من كلمة المرور للتعديل باستخدام Aspose.Cells
Contents
[
Hide
]
في بعض الأحيان ، تحتاج إلى التحقق مما إذا كانت كلمة المرور المقدمة تتطابق معكلمة مرور للتعديل برمجيا. يوفر Aspose.Cells طريقة WorkbookSettings.WriteProtection.ValidatePassword () التي يمكنك استخدامها للتحقق مما إذا كانت كلمة المرور المعينة للتعديل صحيحة أم لا.
تحقق من كلمة المرور للتعديل في Microsoft Excel
يمكنك التنازلكلمة السر لفتح وكلمة مرور للتعديل أثناء إنشاء المصنفات الخاصة بك في Microsoft Excel. يرجى الاطلاع على لقطة الشاشة هذه التي توضح الواجهة Microsoft التي يوفرها Excel لتحديد كلمات المرور هذه.
![]() |
---|
تحقق من كلمة المرور للتعديل باستخدام Aspose.Cells
تقوم الرموز النموذجية التالية بتحميل ملفمصدر Excel ملف. يحتوي على كلمة مرور لفتحها كـ 1234 وكلمة مرور لتعديلها كـ 5678. يتحقق الكود أولاً مما إذا كانت 567 هي كلمة مرور صحيحة لتعديلها ويعيد خطأ ، ثم يتحقق مما إذا كانت 5678 هي كلمة مرور لتعديلها وإرجاعها صحيحة.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Specify password to open inside the load options | |
LoadOptions opts = new LoadOptions(); | |
opts.Password = "1234"; | |
// Open the source Excel file with load options | |
Workbook workbook = new Workbook(dataDir + "sampleBook.xlsx", opts); | |
// Check if 567 is Password to modify | |
bool ret = workbook.Settings.WriteProtection.ValidatePassword("567"); | |
Console.WriteLine("Is 567 correct Password to modify: " + ret); | |
// Check if 5679 is Password to modify | |
ret = workbook.Settings.WriteProtection.ValidatePassword("5678"); | |
Console.WriteLine("Is 5678 correct Password to modify: " + ret); |
إخراج وحدة التحكم
إليك إخراج وحدة التحكم لعينة التعليمات البرمجية أعلاه بعد تحميل ملفمصدر Excel ملف.
Is 567 correct Password to modify: False
Is 5678 correct Password to modify: True