ajWriteWorkbook function
Description
The ajWriteWorkbook function exports data from a range of cells in an Excel worksheet to another Excel file.
Syntax
ajWriteWorkbook(data_range, target_workbook_path, start_address, [convert_to_text], [run_condition], [run_by_function_point_only])
Argument Name | Argument Type | Description |
---|---|---|
data_range (required) | Range | The range of cells to be written into the file. The range of cells can span across multiple rows and columns. It must be a range in the current workbook. |
target_workbook_path (required) | String | The path of the Excel file to be written. The function will create an Excel file automatically if the specified file path does not exist. Ensure that the current user has privilege to add/update files in the specified path. Remark: The function only supports the target workbook in xlsx and xlsm format and it cannot not be the same as the current workbook. |
start_address (required) | String | The top-left cell of the range to write in the target workbook in the [sheet]!cell_address format. For example, "sheet1!A2". The function will check the range size in data_range to determine the actual range in the target workbook. |
convert_to_text (optional) | Boolean | If it equals TRUE, the return result will be converted to string values. If it equals FALSE, the return result will preserve the original data type of each cell. The default value is FALSE. |
run_condition (optional) | Boolean | The function will run when the value is TRUE. Otherwise will not run. The default value is TRUE. |
run_by_function_point_only (optional) | Boolean | If it equals FALSE, the function can be executed through ‘Excel Calculation’ (can be either Automatic or Manual, Calculate Now or Calculate Sheet) or Preview Function Point. If it equals TRUE, the function can be executed with Preview Function Point (AlchemyJ ribbon / Preview Function Point) only. The default value is TRUE. |
The function will return:
1) Return Value: TRUE / #VALUE!
2) Return Type: Single Value
Example
This example will export data from cell B1 to cell F6 to a separate Excel workbook.
A new excel file WriteWB.xlsx is created in the specified path. In the below screenshot, you can see the data is copied from the original Excel to the target Excel. Please note that the format in the AlchemyJ Workbook will not be exported to the new Workbook.
Click here to download the use case workbooks for further reference.
Error Scenarios
It will return #VALUE! when missing any required parameter or mismatch parameter type. Besides, system will raise error for below scenario(s).
Error Scenario |
---|
Target workbook path is not a xlsx file or a xlsm file. |
Invalid start address, it should be in [sheet name]![cell address] format. For example, sheet1!A2. |
Failed to write workbook. |
Target workbook is current workbook. |