Export to .csv without trimming whitespace

Hello everyone,

in my project, I have cells that contain a newline in the beginning, like so:

Entry in Column 1:
"line 1 content
line 2 content"

Entry in Column 2:
"
line 2 extra info"

The linebreak uses “\r\n”. After exporting to .csv, I want to keep the linebreak in column 2, so I can properly assign "line 2 extra info" to "line 2 content" at a later stage.
But while Column 1 gets exported as expected, Column 2 gets exported as simply “line 2 extra info", so the linebreak is trimmed away, it seems.
This is OpenRefine 3.10.0, no extensions, on Windows.

I have looked at the Export section in the docs and found nothing there, nor in forums I’ve searched so far.
I have tried using TSV instead, using different separators in “Export custom tabular” and using the “Always quote text” option with no success.

The only workaround I’ve found so far is to export the project as .xlsx and then from Excel/LibreOffice save it as a .csv. That preserves the newlines but is rather cumbersome.
Does anyone know a better way to preserve the newlines at the beginning of the cell?

Thank you

PS: I found no fitting keywords for this question and just used “hints-and-tips”.

I can confirm that in my testproject on OpenRefine 3.10.0 on Windows the leading linebreaks also get trimmed on CSV and TSV export.

My workaround would be to use the Templating export to preserve the format.

That sounds like a bug. Please file a bug report in our issue tracker: https://github.com/OpenRefine/OpenRefine/issues

Thank you for the answers! @b2m Since my project had more than 100 columns that needed to be exported repeatedly, I decided to just stick with the Excel workaround instead of creating a template for all those columns.

For anyone who does want to do that, though, here is how to get the string values necessary for the custom csv template:

  • The column names for the prefix can be found with the GREL expression: forEach(row.columnNames,v,v).join(",")
  • The row template: forEach(row.columnNames,v,"{{cells["" + v + ""].value}}").join(",")
  • The row separator is just a line break
  • The suffix is empty

This does preserve the newlines for me.

@tfmorris Allright, will do!

Thanks for creating the issue in the tracker. The fix has been merged and will be included in 3.10.2.