Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Cell class #18

Open
Sibz opened this issue Jun 20, 2017 · 0 comments
Open

Issue with Cell class #18

Sibz opened this issue Jun 20, 2017 · 0 comments

Comments

@Sibz
Copy link
Contributor

Sibz commented Jun 20, 2017

I have a slight issue in how the Cell class works.

It seems there's two ways to add cells to a row. 1) Worksheet.AddValue 2) Add via IEnumerable<Cell> cells (after casting to a list) property on Row.

First one is slow as noted, but a handy shortcut.
Second one is error prone as no checks are made. So you could make two identical cells and add them to the row. i.e.

row.Cells.Add(new Cell(1, 0));
row.Cells.Add(new Cell(1, 0));

Also if Cells were added in incorrect order there is no sorting to put it right.

Although this would be a breaking change, I think a better approach would be to make Cells a IReadOnlyDictionary<int, Cell> instead. (The current IEnumerable is read only but casting to a list make it not read only, which is how the internal code updates).
For updating cells,
Row.SetCellValue(int/string column, object value)
Row.SetCellValue(Cell cell)
This could set existing cell value, add cell if it doesn't exist, or remove existing if value is null.
As a dictionary (underlying dictionary being SortedDictionary), it is ordered by index and prevents duplicates.

Of course, this would also apply to the Row class and Rows IEnumerable on worksheet too.

As it's a breaking change it may not be worth doing, however as the version is going to version 2, this indicates there is breaking changes, so this might be a good time to change this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants