ActiveXComponent xl = new ActiveXComponent("Outlook.Application"); Dispatch explorer = Dispatch.get(xl,"ActiveExplorer").toDispatch(); Dispatch selection = Dispatch.get(explorer, "Selection").toDispatch(); Variant count = Dispatch.get(selection, "Count"); // loop over selected mail items. for (int mailIndex = 1; mailIndex <= count.getInt(); mailIndex++ ) { Dispatch mailItem = Dispatch.call(selection, "Item", new Variant(mailIndex)).toDispatch(); Variant subject = Dispatch.get(mailItem, "Subject"); // .... and so on }
OleAutomation active = activeDocument.getAutomation(); if(active!=null){ int[] paragraphsId = getId(active, "Paragraphs"); if(paragraphsId.length > 0) { Variant vParagraphs = active.getProperty(paragraphsId[0]); if(vParagraphs != null){ OleAutomation paragraphs = vParagraphs.getAutomation(); if(paragraphs!=null){ int[] countId = getId(paragraphs, "Count"); if(countId.length > 0) { Variant count = paragraphs.getProperty(countId[0]); if(count!=null){ int numberOfParagraphs = count.getInt(); for(int i = 1 ; i <= numberOfParagraphs ; i++) { Variant paragraph = paragraphs.invoke(0, new Variant[]{new Variant(i)}); if(paragraph!=null){ System.out.println("paragraph " + i + " added to list!"); listOfParagraphs.add(paragraph); } } return listOfParagraphs; } } } } }
int idAddIns = application.getIDsOfNames(new String[] {"COMAddIns"})[0]; Variant addInsVar = application.getProperty(idAddIns); OleAutomation addIns = addInsVar.getAutomation(); int countID = addIns.getIDsOfNames(new String[] {"Count"})[0]; Variant countVariant = addIns.getProperty(countID); int addInsItemID = addIns.getIDsOfNames(new String[] {"Item"})[0]; for (int i = 1; i <= countVariant.getInt(); i++) { Variant addInsItemVariant = addIns.invoke(addInsItemID, new Variant[] {new Variant(i)}); OleAutomation addInsItem = addInsItemVariant.getAutomation(); int addInsItemConnectID = addInsItem.getIDsOfNames(new String[] { "Connect" })[0]; if (addInsItem.getProperty(addInsItemConnectID).getBoolean()) { int addInsItemNameID = addInsItem.getIDsOfNames(new String[] { "ProgId" })[0]; Variant addInsItemNameVariant = addInsItem.getProperty(addInsItemNameID); String name = addInsItemNameVariant.getString(); addInsItem.setProperty(addInsItemConnectID, new Variant(false)); } }