Free Support Forum - aspose.com

Image distortion caused by SetColumnWidth

I have a logo image in the top left corner of the designer spreadsheet. The image is in Cell A1, but it spills over into the range A1…C3. Under certain conditions, I need to set the width of column B to zero (hidden). When I do this, it distorts the logo.

Does anyone have a work-around?

I am using Excel 2002. In the “format picture” dialog in on the “properties” tab, there are 3 radio buttons:

Object Positioning:
() Move and Size with Cells
() Move but Don’t Size with Cells
() Don’t Move or Size with Cells

Regardless of which setting is chosen, an API call the Cells.SetColumnWidth() will use the first option “Move and Size with Cells”.




Hi, thanks for your consideration.

I create a designer file contained a picture and set the option to
() Don’t Move or Size with Cells

Then I using the following code:

Excel excel = new Excel();
excel.Open(“d:\book1.xls”);
Cells cells = excel.Worksheets[0].Cells;
cells.SetColumnWidth(1, 0);
excel.Save(“abc.xls”, SaveType.OpenInExcel, FileFormatType.Default, this.Response);

The result option is still "Don’t Move or Size with Cells ".

What’s your Apose.Excel’s version? Please download the newest fix.

And you can try to save your designer file as Excel200 file.

If the problem still exists, please mail me your designer file.

I couldn’t get version 1.5.8 to work. I am using 1.5.7.0
(Parser Error Message: The check of the signature failed for assembly ‘Aspose.Excel’)

I saved the excel designer file as type:
"Microsoft Excel 97-2002 & 5.0/95 Workbook (*.xls)"

I don’t think I was clear before.


I create a designer file contained a picture and set the option to
() Don’t Move or Size with Cells

Process it using your code

The result option is still "Don’t Move or Size with Cells ". BUT THE IMAGE IS DISTORTED.

So Aspose.Excel is NOT changing the setting, it is just ignoring it.

The image is positioned in the worksheet by a top left cell, a bottom right cell, and 2 values for lowerdeltaX and lowerdeltaY. When you resize a cell, an image overlapping that cell remains anchored in the same bottom right cell, and the image is distorted.

I found a work-around by using the API: I am using excel.Worksheets(0).Pictures.Add, to add the image AFTER I resize the column.

It works pretty good, but I have to scale the image to 100%. This reduces the quality of reports when printed. As you may know, a larger image shrunken to 50% in Excel will print better than a smaller imager shrunken to 50% in Photoshop and then inserted into Excel at 100%. It’s something to do with printer resolution being higher than screen resolution. Excel.Worksheets(0).Pictures.Add inserts the image at 100% size. There is no option to use a different scaling factor.

It would be nice if either

A. There was an option when adding an image to set a scaling factor OR

B. SetColumnWidth was aware of any pictures that overlap the column being resized, and automatically adjusted the bottom right cell position and lowerdeltaX/lowerDeltaY to undo any image distortion.

Mike Olund
OpenRoad Communications


Dear Mike,


I couldn’t get version 1.5.8 to work. I am using 1.5.7.0
(Parser Error Message: The check of the signature failed for assembly ‘Aspose.Excel’)


This issue is produced by inappropriate signature of Aspose.Excel.dll after it is obfuscated by Aspose.Obfuscator.

This weekend or early next week we will publish a hot fix in this forum. Please keep an eye on it.

Please accept my personal apology for any inconvenience you have experienced.

Soon Laurence will reply the rest of your post.

Dear Mike,

Yes. I found the distort problem. I will solve it as soon as possible.

Your requirements are:
A. There was an option when adding an image to set a scaling factor OR

B. SetColumnWidth was aware of any pictures that overlap the column being resized, and automatically adjusted the bottom right cell position and lowerdeltaX/lowerDeltaY to undo any image distortion.

I will implement A at first and try to implement B later.

Dear Mike,

The hotfix, 1.5.8 has been updated. The signature issue has been resolved.

Dear Mike,

Please download Hot Fix 1.5.9.

A new method is added:

Pictures.Add

///


/// Adds a picture to the collection.
///

/// Upper left row index.
/// Upper left column index.
/// Image filename.
/// Scale of image width, a percentage.
/// Scale of image width, a percentage.
/// object index.
public int Add(int upperLeftRow, int upperLeftColumn, string fileName, int widthScale, int heightScale)

For example, if you want to add an image with 50% width and 50% height, you can use the following code:

Pictures pics = excel.Worksheets[0].Pictures;
pics.Add(0, 0, “d:\pic.jpg”, 50, 50);