I have the following code that imports excel documents and parses them so I can manipulate the data before it is saved to the database.
I can parse .xlsx and .xls files just fine but cannot figure out how to use my existing code for .csv files
the customer I am working for wants to use .csv file type to accept special characters.
OpenFileDialog opener = new OpenFileDialog();
opener.Filter = "Excel Files| *.xlsx;*.xls;*.csv;";
if (opener.ShowDialog() == DialogResult.Cancel)
return;
FileStream streamer = new FileStream(opener.FileName, FileMode.Open);
IExcelDataReader reader;
if (Path.GetExtension(opener.FileName) == ".xls")
{
reader = ExcelReaderFactory.CreateBinaryReader(streamer);
}
else if (Path.GetExtension(opener.FileName) == ".csv")
{
*** Need Something Here to read CSV Files that will work with
the rest of code***
}
else
{
reader = ExcelReaderFactory.CreateOpenXmlReader(streamer);
}
DataSet results = reader.AsDataSet();
results.Tables[0].Rows[0].Delete();
results.AcceptChanges();
foreach (System.Data.DataTable table in results.Tables)
{
foreach (DataRow dr in table.Rows)
{
>>> Do Something With the Data
}
}