Configuración de protección avanzada desde Excel XP en Aspose.Cells

Configuración de protección avanzada con Excel XP y versiones posteriores

Para ver la configuración de protección disponible en Excel XP:

  1. Desde elHerramientas menú, seleccioneProteccion seguido porhoja de protección. Se muestra un cuadro de diálogo.

Diálogo para mostrar opciones de protección en Excel XP

todo:imagen_alternativa_texto

  1. Permita o restrinja las funciones de las hojas de trabajo o aplique una contraseña.

Configuración de protección avanzada usando Aspose.Cells

Aspose.Cells admite todas las configuraciones de protección avanzada.

Aspose.Cells proporciona una clase,Libro de trabajo , que representa un archivo de Excel Microsoft. ÉlLibro de trabajo la clase contiene unHojas de trabajo colección que permite el acceso a cada hoja de trabajo en el archivo de Excel. Una hoja de trabajo está representada por elHoja de cálculo clase.

ÉlHoja de cálculo la clase proporciona laProteccionpropiedad que se utiliza para aplicar esta configuración de protección avanzada. ÉlProteccion la propiedad es de hecho un objeto de laProteccion clase que encapsula varias propiedades booleanas para deshabilitar o habilitar restricciones.

A continuación se muestra una pequeña aplicación de ejemplo. Abre un archivo de Excel y utiliza la mayoría de las configuraciones de protección avanzadas compatibles con Excel XP y versiones posteriores.

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

Descargar código de ejecución

Descargar código de muestra