Example Code in Basic for a single macro to perform both functions
REM ***** BASIC *****
Option Explicit
Sub SetFreezeAndWidth
ThisComponent.CurrentController.freezeAtPosition(1, 1)
ThisComponent.CurrentSelection.Spreadsheet.Columns.OptimalWidth = True
End Sub
To place this in a module. From the menu “Tools”, “Macros”, “Organise Macros”, “LibreOffice Basic…” then expand “My Macros”, select “Standard” and click on “New”. You can name the module or just keep the default and click “OK”. Copy the above code into the new module replacing the existing Main sub.
Assign the macro to a hot key using the menu “Tools”, “Customise…”. On the “Keyboard” tab. At the top right select the “Calc” radio button. Select an un-used shortcut key combination. In “Category” expand “LibreOffice Macros”, expand “user”, expand “Standard”, and select the module where you placed the code. In “Function” select the name of the sub “SetFreezeAndWidth”. Then click on “Modify” to set the macro to the hot key selected. Click on OK to exit the dialog.
For more details on macros check the Andrew Pitonyak book