We are using aspose.cells to export records with a thumbnail in the first column. This works great for most of our clients but we have one client who wants to be able to center the images vertically (we have them at the top of the cell). I have tried unlocking the image, changing the format so it isn’t move and size, etc. etc. When you look at the picture format options, all the sizing and alignment options are grayed out. Tried using a macro to move it down in the cell but I get a 1004 error that you can’t change the top property.
I just upgraded to 21.9 so we are using the latest option. I would have attached the spreadsheet but it won’t let me upload an xlsx file.
Notice that we only get the rotate option if we click on the image.
Any ideas how to work around this?
image.png (25.5 KB)
You may please zip the template Excel file and upload here. If it’s size is larger, upload it to some public file sharing server and share the download link.
ProductDiscussionandSampling (1).zip (17.9 KB)
Here is a sample. The file usually has more columns but they are not important so I took it down to just a few columns.
I tried to unlock the pictures in your file in MS Excel manually, but could not do that. Please provide details on how to unlock the images so I could move to different location in the cell or in the sheet. By the way, how did you create such a file with locked images? Is it generated by some tool or utility or APIs, kindly elaborate?
Lol. That is exactly the problem! I created the spreadsheet using Aspose.Cells. But the images are locked and I can’t seem to unlock them in excel no matter what I try.
We set the image for move and resize and lock the aspect ratio. We then scale the thumbnail and center it horizontally but put it close to the top of the cell with a little spacing.
The problem is that after it is in excel, we can’t adjust that spacing or center the image vertically.
Could you please share your runnable sample code that can be compiled and executed here to reproduce this Excel file here. Also share an expected output file created by MS Excel for our reference.
AsposeCode.zip (3.6 KB)
We are creating these files out of our web application. I don’t have a standalone app. I am including examples from one of our pages that creates a spreadsheet. Most of them are pretty similar.
I am afraid that as this code is using DataView object from some external source/database etc. therefore it is not possible to run this code to generate the desired file. You are requested to simplify your code and provide us some runnable console application that can be compiled and executed here without any missing reference. This program should have required data in it so that the program could be executed as it is to observe the problem. Please note that reproducing the issue here is must required to provide further assistance.
After further evaluation of your provided code segment, I found the images in the sheet are locked due the following culprit lines:
Aspose.Cells.Drawing.Picture pic = sheet.Pictures[picId];
So, you got to unlock the pictures for Resize and Move attributes. Please try the following sample code using your template file, it will work as expected. It will unlock the pictures as per your requirements, so you may easily resize the pictures or move these to your specified location in the cells or sheet:
Workbook workbook = new Workbook("e:\\test2\\ProductDiscussionandSampling (1).xlsx");
Worksheet sheet = workbook.Worksheets;
foreach (Aspose.Cells.Drawing.Picture picture in sheet.Pictures)
Let us know if you still have any issue or confusion.
That was it! Thank you. I have no idea why we were locking the pictures that way before. Thanks for the help!
You are welcome and good to know that the suggested code segment works for your needs well. In the event of further queries or issue, feel free to write us back.