Jannik-Schilling / generate_swmm_inp

a QGIS plugin for the import and export of SWMM input files (conversion of geodata, e.g. shapefiles or geopackage into SWMM models and vice versa)
GNU General Public License v2.0
35 stars 11 forks source link

Problem with generating Sheets list #38

Closed IanMahaffey60 closed 1 year ago

IanMahaffey60 commented 1 year ago

My QGIS was having an issue grabbing lists of the sheets in the function "read_data_from_table_direct".

I applied information from the following forums:

https://stackoverflow.com/questions/17977540/pandas-looking-up-the-list-of-sheets-in-an-excel-file https://stackoverflow.com/questions/64264563/attributeerror-elementtree-object-has-no-attribute-getiterator-when-trying

I added a line that said:

sheets = pd.read_excel(file,None,engine='openpyxl').keys()

and now the function looks like:

def read_data_from_table_direct(file, sheet=0):
    '''reads curves or other tables from excel or csv'''
    filename, file_extension = os.path.splitext(file)
    sheets = pd.read_excel(file,None,engine='openpyxl').keys()
    if file_extension == '.xlsx' or file_extension == '.xls' or file_extension == '.ods':
        if sheet == 0:
            data_df = pd.read_excel(file,sheet_name = sheet, engine='openpyxl')
        else:
            #print ('sheet not 0')
            if sheet in sheets:
                data_df = pd.read_excel(file,sheet_name = sheet, engine='openpyxl')
            elif str(sheet).upper() in sheets:
                data_df = pd.read_excel(file,sheet_name = str(sheet).upper(), engine='openpyxl')
            elif str(sheet).lower() in sheets:
                data_df = pd.read_excel(file,sheet_name = str(sheet).lower(), engine='openpyxl')
            elif str(sheet).capitalize() in sheets:
                data_df = pd.read_excel(file,sheet_name = str(sheet).capitalize(), engine='openpyxl')
            else:
                data_df = pd.DataFrame()
    if file_extension == '.csv':
        data_df = pd.read_csv(file)
    return data_df
Jannik-Schilling commented 1 year ago

hey @IanMahaffey60 , Thank you for reporting this issue. Which version of QGIS, python and pandas are you using? I'll try your suggestion in the next plugin version to fix this issue

IanMahaffey60 commented 1 year ago

QGIS Version 3.26.0 Python Version 3.9 Pandas Version 1.1.3 (All the standard packages from the latest QGIS update)

Thank you!

Jannik-Schilling commented 1 year ago

70420f6e6ff2c749c98c1410aab8787b342a1132