A
AA_NED
Guest
Hi,
I am trying to write a console app that extract specific lines from text file and write them in the second column of the excel sheet
my file look like this:
----------
Other text
a,text1,text,text
b,text2,text,text
c,text3,text,text
other text
------------
Once the words in bold are extracted, they need to be written in existing workbook.
So far I am able to read the file and extract the required part but not able to write this to the excel file. Can you please help me on this?
string path = @"C:\Test.txt";
StreamReader file = new System.IO.StreamReader(path);
bool fn = false;
while ((line = file.ReadLine()) != null)
{
if (line.StartsWith("a"))
{
fn = true;
}
if (fn)
{
line = line.Replace(",", "");
var parts = Array.ConvertAll(line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries), lineItem => lineItem.Trim());
string myTxt = parts[1];
if (parts[0].Equals("c"))
{
Console.ReadLine();
break;
Continue reading...
I am trying to write a console app that extract specific lines from text file and write them in the second column of the excel sheet
my file look like this:
----------
Other text
a,text1,text,text
b,text2,text,text
c,text3,text,text
other text
------------
Once the words in bold are extracted, they need to be written in existing workbook.
So far I am able to read the file and extract the required part but not able to write this to the excel file. Can you please help me on this?
string path = @"C:\Test.txt";
StreamReader file = new System.IO.StreamReader(path);
bool fn = false;
while ((line = file.ReadLine()) != null)
{
if (line.StartsWith("a"))
{
fn = true;
}
if (fn)
{
line = line.Replace(",", "");
var parts = Array.ConvertAll(line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries), lineItem => lineItem.Trim());
string myTxt = parts[1];
if (parts[0].Equals("c"))
{
Console.ReadLine();
break;
Continue reading...