ワークシートがパスワードで保護されているかどうかを検出する
Contents
[
Hide
]
ワークブックとワークシートを別々に保護することができます。例えば、スプレッドシートには1つ以上のパスワードで保護されたワークシートが含まれている場合がありますが、スプレッドシート自体が保護されている場合といない場合があります。Aspose.Cells APIは、特定のワークシートがパスワードで保護されているかどうかを検出する手段を提供します。この記事では、Aspose.Cells for JavaAPIの使用方法を示しています。
ワークシートがパスワードで保護されているかどうかを検出する
Aspose.Cells for Java 8.7.0は、ワークシートがパスワードで保護されているかどうかを検出するためのProtection.isProtectedWithPasswordプロパティを公開しました。ブール型のProtection.isProtectedWithPasswordフィールドは、Worksheetがパスワードで保護されている場合はtrueを返し、そうでない場合はfalseを返します。
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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DetectWorksheetisPasswordProtected.class); | |
// Create an instance of Workbook and load a spreadsheet | |
Workbook book = new Workbook(dataDir + "sample.xlsx"); | |
// Access the protected Worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Check if Worksheet is password protected | |
if (sheet.getProtection().isProtectedWithPassword()) { | |
System.out.println("Worksheet is password protected"); | |
} |