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:
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
13.5
Statistic
FMM
Blog
Deletes a sheet with specified index.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
XL | 3.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example |
---|---|---|
bookRef | The reference to the workbook. Please use XL.LoadBook to load a file. | $ref |
sheetIndex | The index of the sheet to delete. This number ranges from 0 to XL.Book.SheetCount-1. | 0 |
Returns OK on success.
Remove all sheets but the second one:
#Find libXL and load it
If [MBS("XL.IsInitialized") ≠ 1]
Perform Script [“InitXL”]
End If
#Load template excel file
Set Variable [$bookRef; Value:MBS( "XL.LoadBook"; "/Users/cs/Desktop/Test.xlsx")]
If [MBS("IsError")]
Show Custom Dialog ["Error"; $bookRef]
Exit Script []
End If
#remove all but second sheet
Set Variable [$c; Value:MBS( "XL.Book.SheetCount"; $bookRef )]
If [$c >= 2]
If [$c > 2]
Set Variable [$i; Value:2]
Loop
Set Variable [$r; Value:MBS( "XL.Book.DeleteSheet"; $bookRef; $i )]
Set Variable [$i; Value:$i + 1]
Exit Loop If [$c = $i]
End Loop
End If
Set Variable [$r; Value:MBS( "XL.Book.DeleteSheet"; $bookRef; 0 )]
End If
#Save to container and cleanup
Set Variable [$r; Value:MBS("XL.Book.SaveToFile"; $bookRef; "/Users/cs/Desktop/output.xlsx")]
Set Variable [$r; Value:MBS( "XL.Book.Release"; $bookRef)]
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
This function checks for a license.
Created 18th August 2014, last changed 13th February 2020