xlsxSheet
Manage sheets in an Excel file.
Syntax
result = xlsxSheet(filename, operation, ...)
Arguments
- filename
A string specifying the path to the Excel (.xlsx) file.
- operation
A string specifying the operation to perform: "create", "delete", "rename", or "info".
- "create", sheet_name [, sheet_index]
Create a new sheet in the workbook.
sheet_name (string): Name of the new sheet
sheet_index (integer, optional): Position where to insert the sheet (1-based). If omitted, sheet is added at the end.
- "delete", sheet_identifier
Remove a sheet from the workbook.
sheet_identifier: Sheet name (string) or index (positive integer)
- "rename", sheet_identifier, new_name
Change the name of an existing sheet.
sheet_identifier: Current sheet name (string) or index (positive integer)
new_name (string): New name for the sheet
- "info" [, sheet_identifier]
Get information about the workbook or a specific sheet.
Without sheet_identifier: Returns complete workbook information (all sheets)
With sheet_identifier: Returns information for the specified sheet only
Description
Manage Excel workbook operations: create new sheets, delete existing sheets, rename sheets, or retrieve sheet information.
Operations:
"create" - Create a new sheet in the workbook:
Syntax:
xlsxSheet(filename, "create", sheet_name [, sheet_index])sheet_name: Name of the new sheet (string)
sheet_index: Optional position where to insert the sheet (1-based). If omitted, sheet is added at the end.
Creates the file if it doesn't exist
"delete" - Remove a sheet from the workbook:
Syntax:
xlsxSheet(filename, "delete", sheet_identifier)sheet_identifier: Sheet name (string) or index (positive integer)
Error if sheet doesn't exist or if attempting to delete the last remaining sheet
"rename" - Change the name of an existing sheet:
Syntax:
xlsxSheet(filename, "rename", sheet_identifier, new_name)sheet_identifier: Current sheet name (string) or index (positive integer)
new_name: New name for the sheet (string)
Error if sheet doesn't exist or if new_name is already used by another sheet
"info" - Get information about the workbook or a specific sheet:
Syntax:
xlsxSheet(filename, "info") or xlsxSheet(filename, "info", sheet_identifier)Without sheet_identifier: Returns complete workbook information (all sheets)
With sheet_identifier: Returns information for the specified sheet only
This operation calls xlsxInfo internally
Sheet identification:
Sheets can be identified by name (string) or by 1-based index (integer). Index 1 refers to the first sheet.
Return values
The return value depends on the operation performed:
"create", "delete", "rename": Returns an operation result code (typically 0 for success, non-zero for errors).
"info": Returns a structure containing workbook/sheet information: see xlsxInfo.
If an error occurs (sheet not found, invalid operation...), an error message is raised.
Examples
// Create example file data = [1 2 3; 4 5 6; 7 8 9]; test_file = TMPDIR + "/test_sheet.xlsx"; xlsxWrite(data, test_file, "title", "My Report", "subject", "Data Analysis", .. "description", "Quarterly analysis results"); // Create a new sheet named "Data" at the end of the workbook result = xlsxSheet(test_file, "create", "Data"); // Create a new sheet at position 2 (becomes the 2nd sheet) result = xlsxSheet(test_file, "create", "Summary", 2); // Delete a sheet by name result = xlsxSheet(test_file, "delete", "Data"); // Delete a sheet by index (delete the 2nd sheet) result = xlsxSheet(test_file, "delete", 2); // Rename a sheet by name result = xlsxSheet(test_file, "rename", "Sheet1", "NewData"); // Get information about all sheets in the workbook info = xlsxSheet(test_file, "info") // Get information about a specific sheet by index info = xlsxSheet(test_file, "info", 1)
See also
History
| Версия | Описание |
| 2026.1.0 | Introduction in Scilab. |
| Report an issue | ||
| << xlsxRead | Электронная таблица | xlsxWrite >> |