Aspose.Cells の Excel XP 以降の高度な保護設定

Excel XP 以降のバージョンを使用した高度な保護設定

Excel XP で使用可能な保護設定を表示するには:

  1. からツールメニュー、選択保護に続くプロテクトシート. ダイアログが表示されます。

    Excel XP の保護オプションを表示するダイアログ

todo:画像_代替_文章

  1. ワークシート機能を許可または制限するか、パスワードを適用します。

Aspose.Cells を使用した高度な保護設定

Aspose.Cells は、すべての高度な保護設定をサポートしています。

Aspose.Cells はクラスを提供し、ワークブック、Microsoft Excel ファイルを表します。のワークブッククラスにはワークシートExcel ファイル内の各ワークシートにアクセスできるコレクション。ワークシートは、ワークシートクラス。

ワークシートクラスが提供する保護これらの高度な保護設定を適用するために使用されるプロパティ。の保護プロパティは実際にはのオブジェクトです保護制限を無効または有効にするためのいくつかのブール型プロパティをカプセル化するクラス。

以下は小さなアプリケーション例です。 Excel ファイルを開き、Excel XP 以降のバージョンでサポートされている高度な保護設定のほとんどを使用します。

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

実行中のコードをダウンロード

サンプルコードをダウンロード