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

XL.Book.SaveToFile

Saves current workbook into xls-file.

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

Parameters

Parameter Description Example
bookRef The reference to the workbook. Please use XL.LoadBook to load a file. $ref
path The native path to write the file to. "C:\test.xls"

Result

Returns OK or error message.

Description

Saves current workbook into xls-file.
Returns error on failure or OK on result.

See FileDialog functions if you like to show a save dialog to pick a destination for the file path.

This function requires a native path. Use Path.FileMakerPathToNativePath to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use FileDialog functions.
For Server be aware that server has limited permissions and may not be able to access all files on a computer.

Examples

Preprocess file before import in FileMaker by removing a row and a sheet:

# Find libXL and load it
If [ MBS("XL.IsInitialized") ≠ 1 ]
    Perform Script [ Specified: From list ; “InitXL” ; Parameter: ]
End If
#
# path to xls or xlsx file
Set Variable [ $path ; Value: MBS( "Path.AddPathComponent"; MBS( "Folders.UserDesktop" ); "test.xls" ) ]
#
# Load template excel file
Set Variable [ $bookRef ; Value: MBS( "XL.LoadBook"; $path) ]
If [ MBS("IsError") ]
    Show Custom Dialog [ "Error" ; $bookRef ]
    Exit Script [ Text Result: ]
End If
#
# Remove first row of first sheet
Set Variable [ $r ; Value: MBS( "XL.Sheet.RemoveRow"; $BookRef; 0 /* sheet index */; 0 /* row index */) ]
#
# Remove second sheet
Set Variable [ $r ; Value: MBS( "XL.Book.DeleteSheet"; $bookRef; 1 /* sheet index */ ) ]
#
# Save to file and cleanup
Set Field [ XL::OutputFile ; MBS("XL.Book.SaveToFile"; $bookRef; $path) ]
Set Variable [ $r ; Value: MBS( "XL.Book.Release"; $bookRef) ]
#
# now let FileMaker import file

Let user pick where to save file:

Set Variable [ $name ; Value: "test.xlsx" // default name? ]
Set Variable [ $r ; Value: MBS("FileDialog.Reset") ]
Set Variable [ $r ; Value: MBS("FileDialog.SetMessage"; "Where to save file?") ]
Set Variable [ $r ; Value: MBS("FileDialog.SetFilter"; "xlsx"; "*.xlsx"; "Excel files") ]
Set Variable [ $r ; Value: MBS("FileDialog.SetNameFieldStringValue"; $name) ]
Set Variable [ $r ; Value: MBS("FileDialog.SaveFileDialog") ]
If [ $r = "OK" ]
    Set Variable [ $path ; Value: MBS("FileDialog.GetPath"; 0) ]
    Set Variable [ $r ; Value: MBS("XL.Book.SaveToFile"; $book; $path) ]
    Set Field [ Writing data::Output ; $r ]
End If

See also

Example Databases

Blog Entries

This function checks for a license.

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


XL.Book.Save - XL.Book.SetActiveSheet