doccano / doccano/doccano

Excel Import Bug

Open
#2,284 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
10.8k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

How to reproduce the behaviour
---------
1. Easily create a Seq2seq project
2. Select Excel format to import

Personal analysis
---------
At this time, there is no way to import Excel. After checking the code, I found that it was a code bug.
Code bug location and class:
` /doccano/backend/data_import/pipeline/parsers.py:ExcelParser`

The cause of the bug: Doccano's uploaded file will modify the file name, resulting in the loss of the Excel suffix. However, the internal parsing of Excel files uses pyexcel,The library seems to have no way to identify files with inconsistent suffixes, causing Excel to fail to upload.

Temporary modification plan
---------
```
class ExcelParser(Parser):
"""ExcelParser is a parser to read a excel file."""

def __init__(self, **kwargs):
self._errors = []

def parse(self, filename: str) -> Iterator[Dict[Any, Any]]:
fn = filename + ".xlsx"
try:
os.rename(filename, fn)
rows = pyexcel.iget_records(file_name=filename)
for line_num, row in enumerate(rows, start=1):
yield {LINE_NUMBER_COLUMN: line_num, **row}
except pyexcel.exceptions.FileTypeNotSupported as e:
error = FileParseException(filename, line_num=1, message=str(e))
self._errors.append(error)
finally:
os.rename(fn, filename)

@property
def errors(self) -> List[FileParseException]:
return self._errors

```

To reproduce the file
---------

[example.xlsx](https://github.com/doccano/doccano/files/12698523/example.xlsx)

Your Environment
---------
I started based on the introduction of docker compose on github's readme.
Therefore, no changes were made to the entire startup environment.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.