当前位置: 代码迷 >> VBA >> VC在EXCEL中画出的图形怎么组合一起
  详细解决方案

VC在EXCEL中画出的图形怎么组合一起

热度:9494   发布时间:2013-02-26 00:00:00.0
VC在EXCEL中画出的图形如何组合一起
VC调用excel,在其中画一个圆和两条线,如何实现将这3个图形组合一起的功能.
(excel中可以选中这3个图形右键菜单:组合->组合)
在excel中实现的vba代码如下:
ActiveSheet.Shapes.Range(Array("Oval 1", "Line 2", "Line 3")).Select
Selection.ShapeRange.Group.Select

在MSDN上查到如下帮助
http://msdn.microsoft.com/zh-cn/library/microsoft.office.interop.excel.shapes(v=office.11).aspx

Use Shapes.Range(index), where index is the shape’s name or index number or an array of shape names or index numbers, to return a ShapeRange collection that represents a subset of the Shapes collection.


但是,这里提到的数组不知如何用,尝试用如下代码可以编译,但是运行时出错.应该明显有问题.
shape=shapes->AddShape(msoShapeOval,BLeft,BTop,Width,Height);
shapeName1=shape->Name.GetBSTR();
shape=shapes->AddLine(BLeft+1.5,BTop+1.5,BLeft+6.5,BTop+6.5);
shapeName2=shape->Name.GetBSTR();
shape=shapes->AddLine(BLeft+1.5,BTop+6.5,BLeft+6.5,BTop+1.5);
shapeName3=shape->Name.GetBSTR();
//实现将图形组合
CString aa[3];
aa[0]=shapeName1;
aa[1]=shapeName2;
aa[2]=shapeName3;
pThisWorksheet->Shapes->Range[aa]->Select();//此处执行时有问题
//pThisWorksheet->GetShapes()->GetRange(aa)->Select();
//shape->GroupItems;//不知组合是否此句实现

谁有做过类似效果,请不吝赐教.多谢

------解决方案--------------------------------------------------------
以下代码测试通过
参考http://social.msdn.microsoft.com/forums/en-us/vclanguage/thread/3035CFD1-7989-4CB8-B987-B6F574B3DDA3
C/C++ code
Function f(d)For Each c In Range(Replace(d, "-", ":"&left(d,3))).Rowsf = f & " " & c.RowNextf = Mid(f, 2)End Function
  相关解决方案