Change picture of Image Control by code

Hi,


Is it possible to change the picture of an Image Control (ActiveX) by code ?

I have added an ActiveX Image Control to my worksheet. I reach this picture like this :

Picture pic = worksheet.Pictures[0];

And i try to change the picture like this :

pic.Data = img; (it is a byte array)

But it doesn’t work :confused:

Can you help me please ?


Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Probably, this feature needs to implemented for ActiveX control pictures. However, please try the following code using the latest version:
Aspose.Cells for .NET (Latest Version)
and let us know your run results.

If your issue still occurs, then please provide us your sample source workbook of which ActiveX picture you want to modify using the code.

We will look into it and help you asap.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;

string imgPath = @“D:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.Worksheets[0];


byte[] picData = File.ReadAllBytes(imgPath);


Picture pic = worksheet.Pictures[0];

pic.Data = picData;


pic.UpdateSelectedValue();


workbook.Save(filePath + “.out.xlsx”);

I have created a new Console Project to test your solution but it still doesn’t work.
The Excel Workbook that i have used contains only an empty ActiveX Image Control

Hi,

Thanks for your input and providing us sample file.

We have investigated this issue and found, it is a New Feature Request.

We have logged this issue in our database. We will look into this issue and implement it if possible.

Once, the feature is implemented or we have some other update for you, we will let you know asap by posting on this thread.

This issue has been logged as CELLSNET-41218.

Thanks,

I have another question. How to delete an ActiveX Image Control by code ?

If i add an ActiveX Image Control to my Excel worksheet, it is added to the Pictures collection of the Worksheet object. But, if i call Pictures.RemoveAt(), the ActiveX Image Control is not deleted from my sheet.Although, it is removed from the collection.

I’ve also tried with standard image control but i have’nt encountered this problem

Hi,

I have tested your case (deleting the activex picture by Pictures.RemoveAt() method) using the latest fix/ version:Aspose.Cells for .NET (Latest Version) and it works fine. The picture is removed in the sheet. I have used your template file “source.xlsx” to test the case. Here is my sample code:

Sample code:

string filePath = @“e:\test2\source.xlsx”;

Workbook workbook = new Workbook(filePath);

Worksheet worksheet = workbook.Worksheets[0];

worksheet.Pictures.RemoveAt(0);

workbook.Save(filePath + “.out.xlsx”);

Please try our latest fix (as shared by Shakeel Faiz) i.e. v7.3.4.1 and let us know your result.

Thank you.

Hi,

We have fixed this issue.

Please download and try this fix: Aspose.Cells for .NET (Latest Version) and let us know your feedback.

Hi,


I have tested your solution with this code :

Picture pic = worksheet.Pictures[i];
pic.Data = imgByteArray;
pic.UpdateSelectedValue();
workbook.Save(…);

The image changes correctly but a security alert appear :
"Content has been disabled…"

When i click on button “Activate content”, the image disappears :confused:

Thanks in advance,
Kevin

Hi,

Thanks for your feedback.

In order to investigate this issue further at our end, please provide us your complete code and the source and output files. Also, screenshot highlighting the issue with red circles will help us greatly.

We will look into your issue soon and reopen this issue.

I have created a console application.


Can you try this ?

Kevin

Hi,

Thanks for your console application.

We were able to replicate this issue. Please see the following screenshot for your reference.

We have reopened this issue. Once the issue is fixed or we have some other update for you, we will let you know asap.

Screenshot:

Kevin.Coulon:
I have created a console application.

Can you try this ?

Kevin
Hi,

After closely looking into this issue, we think MS Excel must store another image for vba shape in the vba project.

Though we directly replace the image in the media directory of xlsm file, the old image displays again when we enable ActiveX in MS Excel.

So we could not support this feature now as we do not support parsing VBA project now.