We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Access Label Properties from OleObjectFrame

I have a presentation that has a Label (Forms.Label.1) embedded in it. I can get a reference to this object as an OleObjectFrame but I need to access the Caption property of the label. How would I do that? I can't directly cast the ObjectData property to Microsoft.Vbe.Interop.Forms.Label.

Thanks,

Dave

Dear Dave,

You need to look for an API, which does this conversion. I mean any function that accepts OLE object as an array of bytes and return the actual object for example, label in your case.

I think, you are using Office 2003 Interop Assemblies, I will let you know if I could find any. Please also attach me your sample ppt file, which does have your label as an OLE object and also let me know, how did you insert it?

If you happened to find it yourself, then please update me, how, in this thread.

You can add the label to a PPT by displaying the Control Toolbox menu bar (right-click on the menu bar and check the Control Toolbox item). Select a Label and draw it on the page. If you then right-click on the label and select Edit, you can change the contents of the label. This is what I want to do in code; change the Caption property of the Label.

I'm not sure what the Office 2003 PIAs have to do with this since they are not being used. I am using only Aspose.Slides to access the PPT file.

You cannot do it with Aspose.Slides, because Aspose.Slides does not know the inner contents of ole objects, for example, inner content can be an excel sheet, it could be ms graph or it can be lable or pdf document.

It just give you access of OLE object properties, like what is its class name, object type or the inner contents as OleObjectData.

To manipulate, the inner contents, you need to cast/convert the array of OleObjectData bytes to its actual object, as you have been trying to do so.

I thought, you are using PIA, because I saw it, when I googled the Microsoft.Vbe.Interop.Forms

Do you have any idea how I can do this?

Dear Dave,

I am able to change the label text with the new text using the following code. Please see the source and output presentation.

It will work for equal length text. You need to investigate, how you can make it work for variable length text.

CODE:

==================================================================

Presentation pres = new Presentation(@"c:\source.ppt");

int cnt = pres.Slides.Count;

int totalCount = pres.Slides.Count + pres.Masters.Count;

Slide sld = pres.GetSlideByPosition(1);

OleObjectFrame oof = sld.Shapes[0] as OleObjectFrame;

string str = BytesToString(oof.ObjectData);

str=str.Replace("This is some text.", "MMMMMMMMMMMMMMMMM.");

byte[] newBytes = StringToBytes(str);

oof.ObjectData = newBytes;

pres.Write(@"c:\output.ppt");

-------------------------------------------------------------------------------------------------

//Bytes to String

public static string BytesToString(byte[] bytes)

{

StringBuilder sb = new StringBuilder();

for (int i = 0; i < bytes.Length; i++)

{

char ch = (char)bytes[i];

sb.Append(ch);

}

return sb.ToString();

}

//String to Bytes

public static byte[] StringToBytes(string str)

{

byte[] bytes = new byte[str.Length];

for (int i = 0; i < bytes.Length; i++)

{

bytes[i] = (byte)(str[i]);

}

//byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);

return bytes;

}

==================================================================