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

Optional parameter to force column Data Type #457

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

johha86
Copy link

@johha86 johha86 commented Jan 7, 2020

To the extension class "ExcelDataReaderExtensions" was added a new optional parameter. This new parameter allow specify the value type associated to a column.

The structure of this parameter is a list of ExcelDataType.

The definition of an ExcelDataType is:

public class ExcelDataType
{
public string ColumnName { get; set; }
public Type ColumnType { get; set; }
}

@andersnm
Copy link
Collaborator

andersnm commented Jan 7, 2020

Hi and thank you! Unfortunately I believe this is a problematic change. In particular because of Mono, which apparently has slight differences in its DataSet implementation from the "official" ones. See #409 / #73 / #30.

Currently by default ExcelDataReader tries to autodetect the type for DataColumn.DataType and the linked issues are reporting problems when there are nulls in the data. I think we should fix the autodetector so that it always works (i.e: assign nullable types in case of nulls, also configure pr sheet), rather than providing a type override mechanism which can easily break (on mono)

If you can tell a bit more about your scenario, maybe we can come up with a better solution?

@johha86
Copy link
Author

johha86 commented Jan 7, 2020

Hi, this is my scenary.

When I read and Excel document that contains an value of type Decimal, it always is save in the DataTable returned by the extensor method as a Double. But in this case I want it as a Decimal cause I'll save the DataTable into the database as Decimal.

This is just a specific scenario. But a very common situation is that someone want to read the value from the Excel with an specific data type. Otherwise he/she must retrieve the information from the original DataTable, perform a casting or type conversion and then create a new DataTable to be stored into the Database. This is memory consuming solution obviously.

@andersnm
Copy link
Collaborator

andersnm commented Jan 7, 2020

Some kind of new ExcelDataTableConfiguration.TransformValue(reader, columnIndex) callback could be a flexible way to handle this and other scenarios. F.ex I had a use case where I wanted to apply formatting on every value in the DataSet, which is similar to yours, but converting to DB types instead. Happy to accept a PR for this.

Alternatively, if you need a quick resolve you might find it easier to build the dataset manually yourself, f.ex by copying the AsDataSet method into your project and adapt+simplify as necessary. AsDataSet() is theoretically quite simple, but comes with lots of bells and whistles.

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.

None yet

2 participants