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: 10.1   10.2   10.3   10.4   10.5   11.0   11.1   11.2   11.3   11.4    Statistic    FMM    Blog  

XL.Book.AddCustomNumFormat

Adds a new custom number format to the workbook.

Component Version macOS Windows Linux Server iOS SDK
XL 3.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "XL.Book.AddCustomNumFormat"; bookRef; format )   More

Parameters

Parameter Description Example
bookRef The reference to the workbook. Please use XL.LoadBook to load a file. $ref
format The format string. "#.000"

Result

Returns number or error.

Description

Adds a new custom number format to the workbook.
The format string customNumFormat indicates how to format and render the numeric value of a cell.
Returns the custom format identifier. It's used in XL_Format_setNumFormat.
Read website for details:
http://www.libxl.com/custom-format.html

Examples

Create Excel file with some date value:

#create new xls file
Set Variable [$book; Value:MBS( "XL.NewBook"; 0 )]
#create date format
Set Variable [$dateFormat; Value:MBS( "XL.Book.AddFormat"; $book)]
Set Variable [$dateFormatID; Value:MBS( "XL.Book.AddCustomNumFormat"; $book; "mmmm\ d\,\ yyyy")]
Set Variable [$r; Value:MBS( "XL.Format.SetNumFormat"; $book; $dateFormat; $dateFormatID)]
#create sheet
Set Variable [$sheet; Value:MBS( "XL.Book.AddSheet"; $book; "Sales Receipt")]
#Write date
Set Variable [$d; Value:MBS( "XL.Date.Pack"; $book; 2013; 10; 21)]
Set Variable [$r; Value:MBS( "XL.Sheet.CellWriteNumber"; $book; $sheet; 4; 4; $d; $dateFormat)]
#
Set Field [Writing data::Output; MBS("XL.Book.Save"; $book; "test.xls")]
Set Variable [$r; Value:MBS("XL.Book.Release"; $book)]

Add american phone number formatting:

Set Variable [$f; Value:MBS( "XL.Book.AddCustomNumFormat"; $book; "[<=9999999]###\\-####;\\(###\\)\\ ###\\-####")]

Add dollar amount formatting:

Set Variable [$f; Value:MBS( "XL.Book.AddCustomNumFormat"; $book; "_($ # ##0.00_);_($ (# ##0.00);_($* -??_);_(@_)")]

Add a custom format with condition:

# define custom number format
#
Set Variable [ $customFormat ; Value: MBS( "XL.Book.AddCustomNumFormat"; $book; "[Red]#[<=100];[Blue]#[>100]") ]
#
# make format
#
Set Variable [ $textFormat ; Value: MBS( "XL.Book.AddFormat"; $book) ]
Set Variable [ $r ; Value: MBS( "XL.Format.SetNumFormat"; $book; $textFormat; $customFormat) ]
#
# add sheet and use format:
#
Set Variable [ $sheet ; Value: MBS( "XL.Book.AddSheet"; $book; "") ]
Set Variable [ $r ; Value: MBS( "XL.Sheet.CellWriteNumber"; $book; $sheet; 8; 1; 90; $textFormat) ]
Set Variable [ $r ; Value: MBS( "XL.Sheet.CellWriteNumber"; $book; $sheet; 8; 1; 110; $textFormat) ]

Format dollar with CAD before:

MBS( "XL.Book.AddCustomNumFormat"; $book; "\"CAD \"$#,##0.00;\"CAD -$\"#,##0.00;\"CAD $\"0.00;@")

See also

Example Databases

Created 18th August 2014, last changed 12nd June 2018


X509.Write - XL.Book.AddFont

Feedback: Report problem or ask question.