Detect if an Excel Document is Password Protected in Java

This article demonstrates how to detect whether an Excel document is password protected or not using Spire.XLS for Java.

import com.spire.xls.Workbook;

public class DetectProtectedOrNot {
    public static void main(String[] args) {

        //Get the file path
        String filePath= "C:\\Users\\Administrator\\Desktop\\sample.xlsx";

        //Detect whether the workbook is password protected or not
        Boolean isProtected = Workbook.bookIsPasswordProtected(filePath);

        //Print results
        if (isProtected) {
            System.out.print("The document is password protected.");
        }
        else {
            System.out.print("The document is not protected.");
        }
    }
}

Detect if an Excel Document is Password Protected in Java