Click here to Skip to main content
16,022,901 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to process find and replace on a file by reading the excel file. the excel file is structured this way.

What I have tried:

This is how my program is structured.
Posted
Updated 26-Jan-17 12:43pm
v3
Comments
[no name] 26-Jan-17 20:24pm    
"This is how my program is structured", well of course! It all makes sense now. That would never work.

You need to do it this way

1 solution

Reading the excel file is quite straightforward. You can use OleDbConnection to create a connection to it and then read the data using OleDbCommand. For example, have a look at Read Excel File into DataSet in ASP.NET Using C#[^]

After you have got the data into the datatable, loop through the rows and create the output. In pseudo code, a very simple approach could be
C#
for each row in excel data table
   open file(row[0]) for apppend
   replace string(row[0]) with ...
   // other replacements if any
   close file
next row

Of course that code unnecessarily opens and closes the same file if the file is the same between several rows so you can optimize that if needed.
 
Share this answer
 
Comments
Member 12494414 11-Jan-17 1:20am    
All the parts are working but not in the right order or logic. Look at the output of the code and the expected output.

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