MS Word OLE自动化MoveUp在表中插入行后不起作用 [英] MS Word OLE automation MoveUp doesn't work after inserting rows in a table
问题描述
大家好!
我想首先感谢所有花时间查看此主题并尝试提供帮助的人。
我有一个带有表的Word文档,其格式如下:4列,40行。
在对话框中框我有一个列表视图,其中包含数据转到Word表格。
在下面的代码中,我检查项目数是否大于40,如果是,我添加(NumberOfItems) - 40个新行,使用方法InsertRowBelow。
然后我输入一些文本来测试东西,并在适当的位置键入文本 - 当前选择是最后添加的行。
然后我尝试向上移动并在最后一行之前的行中键入一些文本,但选择在最后插入的行下方移动28行,和类型文本。
如果我没有插入任何行,它就可以了。
我使用OLE和C ++自动化。
我用过的例子来自以下链接:
如何在MS WORD中将文本插入表格? [ ^ ]
我的问题是:
我添加新行后如何修复我的代码以升级到第一行
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 );
}
我使用纯WIN32 API在MS Visual Studio Express 2008,Windows XP,C ++中工作。
如果需要任何其他信息(源代码或类似的东西),请提出要求,我将非常乐意提供。
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.
推荐答案
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 );
这篇关于MS Word OLE自动化MoveUp在表中插入行后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!