'how can i make this script suitable for converting excel files with more than one sheet inside?

import pandas as pd
from xlsx2csv import Xlsx2csv
from io import StringIO
def read_excel(path: str, sheet_name: str) -> pd.DataFrame:
    buffer = StringIO() #to read and 
    Xlsx2csv(path, outputencoding="utf-8", sheet_name=sheet_name).convert(buffer)
    buffer.seek(0)
    df = pd.read_csv(buffer)
    return df

how can i make this script suitable for converting excel files with more than one sheet inside? It works only for xlsx file with one sheet at the moment...



Solution 1:[1]

Do you really need to use xlsx2csv module? If not, you could try this with Pandas.

import pandas as pd
for sheet in ['Sheet1', 'Sheet2']:
    df = pd.read_excel('sample.xlsx', sheetname=sheet)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manjunath K Mayya