Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV file needs a new column inserted

Status
Not open for further replies.

jimdena33

Programmer
Sep 20, 2008
5
US
I have a CSV file that I open w/ C# via inline = rdr.ReadLine();

While (inline != null)

wrtr.writeline(blah blah....

Wrtr.close

How can I insert a new column in position number 27?
 
create a typed object which reflects the row. each column is a property. include a property for the new property.
read each row, convert to object, set value of the new property. convert object to row, write row to file. Rhino.ETL makes this dead simple.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
rhino.etl gives you the building blocks. you just tie the pieces together. in this scenario there is 1 process with 3 operations
1. get data from csv
2. add new value
3. write objects to csv

if you need help understanding the source review the unit tests, use the forum. This presentation is very helpful in getting started with rhino.etl.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
BTW you don't have to use Rhino.ETL. you can do the same thing on you your own. your code can focus on the business problem without the details of how to read/write data. Otherwise you need to write all the infrastructure to read/write the csv, exception handling etc. along with actually doing the task you want... adding data to the csv.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Current the C# app gets the data and writes it as all one line.

Sounds like I'll have to add a bunch of new code to identify each .csv column as an object from left to right across - just to then get things goind.

Do you agree?
 
Current the C# app gets the data and writes it as all one line.
I think you are comparing apples and oranges. The API you use to export may be 1 LOC, but that doesn't mean the logic is located within that single member, it could be spaced out over an entire object graph.

Rhino.ETL let you build the pieces. the code to actually run the routine looks something like
Code:
new PipelineExectutor().Execute(new MyExportProcess());
Sounds like I'll have to add a bunch of new code to identify each .csv column as an object from left to right across
Code:
public class Foo
{
  public int I {get;set;}
  public string S {get;set;}
  ...
}
isn't too much code, is it? You still need to implement each operation (select, modify, write). Even then each operation can be implemented with around 10-20 lines of code

watch the presentation and review the unit tests provided with the source. Once you understand that you'll see Rhino.ETL makes ETL operations simple.

here are 2 other resources on Rhino.ETL

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top