Impostazioni di protezione avanzata da Excel XP in Aspose.Cells

Impostazioni di protezione avanzata tramite Excel XP e versioni successive

Per visualizzare le impostazioni di protezione disponibili in Excel XP:

  1. DalUtensili menù, selezionareProtezione seguito daProteggi Foglio. Viene visualizzata una finestra di dialogo.

Finestra di dialogo per mostrare le opzioni di protezione in Excel XP

cose da fare:immagine_alt_testo

  1. Consenti o limita le funzionalità dei fogli di lavoro o applica una password.

Impostazioni di protezione avanzata utilizzando Aspose.Cells

Aspose.Cells supporta tutte le impostazioni di protezione avanzate.

Aspose.Cells offre un corso,Cartella di lavoro , che rappresenta un file Excel Microsoft. IlCartella di lavoro la classe contiene unFogli di lavoro raccolta che consente l’accesso a ciascun foglio di lavoro nel file Excel. Un foglio di lavoro è rappresentato daFoglio di lavoro classe.

IlFoglio di lavoro la classe fornisce ilProtezioneproprietà utilizzata per applicare queste impostazioni di protezione avanzate. IlProtezione la proprietà è infatti un oggetto delProtezione classe che incapsula diverse proprietà booleane per disabilitare o abilitare le restrizioni.

Di seguito è riportato un piccolo esempio di applicazione. Apre un file Excel e utilizza la maggior parte delle impostazioni di protezione avanzate supportate da Excel XP e versioni successive.

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();

Scarica il codice in esecuzione

Scarica il codice di esempio