Managing Pictures
Aspose.Cells for Python via .NET allows developers to add pictures to spreadsheets at runtime. Moreover, the positioning of these pictures can be controlled at runtime, which is discussed in more detail in the coming sections.
This article explains how to add pictures, and how to insert an image that shows the content of certain cells.
Adding Pictures
Adding pictures to a spreadsheet is very easy. It only takes a few lines of code: Simply call the add method of the pictures collection (encapsulated in the Worksheet object). The add method takes the following parameters:
- Upper left row index, the index of the upper left row.
- Upper left column index, the index of the upper left column.
- Image file name, the name of the image file, complete with path.
Positioning Pictures
There are two possible ways to control the positioning of pictures using Aspose.Cells for Python via .NET:
- Proportional positioning: define a position proportional to the row height and width.
- Absolute positioning: define the exact position on the page where the image will be inserted, for example, 40 pixels to the left and 20pixels below the edge of the cell.
Proportional Positioning
Developers can position the pictures proportional to row height and column width using the upper_delta_x and upper_delta_y properties of the Aspose.Cells.Drawing.Picture object. A Picture object can be obtained from the pictures collection by passing its picture index. This example places an image in the F6 cell.
Absolute Positioning
Developers can also position the pictures absolutely by using the left and top properties of the Picture object. This example places an image in cell F6, 60 pixels from the left and 10 pixels from the top of the cell.
Inserting a Picture Based on Cell Reference
Aspose.Cells for Python via .NET lets you display the contents of a worksheet cell in an image shape. You can link the picture to the cell that contains the data that you want to display. Since the cell, or cell range, is linked to the graphic object, changes that you make to the data in that cell or cell range automatically appear in the graphic object.
Add a picture to the worksheet by calling the add_picture method of the ShapeCollection collection (encapsulated in the Worksheet object). Specify the cell range by using the formula attribute of the Picture object.