How to write data on multiple lines BUT within the same cell of csv?

后端 未结 5 946
深忆病人
深忆病人 2020-12-15 19:24

I want to create one csv file using C#.

I have some data which I want to write on multiple lines BUT within the same cell.

For example If I have following t

相关标签:
5条回答
  • 2020-12-15 20:07

    To quote Wikipedia:

    Fields with embedded line breaks must be enclosed within double-quote characters.

    Like e.g.:

    1997,Ford,E350,"Go get one now
    they are going fast"
    
    0 讨论(0)
  • 2020-12-15 20:07

    You might be able to change which tokens your application uses to parse rows from the csv file, but according to the definition of the csv file format, lines in the file are used to represent rows in the resulting tabular data.

    0 讨论(0)
  • 2020-12-15 20:18
    string input = "...";
    
    var r = input.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries) // split by dot (have you any better approaches?)
                 .Select(s => String.Format("\"{0}.\"", s.Trim())); // escape each with quotes
    
    input = String.Join(Environment.NewLine, r); // break by line break
    
    0 讨论(0)
  • 2020-12-15 20:19

    CSV stands for "comma seperated values" which is just a description of a text-file. If you want to import into Excel and then only have the sentences in one line you should try:

    Environment.NewLine
    

    instread of a simple /n

    0 讨论(0)
  • 2020-12-15 20:27

    Always wrap your description in between "\" eg: CsvRow.Add("\"" + ID + " : " + description + "\"");

    0 讨论(0)
提交回复
热议问题