XL.Sheet.SetCol
---------------

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

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [XL](component_XL.md) | [3.5](newinversion35.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "XL.Sheet.SetCol"; BookRef; SheetIndex; ColFirst; ColLast; Width { ; Format; Hidden } ) 

**MBS**( **"XL.Sheet.SetCol";** /\* Sets column width and format for all columns from colFirst to colLast. \*/  
**$BookRef**; /\* The reference number for the workbook.e.g. $ref \*/   
**$SheetIndex**; /\* The index of the sheet. This number ranges from 0 to [XL.Book.SheetCount](XLBookSheetCount.md)-1.e.g. 0 \*/   
**$ColFirst**; /\* The first column.e.g. 0 \*/   
**$ColLast**; /\* The last column.e.g. 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.e.g. 10 \*/   
**$Format**; /\* Optional; The format for the cell. This is index from 0 to XL.GetFormatCount-1 in the book's list of formats.e.g. 0 \*/   
**$Hidden**) /\* Optional; Whether to hide columns.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| BookRef | The reference number for the workbook. | $ref |  |
| SheetIndex | The index of the sheet. This number ranges from 0 to [XL.Book.SheetCount](XLBookSheetCount.md)-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.   
  
XL.Sheet.SetCol is the old name for [XL.Sheet.SetColumn](XLSheetSetColumn.md).  
### Examples

Create sheet with column format:

 # create new xls file   
Set Variable \[ $book ; Value: MBS ( "[XL.NewBook](XLNewBook.md)"; 1 ) \]   
\# load logo picture   
Set Variable \[ $logoID ; Value: MBS ( "[XL.Book.AddPictureContainer](XLBookAddPictureContainer.md)"; $book ; Writing data::Logo ) \]   
\# create fonts   
\# create format for column   
Set Variable \[ $colFormat ; Value: MBS ( "[XL.Book.AddFormat](XLBookAddFormat.md)"; $book ) \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Format.SetWrap](XLFormatSetWrap.md)"; $book ; $colFormat ; 1) // enable wrap \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Format.SetAlignH](XLFormatSetAlignH.md)"; $book ; $colFormat ; 1) // left \]   
\#   
\# create specialized format for one cell with lock   
Set Variable \[ $lockFormat ; Value: MBS ( "[XL.Book.AddFormat](XLBookAddFormat.md)"; $book ; $colFormat ) \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Format.SetLocked](XLFormatSetLocked.md)"; $book ; $lockFormat ; 1) // on \]   
\#   
\# create sheet   
Set Variable \[ $sheet ; Value: MBS ( "[XL.Book.AddSheet](XLBookAddSheet.md)"; $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](XLSheetCellWriteText.md)"; $book ; $sheet ; 2; 1; "Long text wraps due to column format") \]   
\#   
\# and locked format   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.CellWriteText](XLSheetCellWriteText.md)"; $book ; $sheet ; 3; 1; "And this is locked"; $lockFormat ) \]   
\#   
\# save and export   
Set Field \[ Writing data::Output ; MBS ("[XL.Book.Save](XLBookSave.md)"; $book ; "test.xlsx") \]   
Set Variable \[ $r ; Value: MBS ("[XL.Book.Release](XLBookRelease.md)"; $book ) \]   
\#   
Export Field Contents \[ Writing data::Output ; Create folders: On \]  
### See also

- [XL.Format.SetWrap](XLFormatSetWrap.md)
- [XL.NewBook](XLNewBook.md)
- [XL.Sheet.CellWriteText](XLSheetCellWriteText.md)
- [XL.Sheet.GetZoom](XLSheetGetZoom.md)
- [XL.Sheet.SetCellFormat](XLSheetSetCellFormat.md)
- [XL.Sheet.SetColPx](XLSheetSetColPx.md)
- [XL.Sheet.SetName](XLSheetSetName.md)
- [XL.Sheet.SetRow](XLSheetSetRow.md)
- [XL.Sheet.SetRowPx](XLSheetSetRowPx.md)
- [XL.Sheet.SetRows](XLSheetSetRows.md)

### Release notes

- **Version 13.3**
    - Added [XL.Sheet.SetColPx](https://www.mbsplugins.eu/XLSheetSetColPx.shtml) and [XL.Sheet.SetRowPx](https://www.mbsplugins.eu/XLSheetSetRowPx.shtml) functions.
- **Version 13.0**
    - Fixed [XL.Sheet.SetColumn](https://www.mbsplugins.eu/XLSheetSetColumn.shtml) and [XL.Sheet.SetRow](https://www.mbsplugins.eu/XLSheetSetRow.shtml) to better.

### Example Databases

- [XL/Writing data](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XL/Writing%20data.shtml#5ScriptAnchor_)
- [XL/XL Import and Export](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XL/XL%20Import%20and%20Export.shtml#4ScriptAnchor_)

This function checks for a license.

Created 18th August 2014 , last changed 22nd August 2022

  
[XL.Sheet.SetCellFormats](XLSheetSetCellFormats.md) - [XL.Sheet.SetColHidden](XLSheetSetColHidden.md)

[HTML Version](XLSheetSetCol.shtml)