Skip to content

Allow XLS and XLSX files without a file extension to be detected as Excel instead of Wikitext #2850

Closed

Description

@thadguidry

Is your feature request related to a problem or area of OpenRefine? Please describe.
Currently, if a XLSX file has no file extension because of someone's preference or OS setup for saving files, then when importing the XLSX file, OpenRefine will not detect it as an Excel file but instead will choose Wikitext importer as the first option.

Describe the solution you'd like
XLS and XLSX files should be detected as Excel for the importer regardless of their file extension.

Describe alternatives you've considered
Ensuring that files when saved include the .xls or .xlsx extension as well as renaming lots of XLSX files to include the file extension on their filename.

Additional context
Windows is an OS that heavily depends on file extensions to navigate and perform actions based on them. However, when a filename has no file extension, OpenRefine should go through its sets of algorithms to detect the most appropriate importer based on the content of the file.

Unfortunately, there is not file signature (magic bytes) for .xls and .xlsx files. Although .xlsx files do start with the same magic bytes as .zip files https://en.wikipedia.org/wiki/List_of_file_signatures
So other detection mechanisms will have to be used such as Apache POI.

Test file
Extract file and then try to open Colorado-Municipalities-XLSX as well as rename it to just ColoradoMunicipalities and notice that OpenRefine will detect as Wikitext and not Excel.

Colorado-Municipalities-XLSX.zip

Activity

  1. added
    Type: Feature RequestIdentifies requests for new features or enhancements. These involve proposing new improvements.
    importAbout importers in general - add a label for the data format if available
    on Jun 30, 2020
  2. tfmorris commented on Jun 30, 2020

    @tfmorris
    Member

    Apache Tika has content sniffing, although it's a relatively heavyweight dependency.

  3. thadguidry commented on Jun 30, 2020

    @thadguidry
    MemberAuthor

    @tfmorris probably the easiest is just use Apache POI with a try catch or throws IOException against each of these to see if it indeed has a workbook. Then we know we can use the Excel importer.

    //xlsx  https://poi.apache.org/apidocs/4.1/org/apache/poi/xssf/usermodel/XSSFWorkbook.html
            workbook = new XSSFWorkbook(inputStream);
    
    // xls  https://poi.apache.org/apidocs/4.1/org/apache/poi/hssf/usermodel/HSSFWorkbook.html
            workbook = new HSSFWorkbook(inputStream);
    
  4. chetan-v commented on Jul 2, 2020

    @chetan-v
    Contributor

    I want to do that

  5. chetan-v commented on Jul 3, 2020

    @chetan-v
    Contributor

    @thadguidry Now I am understanding the codebase for this issue.

    @tfmorris probably the easiest is just use Apache POI with a try catch or throws IOException against each of these to see if it indeed has a workbook. Then we know we can use the Excel importer.

    //xlsx  https://poi.apache.org/apidocs/4.1/org/apache/poi/xssf/usermodel/XSSFWorkbook.html
            workbook = new XSSFWorkbook(inputStream);
    
    // xls  https://poi.apache.org/apidocs/4.1/org/apache/poi/hssf/usermodel/HSSFWorkbook.html
            workbook = new HSSFWorkbook(inputStream);
    

    please give some Idea for this topic

  6. thadguidry commented on Jul 3, 2020

    @thadguidry
    MemberAuthor

    @chetan-v Tom ( @tfmorris ) can give you guidance here.

  7. tfmorris commented on Jul 3, 2020

    @tfmorris
    Member

    @thadguidry This looks to be a fairly complicated issue. I see a few different problems:

    • the wikitable format guesser is much too permissive (who the heck keeps their data in a wiki table anyway?), including:
      • it doesn't require the markers to be at the beginning of the line (modulo whitespace) as required by the spec
      • it doesn't check for matching numbers of begin/end table markers
    • there's nothing in the importer framework that keeps it from attempting to parse binary data (e.g. a zip file as in this case) as text

    When those things are fixed, we can see if we still need more. I don't think we want to be blindly trying to open files using heavyweight parsers. In the case of XLS and XLSX we would want to, at a minimum, make sure they were of the correct container format.

  8. thadguidry commented on Jul 3, 2020

    @thadguidry
    MemberAuthor

    @tfmorris Sure, it's not a huge priority (medium) but would be really nice if we can do the XLS and XLSX detection without relying on the file extension. Whatever you think can help with that even if you think creating our own container detector for those 2 formats specifically. I trust you to make the right decision here.

  9. added
    Priority: MediumRepresents important issues that need to be addressed but are not urgent
    on Jul 3, 2020
  10. tfmorris commented on Jul 3, 2020

    @tfmorris
    Member

    I'm not saying it shouldn't be fixed, just that I think it's too complex for someone who's new to the project to tackle.

  11. thadguidry commented on Jul 3, 2020

    @thadguidry
    MemberAuthor

    @tfmorris yeap, understood. Feel free to reassign. I'll let you and @chetan-v figure out a way forward.

  12. chetan-v commented on Jul 4, 2020

    @chetan-v
    Contributor

    Ok then i solve some other problem

  13. added a commit that references this issue on Jul 4, 2020
    384b53c
  14. added a commit that references this issue on Jul 12, 2020
    d32d627
  15. added a commit that references this issue on Jul 15, 2020
    a3fab26
  16. added this to the 3.5 milestone on Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: MediumRepresents important issues that need to be addressed but are not urgentType: Feature RequestIdentifies requests for new features or enhancements. These involve proposing new improvements.importAbout importers in general - add a label for the data format if available

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions