Excel automation module for Total Control scripting system.
This module allows reading, writing, editing, and navigating Excel files (both .xls and .xlsx)
programmatically without launching Excel. It leverages Apache POI and provides an easy-to-use interface
for accessing and modifying worksheets, individual cells, and data ranges.
It supports:
- Reading full Excel sheets or specific cells
- Writing 2D arrays to new or existing sheets
- Switching between sheets
- Saving and exporting Excel files
- Getting metadata like version, sheet names, and used ranges
Additionally, it includes utility functions like readExcel() and writeExcel() for quick one-off operations.
The Excel object provides a powerful, object-oriented interface for manipulating spreadsheets, while
abstracting POI complexities.
Features
- Supports both
.xlsand.xlsxformats - Access any cell using A1 notation (e.g.,
"B2","C3:D5") - Update cell values and save files
- Retrieve workbook and worksheet objects for POI-level control
- Retrieve metadata such as sheet names and version
- Export specific ranges or entire worksheets as 2D arrays
- Switch between sheets dynamically
Example
var { Excel } = require("sigma/excel");
var excel = new Excel("E:/File/test.xls", "Sheet1");
var name = excel.get("C2");
print("Name in cell C2: " + name);
excel.set("C2", "Updated Name");
excel.save("E:/File/test_updated.xls");
excel.close();
Functions
Classes
(inner) readExcel(fileName, sheetName) → {Array}
Read the contents of the excel document, support "xls" and "xlsx" formats.
Example
var { readExcel } = require('sigma/excel');
// Read content of worksheet "Sheet1" in excel document "E:/File/test.xls"
var arrayStr = readExcel('E:/File/test.xls', 'Sheet1');
if (arrayStr != null) {
print("The contents of the Excel table are as follows:");
for (var i = 0; i < arrayStr.length; i++) {
for(var j = 0;j < arrayStr[i].length;j++) {
print(arrayStr[i][j]);
}
}
} else {
print("Failed to read! The error is: " + lastError());
}
Parameters:
| string | fileName |
Excel file name. |
| string | sheetName |
Sheet name. |
Returns:
| Array |
If successful, returns the contents of the Excel table(Two-dimensional array). If it fails, you can get the specific error message through the lastError() function. |
| string | excelName |
Excel file name. |
| string | sheetName |
Sheet name. |
| number | startColId |
Start writing the column number of the content. Note that the sequence number starts at 0, 3 indicates that the contents of the array will be written from the fourth column. |
| number | startRowId |
Start writing the row number of the content. Note that the sequence number starts at 0, 4 indicates that the contents of the array will be written from the fifth row. |
| array | dataArr |
Two-dimensional array. The data content of the excel table is about to be written, and each row of data members in the parameter does not need to have the same number. |
Returns:
| Boolean |
It returns true if successful, or false if there was an error, specific error information can be obtained by the lastError() function. |