Convert XLS to CSV custom Field separators(string)

Discuss the spreadsheet application
Post Reply
endless
Posts: 4
Joined: Mon Sep 10, 2018 4:19 pm

Convert XLS to CSV custom Field separators(string)

Post by endless »

Hi

I am trying to convert a XLS to CSV with a string separator like '_A_'

I read the documentation and to use the '_' as separator you have to use the ASCII character 95 :

Code: Select all

 /usr/bin/soffice --headless  --convert-to csv:"Text - txt - csv (StarCalc)":95,34,76,,,,true "file.xls" 
it is working fine.

For multiple values documentation says:
1. Field separator(s) as ASCII values. Multiple values are separated by the slash sign ("/"), that is, if the values are separated by semicolons and horizontal tabulators, the token would be 59/9. To treat several consecutive separators as one, the four letters /MRG have to be appended to the token. If the file contains fixed width fields, the three letters FIX are used.
I tried with 95/65/95 (ASCII for _A_ ) but it ignore 65/95

ex:

Code: Select all

 /usr/bin/soffice --headless  --convert-to csv:"Text - txt - csv (StarCalc)":95/65/95,34,76,,,,true "file.xls" 
I also tried with the /MRG after the 95:

Code: Select all

 /usr/bin/soffice --headless  --convert-to csv:"Text - txt - csv (StarCalc)":95/65/95/MRG,34,76,,,,true "file.xls" 
and

Code: Select all

 /usr/bin/soffice --headless  --convert-to csv:"Text - txt - csv (StarCalc)":95/MRG/65/MRG/95/MRG,34,76,,,,true "file.xls" 

but it only add the 95( _ ) separator.

Is it possible to use a word as a field separator?
OpenOffice 2.4 on Ubuntu 9.04
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Convert XLS to CSV custom Field separators(string)

Post by RoryOF »

If i were doing this, I would use a unique token as separator in the CSV file, then edit with a plain text editor and do a global Find and Replace to Find my token then Replace with WORD.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Convert XLS to CSV custom Field separators(string)

Post by FJCC »

I suspect that the handling of multiple separators is only for the import process and that exporting is limited to one separator.The MRG option just doesn't make sense for exporting. RoryOF's suggestion is probably the best path.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
endless
Posts: 4
Joined: Mon Sep 10, 2018 4:19 pm

Re: Convert XLS to CSV custom Field separators(string)

Post by endless »

Thanks for the suggestion.

I am using the token 7(a non printable character for BEL)
and replacing it with sed

Code: Select all

  sed -i 's/\d7/_A_/g' "file.csv"

I hope nobody uses this non-printable character on an XLS file.
OpenOffice 2.4 on Ubuntu 9.04
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Convert XLS to CSV custom Field separators(string)

Post by Lupp »

You surely will intend to use the created files for input again some time. What import filter/software will be in charge of that then?
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
endless
Posts: 4
Joined: Mon Sep 10, 2018 4:19 pm

Re: Convert XLS to CSV custom Field separators(string)

Post by endless »

Lupp wrote:You surely will intend to use the created files for input again some time. What import filter/software will be in charge of that then?
I am processing the CSV with jq.
with jq, I can convert CSV to json.
but, I was having a problem with strings with ',' like :

"apple,orange", 10, "blue"

So I created this custom delimiter.

Also In jq, I can't find a way to use an ASCII character as a delimiter. So I am using a word as delimiter
OpenOffice 2.4 on Ubuntu 9.04
User avatar
Zizi64
Volunteer
Posts: 11360
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Convert XLS to CSV custom Field separators(string)

Post by Zizi64 »

I am processing the CSV with jq.
with jq, I can convert CSV to json.
but, I was having a problem with strings with ',' like :

"apple,orange", 10, "blue"
The TSV type file is not appropriate for you? (TSV: TAB Separated Values - In the locales where the "," used as decimal separator the comma is unusable as data separator for the files containing some numbers)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
endless
Posts: 4
Joined: Mon Sep 10, 2018 4:19 pm

Re: Convert XLS to CSV custom Field separators(string)

Post by endless »

the xls is generated by the user.
As I have no control over what they put in the fields I have to make sure the separator is not used in the xls.
I believe any non-printable character will work.
OpenOffice 2.4 on Ubuntu 9.04
Post Reply