Before going on vacation, I wanted to share a handy little piece of code to convert an Excel sheet to a .csv file.
static void ConvertXlsToCsv(string sheetTitle, string inputFile, string outputFile) { try { string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + inputFile + ";Extended Properties=\"Excel 12.0;HDR=No;IMEX=1\";"; var output = new DataSet(); using (var conn = new OleDbConnection(strConn)) { conn.Open(); var schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, sheetTitle + "$", "TABLE" }); var cmd = new OleDbCommand("SELECT * FROM [" + sheetTitle + "$]", conn); cmd.CommandType = CommandType.Text; OleDbDataAdapter adapter = new OleDbDataAdapter(cmd); adapter.Fill(output, sheetTitle + "$"); var dt = new DataTable(); adapter.Fill(dt); using (var sw = new StreamWriter(outputFile)) { for (int y = 0; y < dt.Rows.Count; y++) { var strRow = ""; for (int x = 0; x < dt.Columns.Count; x++) { strRow += "\"" + dt.Rows[y][x].ToString() + "\","; } sw.WriteLine(strRow); } } } } catch (Exception exc) { // Exception handling logic } }