VBAプロジェクトが保護されているかどうかを調べる
Contents
[
Hide
]
可能な使用シナリオ
Aspose.Cellsを使用してExcelファイルのVBA(Visual Basic Applications)プロジェクトが保護されているかどうかを確認できます。VbaProject.isProtected() メソッドを使用します。
サンプルコード
次のサンプルコードは、ワークブックを作成し、そのVBAプロジェクトが保護されているかどうかを確認し、VBAプロジェクトを保護し、再度そのVBAプロジェクトが保護されているかどうかを確認します。参考のためにコンソール出力をご覧ください。保護前にはVbaProject.isProtected() はfalseを返しますが、保護後はtrueを返します。
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-Java | |
// Create a workbook. | |
Workbook wb = new Workbook(); | |
// Access the VBA project of the workbook. | |
VbaProject vbaProj = wb.getVbaProject(); | |
// Find out if VBA Project is Protected using IsProtected property. | |
System.out.println("IsProtected - Before Protecting VBA Project: " + vbaProj.isProtected()); | |
// Protect the VBA project. | |
vbaProj.protect(true, "11"); | |
// Find out if VBA Project is Protected using IsProtected property. | |
System.out.println("IsProtected - After Protecting VBA Project: " + vbaProj.isProtected()); |
コンソール出力
上記サンプルコードのコンソール出力の参考情報です。
IsProtected - Before Protecting VBA Project: false
IsProtected - After Protecting VBA Project: true