Subscribe to Excel cells modification.

The following example listens to changes in Excel cells. The setEventListener method is used to set event handler which will print A1 cell changes to console of Java application.

Example application will connect to running Excel, so, please start Microsoft Excel before trying example, and enter any data to cell A1.

try
{
    final DDEClientConversation conversation = new DDEClientConversation();

    conversation.setEventListener(new DDEClientEventListener()
    {
        public void onDisconnect()
        {
            System.out.println("onDisconnect()");
        }

        public void onItemChanged(String topic, String item, String data)
        {
            System.out.println("onItemChanged("+topic+","+item+","+data.trim()+")");
        }
    });

    conversation.connect("Excel", "Sheet1");
    try
    {
        conversation.startAdvice("R1C1");

        System.out.println("Press Enter to quit");
        System.in.read();

        conversation.stopAdvice("R1C1");
    }
    finally
    {
        conversation.disconnect();
    }
}
catch (DDEMLException e)
{
    System.out.println("DDEMLException: 0x" + Integer.toHexString(e.getErrorCode())
                       + " " + e.getMessage());
}
catch (DDEException e)
{
    System.out.println("DDEException: " + e.getMessage());
}

Download ExcelAdviceExample.java
Download all examples and binaries

Command line to run example:

java -cp .;pretty-tools-JDDE-2.1.0.jar ExcelAdviceExample