You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow XLS and XLSX files without a file extension to be detected as Excel instead of Wikitext #2850
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.
@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);
@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);
@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.
@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.
Activity
tfmorris commentedon Jun 30, 2020
Apache Tika has content sniffing, although it's a relatively heavyweight dependency.
thadguidry commentedon Jun 30, 2020
@tfmorris probably the easiest is just use Apache POI with a
try catchorthrows IOExceptionagainst each of these to see if it indeed has a workbook. Then we know we can use the Excel importer.chetan-v commentedon Jul 2, 2020
I want to do that
chetan-v commentedon Jul 3, 2020
@thadguidry Now I am understanding the codebase for this issue.
please give some Idea for this topic
thadguidry commentedon Jul 3, 2020
@chetan-v Tom ( @tfmorris ) can give you guidance here.
tfmorris commentedon Jul 3, 2020
@thadguidry This looks to be a fairly complicated issue. I see a few different problems:
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.
thadguidry commentedon Jul 3, 2020
@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.
tfmorris commentedon Jul 3, 2020
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.
thadguidry commentedon Jul 3, 2020
@tfmorris yeap, understood. Feel free to reassign. I'll let you and @chetan-v figure out a way forward.
chetan-v commentedon Jul 4, 2020
Ok then i solve some other problem
Fix text guesser so it doesn't guess wikitext
Fix text guesser so it doesn't guess wikitext
Fix the text format guesser so it doesn't inappropriately guess WikiT…