Uploading Excel with multiple sheets as user input

Hi, I am working on an app where I need user to upload few files (.png, .txt, and .xlsx). Excel file will be having multiple sheets. I will read these sheets as different dataframes . How can I achieve the upload part and then reading sheets individually as dataframe?

Hi Abhi,

Thank you for your question. Here to answer your different questions:

  1. How can I achieve the upload part? This can be achieved by means of using a FileField. More on this can be found here: User input, fields and buttons - Upload files | VIKTOR Documentation
  2. How can I read sheet individually as dataframe? There are different ways of achieving this with different python packages. Here is a link with a solution: python - Using Pandas to pd.read_excel() for multiple worksheets of the same workbook - Stack Overflow

Here is also a small snippet that goes through these steps:

import pandas as pd

def excel_to_dataframe(params) -> pd.DataFrame:
    if params.upload_file:
        excel_file: File = params.upload_file.file
    
    excel_data = pd.ExcelFile(BytesIO(excel_file.getvalue_binary())
    df = pd.read_excel(excel_data, 'Sheet1')
    return df

The conversion from a File object to an ExcelFile was partially solved by using this link as reference:

I hope this helps.