In addition to what @anon73440385 and @mariosv told:
The ordinary way to work with csv-style files in Calc is to import the content into a sheet and then to store the sheet to .ods
.
Why don’t you work this way? For any specific csv you would have to adjust anything to your needs only once.
A csv cannot store settings.
You can create a spreadsheet doument from any template, insert a new sheet From file
, and Copy
/ Paste Special...
(Formats only) the formats of any sheet contained in your template over the new sheet.
If you are fond of “macros” you may also write one based on the following example and apply it when your newly imported csv sheet is active:
Sub limitColumnWidth(Optional pMaxWidth As Long)
If IsMissing(pMaxWidth) Then pMaxWidth = 9998 REM Adjust to your needs"
sheet = ThisComponent.CurrentController.ActiveSheet
cols = sheet.Columns
cur = sheet.createCursorByRange(sheet.getCellRangeByName("a1"))
cur.gotoEndOfUsedArea(True)
cols = cur.Columns
cols.OptimalWidth = True
u = cols.Count - 1
For j = 0 To u
j_col = cols(j)
If j_col.Width>pMaxWidth Then j_col.Width = pMaxWidth
Next j
End Sub
Of course, you can also force a minimum column width this way.
(A reason for me to hesitate with the suggestion is, that I recently got the impression the TableCursor method .gotoEndOfUsedArea
might be buggy.
To understand the code you should know that (for reasons unknown to me) the .OptimalWidth
is always True
and cannot be changed, but only gets applied if newly set. (Strange idea. May have had predecessors decades ago.)