# Is there a way to globally set the maximum column width in Calc?

I frequently work with .csv files, and I've found that whenever I open one of these sheets, columns with cells that contain a large amount of data will be expanded to such a degree that I can see everything in the cells.

This isn't desirable, though, because I find myself having to shrink the column width every single time so that I can easily view the data in other columns as well.

My question is, is there a setting that allows me to essentially tell Calc to never set the column width beyond X (or, even better, to always open up .csv files with the default column width)?

I'm using version 6.3.3.2 on Windows 10.

edit retag close merge delete

Sort by » oldest newest most voted

Well you can do linking the cells to the csv instead open it.

Create a new spreadsheet, open the csv, copy the first cell in csv to the first cell in the new spreadsheet, using paste-special selecting option 'link' and paste. Copy this cell in the new spreadsheet for the cells that you need, and format it as you like.

When the new spreadsheet it's open you can see on top a message about update, and if you need to change the linked csv file use Menu/Edit/Link to external files - Modify

more

Hello,

AFAIK - No, you can't do that. You can't even work with a customized calc template, since this will be ignored by csv input (see #tdf86336)

more

In addition to what @Opaque and @m.a.riosv 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)
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.)

more

For any specific csv you would have to adjust anything to your needs only once

The problem is that I have to work with many, many .csv files. I do understand that a .csv file can't save settings, but I'm somewhat surprised that Libre Office doesn't have a global setting to force a maximum column width (regardless of file format).

( 2020-04-05 21:02:34 +0100 )edit

Some are surprised that LibO hasn't this or that feature.
Others are surprised that it has many a feature they judge to be absolutely useless.
Others again are surprised that there are user knowing and being slick in handling the thousands of features and settings available.
I'm surprised that some users often manage to avoid most of the legion of errors probably caused by the multitude and occasional incompatibility of features ... Most I am surpised if there was an opportunity to learn something new about specifics of the implementation that I hadn't expected possible. Such an opprtunity was today concerning the property .OptimalWidth of spreadsheet columns - thanks to your question.
The special need you requested should anyway be catered by the code I published.
I meanwhile enhanced it a bit to also be able to apply a minimum width and to set a customized default for empty ...(more)

( 2020-04-06 00:03:09 +0100 )edit