Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

Please tell me how to convert the following text to excel using c# these are two rows and in excel we have to put some headers

"OBREPORT","23.08.2013","02.06.58","PBS","8182301","80000001","4802195",""
"OBREPORT","23.08.2013","02.06.58","PBS","8182301","80000001","4802195",""

Thanks in advance.
Posted

 
Share this answer
 
Comments
Sivarjun Chikkala 10-Sep-13 10:07am    
Thank you for reply sir.
C#
static void Main(string[] args)
{

string line;
  using (StreamReader reader = new StreamReader(@"yourFilePath.txt"))
   {
       while ((line = reader.ReadLine()) != null)
     {
      using (StreamWriter writer = new StreamWriter(@"yourFilePath.csv", true))
                  {
                      writer.WriteLine(line.Replace(",",";"));
                  }
      }
   }

}


And if you want to write some headers just write a line before all this and for every new column you add a ";"
 
Share this answer
 
v2
Comments
Sivarjun Chikkala 10-Sep-13 10:03am    
Thanks for respond. But I need excl file conversion.Please improve your answer.
David Goebet 10-Sep-13 11:54am    
if you put this in excel every "keyword" is a new cell -> or do you want to convert an excel file to a txt ?
 
Share this answer
 
Comments
Sivarjun Chikkala 10-Sep-13 10:06am    
Thank you sir, I could not find exact solution but I am happy for your reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900