count the number of excel Sheets

Certified Senior Developer

In the interface user has privilege to upload the excel document, we are using the function readexcelsheetpaging to get the information from the 4th sheet of the uploaded excel. when the user uploads the excel with sheets < 4 expression error is shown. Is there a way to check the number of sheets in the excel uploaded  before passing it to readexcelsheetpaging function?

  Discussion posts and replies are publicly visible

  • +1
    Certified Lead Developer

    AFAIK, No plugins or built-in functions exist to check sheet count/metadata before reading, making pre-validation impossible.
    Use defensive UI design, Warn users clearly and get confirmation before attempting to read sheet 4. This way, if error occurs, user understands why.

    readexcelsheetpaging() throws a Java exception when accessing non-existent sheets, which cannot be caught in interfaces without try() function.
    However, Appian does not officially support this function as it's hidden. It is recommended to check with your organization or Appian Support before using it in Production.

  • 0
    Certified Lead Developer

    Generally for scenarios like these I prefer to add validation in the excel template itself so that users cannot save the file unless they have filled data as per requirement. Its generally is easy as well with or without macros. 
    Assuming you are providing the users with a template to work with easiest will be to Protect the worksheet so that users cannot delete the sheet. Excel functions like SHEET() etc can help in saving and fetching sheet count from excel workbook as well.

    More details will enable me to help you better. Meanwhile explore excel validations instead of Appian ones for your usecase.

  • 0
    Certified Senior Developer

    To check the number of sheets in the excel uploaded you can use this plugin
    document-page-counter