Insert Column
Inserts a new column in a specified location in an Excel sheet.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If ContinueOnError property is true, no error is caught when the project is executed even if a Catch node is used.
Input
- Excel File Descriptor - The unique descriptor identifier for the open Excel file. This ID is generated by the Open Excel or the Create Excel node.
- Column Name - The name of the new column. This is an optional input property. (e.g.
BorF) - Column Data - The data for the new column to be inserted. This should be a string array. (e.g.
["Boston","London","Miami"])
Output
- Excel File Descriptor - The unique descriptor identifier for the open Excel file.
Options
- Target - Select where to insert the column:
- Active Column - Inserts a new column in the active column.
- Specific Column - Inserts a new column at a position specified by the column name.
How It Works
- Validates Input: Checks that the file descriptor and target option are provided
- Verifies Target: Ensures a valid target option is selected
- Checks Column Input: If specific-column is selected, validates that a column name is provided
- Retrieves Handle: Gets the Excel file handle from the descriptor
- Parses Column Data: Reads the string array, one entry per row
- Determines Column: Based on target option, identifies where the new column goes:
- Active Column: Uses the column from the active cell
- Specific Column: Inserts at the named column
- Inserts Column: Adds the column and shifts existing columns to the right
- Writes Values: Fills the column top to bottom from the array
Requirements
- The Excel file must be opened with Open Excel or created with Create Excel
- A valid file descriptor must be provided
- When using specific-column target, a valid column name must be provided (e.g.
B) - When using active-column target, an active cell must be set
- Column Data must be a string array, not an object
- The file must be saved after insertion to persist changes
Error Handling
| Error Code | Description | Solution |
|---|---|---|
| Core.Excel.InsertColumn.ErrOnCreate | Configuration parsing failed | Check node configuration is valid |
| Core.Excel.InsertColumn.OnMessage | Message parsing failed | Verify input message format |
| Core.Excel.InsertColumn.ErrTarget | Target option is empty or invalid | Select a valid target option |
| Core.Excel.InsertColumn.ErrColumn | Column name is empty for specific-column | Provide a column name such as B |
| Core.Excel.InsertColumn.ErrFileDescriptor | File descriptor is empty or file not found | Ensure the file is opened/created before inserting a column |
| Core.Excel.InsertColumn.ErrInput | Column data is not a valid string array | Pass an array such as ["Boston","London"] |
| Core.Excel.InsertColumn.GetActiveCell | Active column cannot be found | Set the active cell before using active-column |
| Core.Excel.InsertColumn.ErrInsert | The insert operation failed | Verify the sheet is not protected and the column is in range |
Usage Examples
Example 1: Insert a Column at a Specific Position
Add a new column at B, shifting the existing B and beyond to the right:
- Open Excel (data.xlsx) -> fileDesc
- Insert Column:
- Excel File Descriptor: fileDesc
- Column Name: B
- Column Data: ["City","Boston","London","Miami"]
- Target: specific-column
- Save Excel (fileDesc)
- Close Excel (fileDesc)
Example 2: Insert an Empty Column
Create the column without filling it, ready to be written later:
- Open Excel (report.xlsx) -> fileDesc
- Insert Column:
- Excel File Descriptor: fileDesc
- Column Name: D
- Target: specific-column
- Save Excel (fileDesc)
- Close Excel (fileDesc)
Example 3: Insert at the Active Column
Insert where the active cell currently sits:
- Open Excel (inventory.xlsx) -> fileDesc
- Set Active Cell (fileDesc, "C1")
- Insert Column:
- Excel File Descriptor: fileDesc
- Column Data: ["Reorder level","10","25","5"]
- Target: active-column
- Save Excel (fileDesc)
- Close Excel (fileDesc)
Example 4: Add a Computed Column to a Report
Insert a column built earlier in the flow:
- Open Excel (sales.xlsx) -> fileDesc
- Get Column (fileDesc, "C") -> amounts
- Map (amounts -> withVat)
- Insert Column:
- Excel File Descriptor: fileDesc
- Column Name: D
- Column Data: withVat
- Target: specific-column
- Save Excel (fileDesc)
- Close Excel (fileDesc)
Usage Notes
- Insert Column adds a new column and shifts existing columns to the right
- Column names are letters (
A,B,AA), not numbers - The first entry of Column Data lands in row 1, so include the header as the first element when the sheet has one
- If Column Data is shorter than the sheet, the remaining cells are left empty
- Column Data must be a string array; a JSON object will raise
ErrInput - Formulas referencing shifted columns are not automatically updated
- When inserting several columns, work right to left so earlier positions do not move
- Remember to save the file to persist the changes
Tips
- Insert the column before writing to it rather than overwriting an existing one, so no data is lost
- Include the header as the first array element - it is easy to forget and shifts every value up by one row
- Use Get Column to read an existing column before building a derived one
- Check the sheet is not protected before inserting, or the operation raises
ErrInsert - Test on a copy of the file when automating inserts into a live workbook
Related Nodes
- Insert Row - Insert entire rows
- Delete Column - Remove columns
- Get Column - Read column data
- Set Active Cell - Set the active cell for active-column target
- Save Excel - Persist changes to disk