We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Sizing pictures in XlsIO Excel spreadsheet

Thread ID:

Created:

Updated:

Platform:

Replies:

118598 Mar 23,2015 08:08 AM Mar 24,2015 01:00 PM WPF 2
loading
Tags: XlsIO
Jonny Shipton
Asked On March 23, 2015 08:08 AM

Hi there,

I am trying to insert an image into a worksheet and scale it so that the width of the image is the same as that of the cell.

var range = ws.Range[5, 2];
var pic = ws.Pictures.AddPicture(range.Row, range.Column, @"D:\Pictures\clouds.JPG");
int scale = (int)(range.ColumnWidth / pic.Width);
pic.Scale(scale, scale);

This results in a scale factor of 0, because as far as I can tell, the scale factors have to be integers and in percents. The use of integers for dimensions throughout the shapes functionality seemed a bit weird, but having integer scale factors is just bizarre.


Just to test it, I tried setting the picture width to the column width.

pic.Width = (int)range.ColumnWidth;
This is completely different when I open up the test file... See the attached image.

I can't say I have been very happy with the functionality for shapes in Excel so far, but if you could help it would be much appreciated :)

Attachment: excel_c7780a1.zip

Jonny Shipton
Replied On March 23, 2015 12:20 PM

I have managed to figure out the second issue with some help. The column width property is not in pixels, and can be converted to pixels with the IWorksheet.ColumnWidthToPixels function. :)

Dilli Babu Nandha Gopal [Syncfusion]
Replied On March 24, 2015 01:00 PM

Hi Jonny,

Thank you for using Syncfusion products.

Regarding Scale() query:

The Scale method of the IPictureShape is used to resize the image in scale width and scale height which is in percent. The below code snippet describes the implementation inside the Scale().

Code Snippet:

Width = ( int )( Width * scaleWidth / 100.0 );

Height = ( int )( Height * scaleHeight / 100.0 );

Here, the scaleWidth and scaleHeight should be in percent.

Regarding ColumnWidth/RowHeight query:

As you mentioned, for all the shape related dimensions, you must use the pixel value. The table describes the point and pixel values of the range for RowHeight and ColumnWidth.

Property in Points

Equivalent pixel values

range.ColumnWidth

worksheet.GetColumnWidthInPixels(range.Column)

range.RowHeight

worksheet.GetRowHeightInPixels(range.Row)

Please let us know if you have any concerns.

Regards,

Dilli babu.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;