Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

XL.Sheet.CellWriteNumber

Writes a number into cell.

Component Version macOS Windows Linux Server iOS SDK
XL 3.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "XL.Sheet.CellWriteNumber"; bookRef; sheetIndex; Row; Column; Value { ; Format } )   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
Row The row for the cell. First row has index 0. $row
Column The column for the cell. First column has index 0. $column
Value The new value to write. 123
Format The format for the cell. This is index from 0 to XL.GetFormatCount-1 in the book's list of formats. 0 Optional

Result

Returns OK or error message.

Description

Writes a number into cell.
If you run into problem with floating point number's limited precision, you may use XL.Sheet.CellWriteTextAsNumber instead.

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)]

Writes sheet with red font:

#create new xls file
Set Variable [$book; Value:MBS( "XL.NewBook"; 0 )]
#create fonts
Set Variable [$redColor; Value:MBS( "XL.Color.Pack"; $book; 255; 0; 0)]
Set Variable [$redFont; Value:MBS( "XL.Book.AddFont"; $book)]
Set Variable [$r; Value:MBS( "XL.Font.SetColor"; $book; $redFont; $redColor)]
#
#create formats
Set Variable [$redFormat; Value:MBS( "XL.Book.AddFormat"; $book)]
Set Variable [$r; Value:MBS( "XL.Format.SetFont"; $book; $redFormat; $redFont)]
#
#create sheet
Set Variable [$sheet; Value:MBS( "XL.Book.AddSheet"; $book; "Sales Receipt")]
#
#add number in red
Set Variable [$r; Value:MBS( "XL.Sheet.CellWriteNumber"; $book; $sheet; 5; 3; 123; $redFormat)]
#
Set Field [Writing data::Output; MBS("XL.Book.Save"; $book; "test.xls")]
Set Variable [$r; Value:MBS("XL.Book.Release"; $book)]

Use a number format:

# create new format
Set Variable [$format; Value:MBS( "XL.Book.AddFormat"; $book)]
# use existing number format
Set Variable [$r; Value:MBS( "XL.Format.SetNumFormat"; $book; $format; 7)]
# and use format
Set Variable [$r; Value:MBS( "XL.Sheet.CellWriteNumber"; $book; $sheet; 5; 3; 123; $format)]

Write to a time formatted cell a time value:

MBS("XL.Sheet.CellWriteNumber"; $BookRef; $sheet; $row; $col; GetAsNumber(ExcelTest::TimeField)/(24*60*60))

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 26th May 2020


XL.Sheet.CellWriteMatrix - XL.Sheet.CellWriteNumbers