24
Access to Excel within Your Own Indicator
A simple example showing how you can access data directly from your Excel.
Indicator
This example indicator is written in Delphi script. You can easily copy the code and use that in your Delphi IDL indicators.
Download ReadExcelSingleCell
Using the Indicator
In the chart, I have applied the indicator twice, one to read the cell A1 and the other to read the cell A2.
Within Excel, You can see clearly what value I have entered into the worksheet,
Coding Technique
When using the Excel OLE automation objects, there are several important rules that you have to follow.
1. Always use try exception
blocks around Excel OLE calls. If Excel is not installed on the computer, or, for some reason, Excel rejects your calls, exceptions will be raised. Your indicator must handle that properly.
2. Most of the time, users prefer opening their Excel manually. The workflow goes from opening their workbooks first, entering or adjusting the values within Excel, before using them in NeoTicker. The example use the GetActiveOleObject
function to gain access to the opened Excel instance. If your intention is to access a new instance of Excel, or completely automate the process including opening the workbooks, etc. then you need to use the CreateOleObject
function instead.
3. The example indicator read the Excel cell value only once. If your interest is to access the Excel values in real-time, then you need to implement the Excel calls outside of the firstcall
block.
4. Workbook names are referenced without the path if it is already opened in the existing Excel instance. If you are going to open a workbook within your code, then you need the complete path.