Paramètres de protection avancés depuis Excel XP dans Aspose.Cells

Paramètres de protection avancés à l’aide d’Excel XP et des versions ultérieures

Pour afficher les paramètres de protection disponibles dans Excel XP :

  1. DuOutils menu, sélectionnezprotection suivie parFeuille de protection. Une boîte de dialogue s’affiche.

Boîte de dialogue pour afficher les options de protection dans Excel XP

tâche : image_autre_texte

  1. Autorisez ou restreignez les fonctionnalités des feuilles de calcul ou appliquez un mot de passe.

Paramètres de protection avancés à l’aide de Aspose.Cells

Aspose.Cells prend en charge tous les paramètres de protection avancés.

Aspose.Cells fournit une classe,Cahier , qui représente un fichier Excel Microsoft. LeCahier classe contient unFeuilles de travail collection qui permet d’accéder à chaque feuille de calcul dans le fichier Excel. Une feuille de calcul est représentée par leFeuille de travail classe.

LeFeuille de travail la classe fournit laprotectionpropriété utilisée pour appliquer ces paramètres de protection avancés. Leprotection la propriété est en fait un objet de laprotection classe qui encapsule plusieurs propriétés booléennes pour désactiver ou activer des restrictions.

Ci-dessous un petit exemple d’application. Il ouvre un fichier Excel et utilise la plupart des paramètres de protection avancés pris en charge par Excel XP et les versions ultérieures.

C#

 //Creating a file stream containing the Excel file to be opened

FileStream fstream = new FileStream("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("output.xls", SaveFormat.Excel97To2003);

//Closing the file stream to free all resources

fstream.Close();

Télécharger le code d’exécution

Télécharger l’exemple de code