Skip to content

Named range being parsed with erroneous single quotes #189

@crabbixOCE

Description

@crabbixOCE

When I try to read in a named range the way it is done in the tutorial documentation:

input_file = XLSX.readxlsx("filepath")
named_range = input_file["NAMED_RANGE`]

I get AssertionError: Sheet 'SHEET NAME' not found. SHEET NAME, without the single quotes, is a perfectly valid reference. I tried changing the reference in Excel name manager itself from 'SHEET NAME'!A1:A5 to SHEET NAME!A1:A5, but the error persisted.

I then modified the function getdata in workbook.jl to the following, and it now correctly imports the named range:

function getdata(xl::XLSXFile, s::AbstractString)
    
    if is_valid_sheet_cellname(s)
        return getdata(xl, SheetCellRef(s))
    elseif is_valid_sheet_cellrange(s)
        return getdata(xl, SheetCellRange(s))
    elseif is_valid_sheet_column_range(s)
        return getdata(xl, SheetColumnRange(s))
    elseif is_workbook_defined_name(xl, s)
        
        v = get_defined_name_value(xl.workbook, s)
        if is_defined_name_value_a_constant(v)
            return v
        elseif is_defined_name_value_a_reference(v)
            if typeof(v)==SheetCellRef
                v2 = SheetCellRef(replace(v.sheet,"'"=>""),v.cellref)
            else
                v2 = SheetCellRange(replace(v.sheet,"'"=>""),v.rng)
            end
            try
                return getdata(xl, v)
            catch
                println("Removing single quotes and retrying")
            finally
                return getdata(xl, v2)
            end
        else
            error("Unexpected defined name value: $v.")
        end
    end

    error("$s is not a valid sheetname or cell/range reference.")
end

Not sure if this is the most efficient fix, but thought it should be brought to someone's attention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions