0

I have a my address stored in the database as follows.

Address_1, Address_2, Address_3, City, State, Country, Pin.

In the report (CSV) that is to be generated, all of these should appear under one field Address neatly formatted i.e., as below

Address_1 \n Address_2 \n Address_3 \n City \n State \n Country \n Pin

so that when they open it in Excel, they all appear in one Cell.

How can I get it using C#?

4
  • I guess you want \t as the separator. \n is newline Commented Dec 13, 2010 at 11:45
  • @VVS: i guess he tries to create multiline-columns :) Commented Dec 13, 2010 at 11:46
  • @Andreas Niedermair: Ah, you might be right. Maybe the OP wants to clarify that. Commented Dec 13, 2010 at 11:48
  • @VVS: I want the address as a multiline-cell Commented Dec 13, 2010 at 11:50

3 Answers 3

2

If you write your CSV file wrapping the address in quotes, it will come out in a single cell in Excel (2010 anyway)... The fields are still separated with a comma, and the \r\n indicate the newlines in the file.

Tom,"address1,\r\n
address2,\r\n
address3", nextcolumn!\r\n
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Worked like a charm! This method works in Excel 2007 as well (which is what I wanted!)
0

Whenever I need to import or export data in text form, I use FileHelpers. That said, there are plenty other libraries that are also able to write csv.

11 Comments

@VVS: Thanks! I cannot use other libraries with this particular client.
@Kanaini: So if you can't use other libraries, what do you expect from us? To write an RFC 4180 compliant CSV Writer for you?
@VVS: No, but you can atleast answer as to whether there is a way to do it using C#/Microsoft libraries (and provide helpful pointers) or inform nay educate me that it cannot be done.
@Andreas Niedermair:Thanks! So, that means that this sort of thing can never be achieved. Right?
@Andreas Niedermair: Here's my proof. For the right screenshot I adjusted the row height. i52.tinypic.com/14sjq8i.png
|
0

CSV format does not allow this feature. CSV format - it just text file that is divided by some delimiters (e.g. "\t" or "," or ";"). If you want multiline-columns you should use another file format (e.g. XLS)

1 Comment

Tom's idea just worked. I enclosed the whole address variable in qotes and then put in delimiters of \r\n for each internal sub-field and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.