SpreadSheets
Overview¶
AMI supports user interactions and manipulation of spreadsheets. Users can create new spreadsheets or import existing ones for editing within the AMI environment. This section will discuss the various ways to work with spreadsheets in AMI.
Contents:
- Parsing XLSX & CSV files
- AMI Spreadsheet Classes
- Downloading Spreadsheets from AMI
- Example Workflows
Parsing CSV and XLSX¶
For simple use cases, AMI allows for the parsing of both XLSX and CSV file formats. Users can import these files into the AMI environment for further manipulation and analysis.
To import an existing spreadsheet, first create an empty datamodel, then add the following AMIScript to the onProcess tab.
Parsing CSV¶
parseCsv(String text, Boolean firstLineIsHeader)
Parse the CSV file and returns a table.
Parsing XLSX¶
parseXlsx(Binary data, Boolean firstLineIsHeader, String sheetName)
Parse the XLSX file and returns a table.
AMI Spreadsheet Classes¶
For more complex use cases, AMI provides a set of spreadsheet classes that facilitate various operations on spreadsheets. These classes offer methods for reading, writing, and modifying spreadsheet data. The classes include:
SpreadSheet Builder:
- Purpose: Used to generate a new spreadsheet within AMI web environment.
- Features: Required for creating both flexsheets and worksheets. Provides foundational methods for building spreadsheet structures.
- Use Case: Initialize a new spreadsheet project, laying the groundwork for further customization and data manipulation.
- Note: Currently, combining both flexsheets and worksheets within a single spreadsheet builder is not supported.
SpreadSheet Flexsheet:
- Purpose: Designed to create and manage flexsheets in AMI.
- Features: Supports workflows involving Excel to AMI and back to Excel. Facilitates flexible data handling and transformation within AMI.
- Use Case: Best suited for scenarios where users need to import Excel spreadsheets into AMI, manipulate the data, and then export it back to Excel.
Spreadsheet Worksheet:
- Purpose: Used to generate and manage individual worksheets in AMI.
- Features: Focuses on the workflow from AMI to Excel, allowing detailed operations on specific worksheets.
- Use Case: Best suited for exporting data from AMI into Excel.
SpreadSheet Builder¶
Method | Return Type | Description |
---|---|---|
addSheet(TablePanel tablePanel, String sheetName, Boolean onlySelectedRows, Boolean shouldFormat) |
Boolean | Adds a new worksheet to the spreadsheet builder. |
addFlexSheet(String name) |
Boolean | Adds a new flexsheet to the spreadsheet builder. |
deleteSheet(String sheetName) |
Boolean | Deletes the specified spreadsheet from the spreadsheet builder. |
getExcelPosition(Integer position) |
String | Returns the alphabetical representation of the zero-based position. |
loadExistingSheets(Binary data) |
Boolean | Loads the binary data of an XLSX file into individual flex sheets. |
getSheetNames() |
Set | Returns a set containing the names of the sheets added, including hidden sheets. |
getWorksheet(String worksheetName) |
Object | Returns the spreadsheet in the SpreadSheetFlexsheet class. |
getWorksheet(String worksheetName) |
Object | Returns the spreadsheet in the SpreadSheetWorksheet class. |
hideSheet(String sheetName) |
Boolean | Hides the specified spreadsheet. |
showSheet(String sheetName) |
Boolean | Shows the specified hidden spreadsheet. |
renameSheet(String sheetName, String newSheetName) |
Boolean | Rename the specified spreadsheet. |
build() |
Boolean | Builds and returns a binary containing the spreadsheet. |
addSheet(TablePanel tablePanel, String sheetName, Boolean onlySelectedRows, Boolean shouldFormat)
Adds a new worksheet to the spreadsheet builder.
addFlexSheet(String name)
Adds a new flexsheet to the spreadsheet builder.
deleteSheet(String sheetName)
Deletes the specified spreadsheet from the spreadsheet builder.
getExcelPosition(Integer position)
Returns the alphabetical representation of the zero-based position.
loadExistingSheets(Binary data)
Loads the binary data of an XLSX file into individual flex sheets.
getSheetNames()
Returns a set containing the names of the sheets added, including hidden sheets.
getWorksheet(String worksheetName)
Returns the spreadsheet in the SpreadSheetFlexsheet class.
getWorksheet(String worksheetName)
Returns the spreadsheet in the SpreadSheetWorksheet class.
showSheet(String sheetName)
Shows the specified hidden spreadsheet.
renameSheet(String sheetName, String newSheetName)
Rename the specified spreadsheet.
build()
Builds and returns a binary containing the spreadsheet.
SpreadSheet Flexsheet¶
Method | Return Type | Description |
---|---|---|
getValue(String dimension) |
Boolean | Gets the value of the specified cell. |
getValues(String dimension, Boolean hasHeader, List classes) |
Boolean | Returns the values of the specified range of cells as a table. |
getValuesNamedRange(String nameRange, Boolean hasHeader, List classes) |
Boolean | Returns the values of the specified name range as a table. |
getTitle() |
String | Gets the name of the sheet. |
getStyle(String dimension) |
Boolean | Gets the style id associated with the specified cell. |
setValue(String dimension, Object value) |
Set | Sets the value for the specified range of cells. |
setValue(String dimension, Table value, Boolean useHeader) |
Object | Sets the value for the specified range of cells. |
setValueNamedRange(String nameRange, Object value) |
Object | Sets the values for the specified named range of cells. |
setTitle(String title) |
Boolean | Sets the name of the sheet. |
setStyle(String dimension) |
Boolean | Sets the style id for the specified range of cells. |
getValue(String dimension)
Gets the value of the specified cell.
getValues(String dimension, Boolean hasHeader, List classes)
Returns the values of the specified range of cells as a table.
If the values are of a date type in Excel, they are returned as strings.
To manage large Excel file with many columns, use the following approach:
Note: In this example, all columns are set to string type. You can modify the column types using Table::alterColumn(currentColumnName, newColumnName, newTypeOrNull)
.
getValuesNamedRange(String nameRange, Boolean hasHeader, List classes)
Returns the values of the specified name range as a table.
namedRange refers to the Names defined in the Name Manager in Excel.
getTitle()
Gets the value of the specified cell.
getStyle(String dimension)
Gets the style id associated with the specified cell.
setValue(String dimension, Object value)
Sets the value for the specified range of cells.
setValue(String dimension, Table value, Boolean useHeader)
Sets the style id associated with the specified cell.
setValueNamedRange(String nameRange, Object value)
Sets the values for the specified named range of cells.
namedRange refers to the Names defined in the Name Manager in Excel.
setTitle(String title)
Sets the name of the sheet.
setStyle(String dimension)
Sets the style id for the specified range of cells.
Spreadsheet Worksheet¶
Method | Return Type | Description |
---|---|---|
getTable() |
Table | Returns the table. |
getTitle() |
String | Gets the name of the sheet. |
setTitle(String title) |
String | Sets the name of the sheet. |
addColWithFormula(Integer position, String colName, String formula) |
Boolean | Creates a new formula based column. |
getTable()
Returns the table.
getTitle()
Gets the name of the sheet.
setTitle(String title)
Sets the name of the sheet.
addColWithFormula(Integer position, String colName, String formula)
Creates a new formula based column.
Downloading of SpreadSheets¶
Users can download their modified spreadsheets from AMI. This feature ensures that any changes made within the AMI environment can be saved and utilized outside of it.
From AMI Tables¶
To download an existing table in AMI as a spreadsheet, click on the Download as Spread Sheet
option.
From Datamodels¶
To download from Datamodels, use either of the following AMIScripts:
Session.downloadToBrowser(String fileName, String fileData)
FileSystem.writeFile(String file, String data, Boolean shouldAppend)
Example Workflows¶
This section provides example workflows that demonstrate how to use AMI's spreadsheet features.