Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 9.5   10.0   10.1   10.2   10.3   10.4   10.5   11.0   11.1   11.2    Statistic    FMM    Blog  

XL.Sheet.SetCol

Sets column width and format for all columns from colFirst to colLast.

Component Version macOS Windows Linux Server iOS SDK
XL 3.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "XL.Sheet.SetCol"; bookRef; sheetIndex; ColFirst; ColLast; Width { ; Format; Hidden } )   More

Parameters

Parameter Description Example Flags
bookRef The reference to the workbook. Please use XL.LoadBook to load a file. $ref
sheetIndex The index of the sheet. This number ranges from 0 to XL.Book.SheetCount-1. 0
ColFirst The first column. 0
ColLast The last column. 0
Width The new column width measured as the number of characters of the maximum digit width of the numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. Value -1 is used for autofit column widths. 10
Format The format for the cell. This is index from 0 to XL.GetFormatCount-1 in the book's list of formats. 0 Optional
Hidden Whether to hide columns. 0 Optional

Result

Returns OK or error message.

Description

Sets column width and format for all columns from colFirst to colLast.
If format equals 0 then format is ignored. Columns may be hidden.

Examples

Create sheet with column format:

# create new xls file
Set Variable [ $book ; Value: MBS( "XL.NewBook"; 1 ) ]
# load logo picture
Set Variable [ $logoID ; Value: MBS( "XL.Book.AddPictureContainer"; $book; Writing data::Logo) ]
# create fonts
# create format for column
Set Variable [ $colFormat ; Value: MBS( "XL.Book.AddFormat"; $book) ]
Set Variable [ $r ; Value: MBS( "XL.Format.SetWrap"; $book; $colFormat; 1) // enable wrap ]
Set Variable [ $r ; Value: MBS( "XL.Format.SetAlignH"; $book; $colFormat; 1) // left ]
#
# create specialized format for one cell with lock
Set Variable [ $lockFormat ; Value: MBS( "XL.Book.AddFormat"; $book; $colFormat) ]
Set Variable [ $r ; Value: MBS( "XL.Format.SetLocked"; $book; $lockFormat; 1) // on ]
#
# create sheet
Set Variable [ $sheet ; Value: MBS( "XL.Book.AddSheet"; $book; "Sales Receipt") ]
# set default format for whole column
Set Variable [ $r ; Value: MBS( "XL.Sheet.SetCol"; $book; $sheet; 1; 1; 12; $colFormat ) ]
#
# put some text in using column format
Set Variable [ $r ; Value: MBS( "XL.Sheet.CellWriteText"; $book; $sheet; 2; 1; "Long text wraps due to column format") ]
#
# and locked format
Set Variable [ $r ; Value: MBS( "XL.Sheet.CellWriteText"; $book; $sheet; 3; 1; "And this is locked"; $lockFormat) ]
#
# save and export
Set Field [ Writing data::Output ; MBS("XL.Book.Save"; $book; "test.xlsx") ]
Set Variable [ $r ; Value: MBS("XL.Book.Release"; $book) ]
#
Export Field Contents [ Writing data::Output ; Create folders: On ]

See also

Example Databases

Created 18th August 2014, last changed 11st February 2020


XL.Sheet.SetCellFormats - XL.Sheet.SetColHidden

Feedback: Report problem or ask question.