Ask Your Question
0

Save as CSV stricter rule following [closed]

asked 2012-11-06 20:28:00 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I am exporting a sheet of several thousand rows from LibreOffice and importing this data into something else. What I am importing this into requires very specific formatting, and I cannot seem to get the filters to save it in the format that it seems it should.

It is really just the typical csv format, except that the rules must be strictly followed. LibreOffice, with every setting I have changed, still exports numbers and empty cells without quotes.

Process I am currently using (though I have tried different versions of this: File > Save As > check "Edit filter settings" and select csv for format > Character set: [Unicode (UTF-8)], Field delimiter: [,], Text delimiter: ["], checked "Save cell content as shown" and "Quote text cells".

This will export:

[name][][][6][blah]

as

"name",,,6,"blah"

when I am wanting

"name","","","6","blah"

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-03-04 11:37:40.408556

Comments

That would nearly work. The problem that would leave is numbers, which also do not get quotes.

My best workaround I came up with was to save without quotations and do a find and replace , with ",". That left me manually entering the first and last ", but that was still better than doing it all.

shgysk8zer0 gravatar imageshgysk8zer0 ( 2012-11-17 09:04:57 +0200 )edit

3 Answers

Sort by » oldest newest most voted
0

answered 2012-11-20 04:35:27 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

If you're okay with post-processing, run the export with a unique character delimiter that doesn't appear in your document (e.g. \t) and turn off all field-level quoting.

Post-process with something like:

perl -ne 'chomp; @fields = split /\t/; print join ", ", map { qq/"$_"/ } @fields; print "\n"' lo-export-file-here.csv > output-file.csv
edit flag offensive delete link more
1

answered 2014-09-29 12:36:01 +0200

Andrew Wheeler gravatar image

I know this is old but as I was looking for the same information I thought I would post what I found.

Select all fields and set the format to text then save as Text CSV and check edit filter settings and set the field delimiter to , and the text delimiter to " and all fields are quoted.

edit flag offensive delete link more
0

answered 2012-11-06 21:46:47 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Here's a work-around. Do a search and replace on your table. Leave the search-for box blank, replace with ### (or some other unique string) and check the Entire-cells box. Export the CSV using the quote-all-text-cells option. The formerly empty cells will be quoted "###". Process the CSV file to replace ### with [nothing]. On Linux you could use sed

sed 's/###//g' input.csv >output.csv

but any text editor could work.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-11-06 20:28:00 +0200

Seen: 3,087 times

Last updated: Sep 29 '14