在功率点图片更换使用C# [英] Replacing images in power point using c#
问题描述
在PowerPoint中我已经把一些图图,其中每个图包含不同guid.And我已经设置了GUID作为他们的超链接。被点击刷新按钮,我做的是什么,会发现形状,然后将得到我所保存为超链接为每个图像的GUID,从每个图像,并使用GUID将在该形状的旧形象取代最近的图像
In in powerpoint i have placed some diagrams diagrams, where each diagram contains different guid.And i have set the GUID as their hyperlink. when the refresh button is clicked what i do is ,will find the shape and then will get the guid which i have saved as hyperlink for each image , from each image and using that GUID will replace the recent image with the old image in that shape.
foreach (var shape in presentation.Slides[slideno].Shapes)
{
var slide = (PPT.Slide)item;
if (j <= shapeCount)
{
string[] address = new string[] { };
string dskj = slide.Shapes[j].Name;
if (slide.Shapes[j].Name.Equals("DIAGRAM")//, StringComparison.InvariantCultureIgnoreCase)
&& slide.Shapes[j].ActionSettings[PPT.PpMouseActivation.ppMouseClick].Hyperlink.Address != null)
{
address = slide.Shapes[j].ActionSettings[PPT.PpMouseActivation.ppMouseClick].Hyperlink.Address.Split('*');
string Type = address[0];
string Guid = address[1];
if (Type == "D")
{
Session.path = presentation.Path;
if (Session.path != "")
Session.Repository.GetProjectInterface().PutDiagramImageToFile(address[1], Session.path + "\\" + address[1] + ".jpg", 1);
bool diagrm = false;
try
{
EA.Diagram diag = Session.Repository.GetDiagramByGuid(Guid);
diagrm = true;
}
catch
{
continue;
}
if (diagrm)
{
float Shapeleft = slide.Shapes[j].Left;
float Shapetop = slide.Shapes[j].Top;
float Shapewidth = slide.Shapes[j].Width;
float Shapeheight = slide.Shapes[j].Height;
slide.Shapes[j].Delete();
PPT.Shape pic = slide.Shapes.AddPicture(Session.path + "\\" + Guid + ".jpg", Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, Shapeleft, Shapetop, Shapewidth, Shapeheight);
pic.Name = "DIAGRAM";
pic.ActionSettings[PPT.PpMouseActivation.ppMouseClick].Hyperlink.Address = "D*" + Guid;
}
}
}
}
使用这个上面code一切都很正常。
using this above code everything works great.
address = slide.Shapes[j].ActionSettings[PPT.PpMouseActivation.ppMouseClick].Hyperlink.Address
在地址我将得到当前图像的超链接的地址,但现在我的问题是,如果我在同一单个幻灯片有两个图像,则两个当它循环形状内部时它仅给出了相同的超链接两个图像。
in address i will get the hyperlink address of that current image,but now my problem is if i have two images in a same single slide , then both the time when it loops inside the shapes it only gives the same hyperlink for both the images.
**注意:**如果我在幻灯片中只有一个图像,然后一切工作正常。
**NOTE:**If i have only one image in a slide then everything works properly.
推荐答案
它,因为你删除previous形状和插在同一个地方一个新的形状,但每个形状包含在那里,因为你ZOrderPosition,删除的previous并插入一个新的形状的Zorderposition得到改变为新的形状,如果一个以上的图像中插入一个形状它只refrsh某些图像将被包括在下一个iteration.So。
SOLUTION
Its because you're deleting the previous shape and inserting a new shape at the same place , but each shape contains a ZOrderPosition , where because of you deleted the previous and inserted a new shape the Zorderposition get changed for the new shape and it will be included in the next iteration.So if more than one image is inserted in a shape it only refrsh some images . SOLUTION:
删除后现有的并插入一个新的形状设置其ZorderPosition还当。
After deleting the existing and when inserting a new shape set its ZorderPosition also.
pic.ZOrder(MsoZOrderCmd.msoSendToBack);
希望工程.. !!
Hope it works..!!
这篇关于在功率点图片更换使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!