For part of a web application the user needs to import some data from a spreadsheet. Such as a list of names and email addresses. Currently we do this by asking the user to browse for and upload a CSV file.
Unfortunately, this isn’t always possible as various corporate IT systems only allow users to access files from document management systems and they have no privileges to save these to a local drive or network share.
The solution we have is to allow the user to cut and paste the entire sheet (CSV) into a text area and submit that. On doing this you get a nice tab delimited list of the data that is easily parsed as below.
Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus fermentum Vivamus et diam eu eros egestas rutrum Morbi id neque id enim molestie tincidunt Nullam
Unfortunately, various cells could produce unexpected results. In the set below you can see a ‘ within the word prerium, a tab with the word Suspendisse and a line break within the word sollicitudin.
bibendum ante molestie lectus Sed pret'ium 'Susp endisse' 'sollic itudin' nisi at urna Sed sit amet odio eu neque egestas tincidunt Nunc metus Curabitur at nibh Nulla
In this case I cannot just split on tabs and line breaks without a more enhance mechanism to deal with the tabs, quotes and line breaks within the actual data.
Does anyone know of any code that can handle this reliably? Or even if excel and the clipboard like this can be relied upon to produce consistant results?
I am working in Asp.net 3.5 using C#. The users excel version may vary but should always be Windows 2000/XP/Vista and IE 6/7.
This looks like a ‘delimited values’ list to me, so basically the same as CSV with TAB as the field delimiter and line break as the row delimiter. You could try it with the CSV Reader library from CodeProject, it should be handle to handle different delimiters, not just comma.