Hi,
use this modified code working fine.
string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0}; Extended Properties=""Excel 12.0;HDR=No;IMEX=1""", fpath);
OleDbConnection conn = null;
StreamWriter wrtr = null;
OleDbCommand cmd = null;
OleDbDataAdapter da = null;
conn = new OleDbConnection(connectionString);
conn.Open();
cmd = new OleDbCommand("SELECT * FROM [test$]", conn);
cmd.CommandType = CommandType.Text;
wrtr = new StreamWriter("D:\\test.csv");
da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
string rowString = ""; ;
for (int x = 0; x < dt.Rows.Count; x++)
{
rowString = "";
for (int y = 0; y < dt.Columns.Count; y++)
{
rowString += "\"" + dt.Rows[x][y].ToString() + "\",";
}
wrtr.Write(rowString);
}
string str = rowString;
wrtr.Dispose();
conn.Close();
MessageBox.Show("file is saved");