Skip to content

fix issue 578.#644

Merged
appel1 merged 4 commits into
ExcelDataReader:developfrom
Andreybonfi:fix-578-issue
Apr 15, 2024
Merged

fix issue 578.#644
appel1 merged 4 commits into
ExcelDataReader:developfrom
Andreybonfi:fix-578-issue

Conversation

@Andreybonfi

@Andreybonfi Andreybonfi commented Jul 22, 2023

Copy link
Copy Markdown
Contributor

Based on issue 578
Add Inplementation of GetValues(object[] values)

  • Return real count of readed Cells
  • Always return reading row from excel

It seems to me the best solution is to always return data to the user even if he asks for more than what exists in the Excel Row.

It seems to me the best solution is to always return data to the user even if he asks for more than what exists in the Excel Row.
@Andreybonfi

Andreybonfi commented Jul 22, 2023

Copy link
Copy Markdown
Contributor Author

However, the solution that I implemented, when using this library, seems to me to make the library easy to use. using While, it seems to me not the best solution. I suggest the following approach

This is how I use the library:

using (ExcelReader excel = new ExcelReader(FileInfo.Path))
     {
            foreach (var Row in excel)
                {
                 <...>
                 }
      }

For use, I just implemented the following code

public IEnumerator<ExcelRow> GetEnumerator()
        {
            while (Read())
            {
                var CurrentRow = ReadRow();
                yield return CurrentRow;
            }
        }
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }


        public object[] ReadRow(int width = 100)
        {
            int max = FieldCount > width ? width : FieldCount;

            var row = new object[max];

            for (int i = 0; i < max; i++)
            {
                row[i] = RowCells[i]?.Value;
            }

            return row;
        }

I think width must become part of the constructor (Excel reader). That the user can define the maximum readable width of their files. In general, if there is an empty string, create an array of 16.000 items, bad idea.

If you think this is a good idea, I could implement it.

@appel1

appel1 commented Jul 22, 2023

Copy link
Copy Markdown
Collaborator

Thanks.

The implementation should follow the contract as specified which I think you've already done. I'll take closer look after the holidays.

I don't think the ReadRow helper adds enough value to add to the core library.

@appel1

appel1 commented Aug 8, 2023

Copy link
Copy Markdown
Collaborator

Could you add tests for the other supported file formats as well?

@Andreybonfi

Copy link
Copy Markdown
Contributor Author

Yes, I can do it after my vacation. But I'm not sure that is useful, because I just add using of RowCells[I].Value.

@Andreybonfi

Copy link
Copy Markdown
Contributor Author

Good afternoon, I'm not sure if you saw the changes. But I have added tests for supported files.

@appel1 appel1 merged commit 98ce91c into ExcelDataReader:develop Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants