I have a requirement where in I need to remove dependency of MS Office to read and work on CSV files since the client does not want to have MS Office installed on the server. I was trying EPPlus but it seems it does not work correctly with .CSV files.
Asked
Active
Viewed 1,312 times
-1
-
1There are literally hundreds of CSV parsers/readers available for C#, a quick google for "C# CSV parser" turns up several libraries and a few SO questions on the same topic. – Karl-Johan Sjögren Nov 02 '15 at 06:09
-
1Since when do programs require that **Office be installed** in order to parse **CSV**? – Nov 02 '15 at 06:23
-
A CSV is just a text file. What are you doing to the file that makes you think you need office installed? – Nick.Mc Nov 02 '15 at 06:28
-
ApplicationClass m_App = new Excel.ApplicationClass(); m_Book = m_App.Workbooks.Open(m_strExcelBook, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing); m_Book = m_App.Workbooks.Open(m_strExcelBook, m_Missing, true, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing, m_Missing); m_SwapDataSheet = (Excel._Worksheet)m_Book.Worksheets[REPORTINDEX]; – jen123 Nov 02 '15 at 06:31
-
ApplicationClass m_App = new Excel.ApplicationClass(); This is where I am getting error ; I am unsure how to change it to work without MS office – jen123 Nov 02 '15 at 06:33
1 Answers
0
Very easy solution that I used too:
Download DLL and more detailed information From here
using (CsvReader csv = new CsvReader(new StreamReader("data.csv"), true))
{
int fieldCount = csv.FieldCount;
string[] headers = csv.GetFieldHeaders();
while (csv.ReadNextRecord())
{
for (int i = 0; i < fieldCount; i++)
Console.Write(string.Format("{0} = {1};",
headers[i], csv[i]));
Console.WriteLine();
}
}

Waqar Ahmed
- 1,414
- 2
- 15
- 35