Cells.InsertRows() Method Does Not Push Images Down

I’ve been using the InsertRows() method and it will not push images down like inserting a row from Excel will. Is there something more I need to do?

Thanks, Natan.

Hi Natan,

Please try this attached fix.

Thanks! Looks good.

@cohenn,
Aspose.Cells is the new product that has replaced Aspose.Excel that is no more available now. You can insert rows using Aspose.Cells with a variety of options similar to MS Excel. Here is an example that demonstrates this feature where rows are inserted such that images are moved also. Note that you can insert images also using Aspose.Cells such that you can set option for the images to be moved or remain fixed while inserting/deleting rows.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
string dataDir = "";

// Instantiate a new workbook
Workbook workbook = new Workbook();

// Get the first worksheet
Worksheet worksheet = workbook.Worksheets[0];

// Insert a string value to a cell
worksheet.Cells["C2"].PutValue("Image Hyperlink");

// Set the 4th row height
worksheet.Cells.SetRowHeight(3, 100);

// Set the C column width
worksheet.Cells.SetColumnWidth(2, 21);

// Add a picture to the C4 cell
int index = worksheet.Pictures.Add(3, 2, 4, 3, dataDir + "Forum_AsposeIcon.png");

// Get the picture object
Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[index];

// Set the placement type
pic.Placement = PlacementType.Move;

// Add an image hyperlink
Aspose.Cells.Hyperlink hlink = pic.AddHyperlink("http://www.aspose.com/");

// Specify the screen tip
hlink.ScreenTip = "Click to go to Aspose site";

// Save the Excel file
workbook.Save("ImageHyperlink.out.xlsx");

// Inserting a row into the worksheet at 3rd position
InsertOptions insertOptions = new InsertOptions();
insertOptions.CopyFormatType = CopyFormatType.SameAsAbove;
worksheet.Cells.InsertRows(0, 5, insertOptions);
workbook.Save("ImageHyperlink.InsertRows.xlsx");

For more information about this feature, refer to the following article:
Inserting and Deleting Rows and Columns

For testing this code, get a free trial version here:
Aspose.Cells for .NET (Latest Version)

A comprehensive detailed solution is available here which contains hundreds of ready to run examples for testing different features of this product.