Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to replace \n with alt+enter while exporting to .CSV

how to replace \n with alt+enter while exporting to .CSV

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sma123
    wrote on last edited by
    #1

    how to replace \n with alt+enter while exporting to .CSV HI, I am writing line by line to a file(.CSV). If the string is having "\n" in between then the multiline is not possible for a single cell and it is coming to the next line of Excel . Can anyone help me to replace the "\n" with "Alt+Enter" equivalent? I am using CSting to collect the entire line at a tiime. I am trying as below CSting temp; temp.Replace("\n", "")); Thanks SMA

    J 1 Reply Last reply
    0
    • S sma123

      how to replace \n with alt+enter while exporting to .CSV HI, I am writing line by line to a file(.CSV). If the string is having "\n" in between then the multiline is not possible for a single cell and it is coming to the next line of Excel . Can anyone help me to replace the "\n" with "Alt+Enter" equivalent? I am using CSting to collect the entire line at a tiime. I am trying as below CSting temp; temp.Replace("\n", "")); Thanks SMA

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      Let the line feed in place and enclose the cell content by double quotes. This should be accepted by Excel when rows are terminated by carriage return - line feed pairs. So your CSV file should look like:

      Row1:Col1, "Row1:Col2\n with new line"\r\n
      Row2:Col1, "Row2:Col2, with comma"\r\n
      Row3:Col1, "Row3:Col2 with "" esacped quote"\r\n
      Row4:Col1, " Row4:Col2 begins and/or ends with space "\r\n

      As an alternative you may write HTML files using tables. These can be also imported by Excel.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups