Reading streamed data from Excel or CSV

Recently I stumbled over the task to read either CSV or Excel files and transfer data in an independent format to a server.

The existing software part implemented to similar approaches to

1. Read the file

2. Transfer the file into an intermediate format (a DataTable)

3. Transfer the file up to the server

The server took the file, read all data, translate number according to a given number format sent by the client, …

Reviewing the code resulted into a couple of drawbacks: redundant code, performance, use of language depending information on the server side, etc.

As a result I looked for an approach to

1. combine CSV and excel load within one flow and

2. have data translated on the client side into a format which can be read by the server without knowledge of the client user language (or the date format used for loading files)

Based on a code example for IDataReader (http://blogs.msdn.com/b/anthonybloesch/archive/2013/01/23/bulk-loading-data-with-idatareader-and-sqlbulkcopy.aspx) I had the idea to create a library which streams data independent of the input format.
Continue reading “Reading streamed data from Excel or CSV”

I18n: Parsing Decimal values

At Tideum and for TimeJack we are developing line of business applications which usually handle numbers. As we are developing our software for international markets we usually face the problem of users entering numbers in a format that is not the same as the current locale (e.g. Germans are entering numbers in English locale and vice versa). This happens very often if data is copied from 3rd party applications (e.g. SAP or Excel).

Parsing those numbers with the standard .NET functions (aka. Decimal.Parse()) is parsing only a fixed language, e.g.

string source = "123,45";
decimal value = Decimal.Parse(source);

depends on the current thread culture settings. In case the current settings are “de-DE” (or “de-AT”), the conversion will return value == 123.45, for “en-US” value == 12345 will be returned and for “de-CH”/”fr-CH” a System.FormatException is thrown.
Continue reading “I18n: Parsing Decimal values”