Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Merging cells in a Word table through OleAutomation
Merging cells in a Word table through OleAutomation [message #1060372] Fri, 24 May 2013 10:35
Binko Binev is currently offline Binko BinevFriend
Messages: 20
Registered: June 2012
Junior Member
Hi all,

I have the following problem:

I use OleAutomation for generating reports. For this purpose some cells in tables are merged together. The report is produced as it should look.

But when I merge cells, the WinWord.exe process remains after the client site is closed. If I comment the merge line , the WinWord.exe process is closed as it should.

I have disposed all OleAutomations and Variants in my java code. But as it seems there is some internal stuff in the dll that does not remove the pointers created internally in the dll.

Here is the method I use to merge cells - it is a little bit bloated, as I have tried out different solution attempts:

	 * Merges the range from cell1 in upper left corner to cell2 in lower right corner
	 * @param cell1Var - Variant of cell1
	 * @param cell2Var - Variant of cell2
	 * @return
	 * @throws Exception
	public static Variant mergeCells(Variant cell1Var, Variant cell2Var) throws Exception {
		Variant mergeCellsVar = null;
		Variant cell1RangeVar = OleWordTableCell.getRange(cell1Var);
		if (cell1RangeVar == null){
			return null;
		int cell1RangeStart = OleWordRange.getStart(cell1RangeVar);
		Variant cell2RangeVar = OleWordTableCell.getRange(cell2Var);
		int cell2RangeEnd = OleWordRange.getEnd(cell2RangeVar);
		OleAutomation cell1Auto = cell1Var.getAutomation();
		Variant documentVar = cell1Auto.getProperty(1002/*Parent*/);
		Variant cellsToMergeRangeVar = OleWordDocument.setRange(documentVar,cell1RangeStart,cell2RangeEnd);
		OleAutomation cellsToMergeRangeAuto = cellsToMergeRangeVar.getAutomation();
		Variant selectionVar =;
		Variant selectionCellsVar = OleWordSelection.getCells(selectionVar);
		OleAutomation cellsToMergeAuto = selectionCellsVar.getAutomation();
		int cellsToMergeCount = cellsToMergeAuto.getProperty(2/*Count*/).getInt();
		if (cellsToMergeCount > 1){
				[color=blue][/color]mergeCellsVar = cellsToMergeAuto.invoke(204/*Merge*/);
			catch(Exception e){
				throw e;
//		else if (cellsToMergeCount == 1){
//			// get item
//			Variant cellVar = cellsToMergeAuto.invoke(0, new Variant[]{new Variant(1)});
//			OleAutomation cellAuto = cellVar.getAutomation();
//			int rowIndex = cellAuto.getProperty(4).getInt();
//			int colIndex = cellAuto.getProperty(5).getInt();
//			cellAuto.setProperty(110/*FitText*/, new Variant[]{new Variant(true)});
//			System.out.println("row: " + rowIndex + ",col: " + colIndex);
//			return null;
//		}
//		else{
//			return null;
//		}
		return mergeCellsVar;

The problem code line is in blue. If it is commented out, the process closes, but cells are not merged.
If it is left, the cells are merged, but the process is not closed.

I want that both the cells are merged and the process is closed.

[Updated on: Fri, 24 May 2013 12:48]

Report message to a moderator

Previous Topic:Detecting keys while showing a context menu
Next Topic:How to keep Popup-menu open after selection event?
Goto Forum:

Current Time: Fri Aug 18 18:52:56 GMT 2017

Powered by FUDForum. Page generated in 0.01614 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software