Please, need help with reading CSV from Excel. Please help.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

When the user of my app selects some rows from an open excel file and
drag-n-drops them onto my form, I need to be able to parse those lines and
create a datatable that would match the original selected Excel rows.

Is there any way the I can create a DataTable from CSV that is just droppped
onto the form?

I tried parsing each line myself, using some regular expressions I found
online, but they would fail if a cell in the Excel row contained quotes or
commas.

Any help is GREATLY appreciated!

Thanks
-Flack
 
I am pretty sure if you copy and paste cells from Excel, they are TAB
delimited with no field qualifiers, not comma delimited.

In either case you can parse them using Split for each line.

public class Parser
{
private const string delimiter = "\t";
private ArrayList data;

public Parser(string[] lines)
{
data = new ArrayList();
foreach(string line in lines)
{
data.Add(line.Split(delimiter));
}
}

public ArrayList DataForDataTable
{
get { return data; }
}
}

Hope that helps.

Patrick Altman
<><
 
Back
Top