word ole 文字上下标 问题
我在往WORD里面送文字\图片无可以实现了.但现在是送文字的上标.在一般的地方可以
如下列代码
try
{
vWordApp = Variant::CreateObject( "Word.Application ");
}
catch(...)
{
MessageBox(0, "启动 Word 出错, 可能是没有安装Word. ",
"Print2Doc ", MB_OK | MB_ICONERROR);
vWordApp = Unassigned;
return;
}
// 隐藏/显示Word界面
vWordApp.OlePropertySet( "Visible ",true);
// 新建一个文档,从模板中
vWordApp.OlePropertyGet( "Documents ").OleFunction( "Add ", "d:\\证书.dot ");
Variant vSelect = vWordApp.OlePropertyGet( "Selection ");
vSelect.OleFunction( "TypeText ", "U ");
vSelect.OlePropertyGet( "Font ").OlePropertySet( "Subscript ",true);
vSelect.OleFunction( "TypeText ", "rel ");
vSelect.OlePropertyGet( "Font ").OlePropertySet( "Subscript ",false);
vSelect.OleFunction( "TypeText ", "=0.28% ");
效果 U <下标> rel </下标> =0.28%
这样子没有问题.但现在是我往表中的一个CELL里面放.如何控制,可以写进去.但上下标?
void __fastcall TForm1::InsertTableCellText(Variant &vTable, int nTableIndex ,int nCellx,int nCelly,String abc)
{
vTable= vWordApp.OlePropertyGet( "ActiveDocument ").OlePropertyGet( "Tables ").OleFunction( "item ",nTableIndex);
vTable.OleFunction( "Cell ",nCellx,nCelly).OlePropertyGet( "Range ").OlePropertyGet( "Font ").OlePropertySet( "Superscript ",true); //这样一来,表中的所有字体全变了上标了
vTable.OleFunction( "Cell ",nCellx,nCelly).OlePropertyGet( "Range ").OlePropertySet( "text ",abc.c_str()); //写入字符
vTable.OleFunction( "Cell ",nCellx,nCelly).OlePropertyGet( "Range ").OleFunction( "InsertAfter ", ",在刚才字符基础上再追加字符 ");
如何在表格中实现以上效果呢
效果 U <下标> rel </下标> =0.28%
[解决办法]
TVariant vTemp00,vTemp01;
long lend = tbl-> Cell(rows,2)-> Range-> get_End();
long lstart = leng-1;
vTemp00 = lstart;
vTemp01 = lend;
RangePtr subRange = wd-> Range(&vTemp00, &vTemp01);