Open .csv by specifying column widths on command line

classic Classic list List threaded Threaded
8 messages Options
edonkey2001-libreoffice edonkey2001-libreoffice
Reply | Threaded
Open this post in threaded view
|

Open .csv by specifying column widths on command line

I've got some csv files to work with. They contain fields which are quite long, and opening them with LO results in very large columns, which are difficult to handle. Setting the column width by hand also has me enabling line wrapping to show the full cell content.

I'm looking for a way to open those files by specifying my intended column width and by enabling line wrapping.

e.g. this is the way to open files with custom input filter parameters:
soffice --infilter=CSV:44,34,UTF8 file.csv

what I need is a way to also specify column widths and enable line wrapping.




If this helps, I think I've narrowed down the scope to:
core/sc/source/ui/dbgui and core/sc/source/ui/inc
but I may be wrong.

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Brian Barker Brian Barker
Reply | Threaded
Open this post in threaded view
|

Re: Open .csv by specifying column widths on command line

At 09:18 07/04/2020 +0000, Nobody Noname wrote:
>I've got some csv files to work with. They contain fields which are
>quite long, and opening them with LO results in very large columns,
>which are difficult to handle. Setting the column width by hand also
>has me enabling line wrapping to show the full cell content. I'm
>looking for a way to open those files by specifying my intended
>column width and by enabling line wrapping.

I think there is a workaround, which may or may not be helpful.

o Start a fresh spreadsheet.
o Adjust the column widths as desired.
o Format relevant cells to "Wrap text automatically".
o Save as a template.

To use:
o Open CSV fie normally.
o Select all (Edit | Select All, or Ctrl+A, or click the rectangle at
top left where the row and column headers meet) or relevant cell range.
o Copy.
o Open new spreadsheet based on template.
o Click cell A1 or select all (as above).
o Paste, but using Edit | Paste Special (or Ctrl+Shift+V) instead of
normal Paste. In the Paste Special dialogue, ensure that Formats is
*not* ticked.

I trust this helps.

Brian Barker


--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy

edonkey2001-libreoffice edonkey2001-libreoffice
Reply | Threaded
Open this post in threaded view
|

Re: Open .csv by specifying column widths on command line

Thanks Brian for your reply, unfortunately that does not help me.

What I'm looking for is a way to work with csv files with minimum hassle.
I do not need features such as column widths, other formatting etc. to be saved in the file(s).
I just need to specify the way LO displays csv files when they are opened (as command line arguments so I can automate that).

Your proposed workaround would require manual adjustments, on a file by file basis, and each time they are opened.
These manual steps are what I'm looking to avoid. Else I could just resize the columns and enable wrapping every time and be done with this.

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Paul D. Mirowsky Paul D. Mirowsky
Reply | Threaded
Open this post in threaded view
|

Re: Open .csv by specifying column widths on command line

Would this work in your command line mixed with Brians' idea?

-n {filename} Creates a new document using *{filename}* as a template.

From:
https://help.libreoffice.org/Common/Starting_the_Software_With_Parameters

On 4/7/20 6:58 AM, [hidden email] wrote:
> Thanks Brian for your reply, unfortunately that does not help me.
>
> What I'm looking for is a way to work with csv files with minimum hassle.
> I do not need features such as column widths, other formatting etc. to be saved in the file(s).
> I just need to specify the way LO displays csv files when they are opened (as command line arguments so I can automate that).
>
> Your proposed workaround would require manual adjustments, on a file by file basis, and each time they are opened.
> These manual steps are what I'm looking to avoid. Else I could just resize the columns and enable wrapping every time and be done with this.
>

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Alex Thurgood Alex Thurgood
Reply | Threaded
Open this post in threaded view
|

Re: Open .csv by specifying column widths on command line

In reply to this post by edonkey2001-libreoffice
Le 07/04/2020 à 11:18, [hidden email] a écrit :

Hi,

> e.g. this is the way to open files with custom input filter parameters:
> soffice --infilter=CSV:44,34,UTF8 file.csv
>
> what I need is a way to also specify column widths and enable line wrapping.

My suggestion would probably be to use a python script to get LO running
and waiting for a connection (using the URP connection port), then
formatting your column widths using the appropriate python-UNO objects
after the CSV has been loaded into a Calc sheet. That way, at least in
theory, you wouldn't have to intervene at all in the GUI. You should
also be able to save the file as an ODS.

Another alternative would be to do something similar using python to
load a Calc template containing the required formatting, and then copy
your CSV values (range of cells) into that loaded Calc document. Again,
all of this should be doable without having to intervene via the GUI.

I don't know how to write such a script, as I'm not familiar enough with
python to do so.


Alex


--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Paul D. Mirowsky Paul D. Mirowsky
Reply | Threaded
Open this post in threaded view
|

Re: Open .csv by specifying column widths on command line

In reply to this post by edonkey2001-libreoffice
There may be another answer.

I import semi-colon (;) separated data into Writer, recorded Macro
filters and tied them together. In my case, I made a Menu which reformat
the data fields.

See the example below from URL:
https://ask.libreoffice.org/en/question/150565/execute-macro-in-calc-from-terminal/

> Also, this simple Sub:

> |SubFindSheet(aNumber)MsgBox"Here is the number "&aNumber EndSub|
>
> run from terminal as:
>
> |libreoffice6.0"macro:///Standard.Module1.FindSheet(4)"|
>
> or on some systems:
>
> |soffice "macro:///Standard.Module1.FindSheet(4)"|
>
> displays the proper variable and message in a message box.
>
> Another note, when executing the macro from terminal and all of LO is
> closed, you will briefly see the LO splash screen displayed.
>


> Thanks Brian for your reply, unfortunately that does not help me.
>
> What I'm looking for is a way to work with csv files with minimum hassle.
> I do not need features such as column widths, other formatting etc. to be saved in the file(s).
> I just need to specify the way LO displays csv files when they are opened (as command line arguments so I can automate that).
>
> Your proposed workaround would require manual adjustments, on a file by file basis, and each time they are opened.
> These manual steps are what I'm looking to avoid. Else I could just resize the columns and enable wrapping every time and be done with this.
>

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
edonkey2001-libreoffice edonkey2001-libreoffice
Reply | Threaded
Open this post in threaded view
|

Re: Open .csv by specifying column widths on command line

Hi Paul,
I've tried to create an ods file to use as template as suggested.
I've set my intended column widths in it, enabled line wrapping, then I saved it.

Then I ran:
soffice -n template.ods --infilter=CSV:44,34,UTF8 myfile.csv

Unfortunately what actually happens is that LibreOffice opens two files:
- a new file based on my template, which contains no data
- my csv file, without applying my template to it

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
Paul D. Mirowsky Paul D. Mirowsky
Reply | Threaded
Open this post in threaded view
|

Re: Open .csv by specifying column widths on command line

Calc template files end in .ots

Although I used Writer to make my macros, Writer does not export CSV
files correctly, or should I say without spaces as Calc does, I guess
you will have to make your macros in Calc. (Version: 6.3.5.2).

Hope this helps.

On 4/8/20 1:30 PM, [hidden email] wrote:

> Hi Paul,
> I've tried to create an ods file to use as template as suggested.
> I've set my intended column widths in it, enabled line wrapping, then I saved it.
>
> Then I ran:
> soffice -n template.ods --infilter=CSV:44,34,UTF8 myfile.csv
>
> Unfortunately what actually happens is that LibreOffice opens two files:
> - a new file based on my template, which contains no data
> - my csv file, without applying my template to it
>

--
To unsubscribe e-mail to: [hidden email]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy