Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Word OLE
Hello everyone!

I would like to start by saying thanks to everyone who takes some time to view this thread and try to help.
 
I have a Word document with a table, which has following format: 4 columns, 40 rows.
 
In a dialog box I have a listview that has data which goes to Word table.
 
In the code bellow, I check if number of items is greater than 40, and if is, I add ( NumberOfItems ) - 40 new rows, using method InsertRowBelow.
 
Then I type some text to test things, and it types text at proper place - current selection is the last added row.
 
Then I try to move up and type some text in the row before the last one, but selection moves 28 lines below the last inserted row, and types text.
 
If I don't insert any rows, it works OK.
 
I work with OLE and C++ automation.
 
I have used examples from these links:
 
How to insert text into tables in MS WORD ?[^]
 
My question is:
 
How can I fix my code to move up to the first row, after I have added new rows
 
{
		// move from header to first row
					
		hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"MoveDown", 0 );
 
		// if there are more then 40 items in listview add rows

		if( ListView_GetItemCount( GetDlgItem( hwnd, IDC_LIST1 ) ) > 40 )
			for( int i = 0; i < 
				(int)( ListView_GetItemCount( GetDlgItem( hwnd, IDC_LIST1 ) ) - 40 );
				i++ )
			{
				hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"InsertRowsBelow", 0 );
 
			}
 
		// this is test stuff

		VARIANT xx;
		xx.vt = VT_BSTR;
		xx.bstrVal = ::SysAllocString(L"rows");
 
		hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"TypeText", 1, xx );
 
		hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"MoveUp", 0 );
 
		VARIANT x;
		x.vt = VT_BSTR;
		x.bstrVal = ::SysAllocString(L"TEST");
 
		hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"TypeText", 1, x );
 
	}
I work in MS Visual Studio Express 2008, on Windows XP, in C++, using pure WIN32 API.
 
If any other information is required ( source code or something similar ), please ask for it, I will more than gladly supply it.
Posted 8-Jul-13 22:52pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

VARIANT wdCell, Count;
				
wdCell.vt = VT_I4;
wdCell.lVal = 12;
			
Count.vt = VT_I4;
Count.lVal = (int)( 4 * ( ListView_GetItemCount( GetDlgItem( hwnd, IDC_LIST1 ) ) - 40 )  + 1 );
 
hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"MoveLeft", 2, Count, wdCell );
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 565
1 Maciej Los 319
2 Richard MacCutchan 220
3 BillWoodruff 164
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 15 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100