Picture.right does not work

I’m using the following example:

Excel excel = new Excel();
Worksheet sheet = excel.Worksheets[0];
FileStream fs = new FileStream(“c:\tmp\gifpos\logo.gif”, FileMode.Open, FileAccess.Read);
int pos = sheet.Pictures.Add(0, 0, fs);
Picture pic = sheet.Pictures[pos];
pic.Right= 5;

sheet.Cells[“a1”].PutValue(123);

sheet.Cells[“a1”].Style.HorizontalAlignment = TextAlignmentType.Right;
sheet.Cells[“a1”].Style.IndentLevel = 2;

The image will not align itself to the right side of the cell. Am I doing something wrong?

I could use pic.Left = getColumnWidth(Convert.toByte(0))-5 but the width of the column may be changed later if a wider cell is appended.

I am using version 2.9.0.1

Picture.Right property is just a placeholder and not supported yet. We will implement it in the following releases. You will get it within 1-2 weeks.

Can you please be more specific about the date? We have 18-19000 people depending on our delivery of this feature. We can not ship the product before the Picture.right functionality is working as described in your documentation.

I will speed up to implement this feature. The planned date is the end of this week. Will it serve your need?

If the end of this week is Friday, it will serve our needs just fine.

Thank you for speedy reply.

Now it’s available. Please download v2.9.1

and have a try.

I’ve tested it and it seems to work, except that now the Picture.Top is disregarded instead. Can you please take a look at that?

Another request: Is it possible to ‘stick’ the picture to the right side of the cell? If the user decides to make the column wider, the picture does not follow as it is. Is there a feature that I am missing?

I will check this “Top” issue. And I will add a property to enable you to lock the image.

Please download and try v2.9.2 at Downloads section. Picture.Top issue is fixed. And you can try to use Picture.Placement property to stick the picture.

The Picture.Placement = PlacementType.Move does not stick the picture to the right side of the cell. Am I using it wrong?

Excel excel = new Excel();
Worksheet sheet = excel.Worksheets[0];
FileStream fs = new FileStream("c:\\tmp\\gifpos\\logo.gif", FileMode.Open, FileAccess.Read);
int pos = sheet.Pictures.Add(0, 0, fs);
Picture pic = sheet.Pictures[pos];
pic.Right= 5;
pic.Placement = PlacementType.Move;
sheet.Cells["a1"].PutValue(123);
sheet.Cells["a1"].Style.HorizontalAlignment = TextAlignmentType.Right;
sheet.Cells["a1"].Style.IndentLevel = 2;

PlacementType.Move sticks the image to the left side of the cell. That’s the routine of MS Excel. I haven’t found such a feature in MS Excel to stick an image to the right side of the cell. So I don’t have an idea to do it in Aspose.Excel.

Is it possible to lock the columnwidth so the user can not change it? That way we can make sure the images stay on the right side.

You need protect the worksheet to lock the column width. Please try to lock the worksheet in your designer file or use Worksheet.Protect method.

All right.

Thank you very much for the speedy solutions.

@dpouls1,
Aspose.Cells has replaced Aspose.Excel and contains advanced features to work with pictures in MS Excel files. It supports following features for working with pictures:

  • Add picture at location of a cell whose indices are known
  • Position picture proportional to row height and column width
  • Place picture at an absolution position
  • Insert picture based on cell’s reference

Here is an example that can be used to place picture at an absolute position.

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Adding a new worksheet to the Workbook object
int sheetIndex = workbook.Worksheets.Add();

// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];

// Adding a picture at the location of a cell whose row and column indices
// Are 5 in the worksheet. It is "F6" cell
int pictureIndex = worksheet.Pictures.Add(5, 5, dataDir + "logo.jpg");

// Accessing the newly added picture
Aspose.Cells.Drawing.Picture picture = worksheet.Pictures[pictureIndex];

// Absolute positioning of the picture in unit of pixels
picture.Left = 60;
picture.Top = 10;

// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls");

For more details about working with pictures, follow the link below:
Managing Pictures

Get a free trial version to test different features of this product:
Aspose.Cells for .NET (Latest Version)

Here you will get a runnable solution that can be used to test a variety of features of this product without writing any code.