Document Solutions for Excel, .NET Edition | Document Solutions
Features / Shapes and Pictures / Linked Picture
In This Topic
    Linked Picture
    In This Topic

    Linked Picture, also known as Camera shape or picture, refers to a real-time dynamic snapshot of the copied range. That is, as values in the copied cell range change, the same is automatically reflected in its snapshot as well. In Microsoft Excel, this feature is provided through Special Paste option named "Linked Picture". This feature is especially useful in case of dashboards and reports as you can display dynamically changing images and can even resize them according to the available space.

    DsExcel allows you to create these dynamic linked pictures through AddCameraPicture method of the IShapes interface. This method accepts the source range of the linked picture and position coordinates of the target range with respect to the document as parameters. You can also specify the cell range where you want to add the linked picture using another overload of this method. As the linked picture is also just another picture, it can be resized and formatted similar to any other picture.

    C#
    Copy Code
    Workbook workbook = new Workbook();
    workbook.ActiveSheet.Range["A1"].Interior.Color = Color.Blue;
    workbook.ActiveSheet.Range["B5"].Interior.Color = Color.Yellow;
    //Add linked picture at a specific position(coordinates)
    IShape shape = workbook.ActiveSheet.Shapes.AddCameraPicture("=$A$1:$B$4", 100, 100);
    
    //Add linked picture at a specific cell range
    //IShape shapeRange = workbook.ActiveSheet.Shapes.AddCameraPicture("=$A$1:$B$5", worksheet.Range["G1:H5"]);
    
    workbook.Save("LinkedPicture.xlsx");
    Note: The targetRange and the linked picture to be added must exist in the same worksheet. Otherwise, it results into an InvalidOperationException.

    Format Linked Picture

    You can set whether the linked picture should display with a transparent background by setting the IPictureFormat.TransparentBackGround property to true.

    C#
    Copy Code
    // Set transparent background
    shape.PictureFormat.TransparentBackground = true;
    // Set degree of transparency
    shape.PictureFormat.Transparency = 0.8;

    You can also convert a linked picture to a usual static picture by setting the IPictureFormat.Reference property to null. Whereas, when this property is set to a reference for a normal picture, it is converted into a linked picture. For detailed implementation of converting a normal picture to a linked picture or vice versa, see online demo.