void Copy (WorkBook book) { WorkSheet sheet1 = book.WrokSheets [0]; WorkSheet sheet2 = book.WrokSheets [1]; WorkSheetShape shape = sheet1.Shapes [0]; sheet2.Shapes.Add (shape); / / exception } How to add shape to sheet2?
For me it worked like this:
foreach (WorksheetImage shapeSource in sourceWorksheet.Shapes) { WorksheetImage shapeDestination = new WorksheetImage(shapeSource.Image); shapeDestination.Outline = shapeSource.Outline; shapeDestination.TopLeftCornerCell = GetSameCellInOtherWorksheet(shapeSource.TopLeftCornerCell, destination); shapeDestination.TopLeftCornerPosition = shapeSource.TopLeftCornerPosition; shapeDestination.BottomRightCornerCell = GetSameCellInOtherWorksheet(shapeSource.BottomRightCornerCell, destination); shapeDestination.BottomRightCornerPosition = shapeSource.BottomRightCornerPosition; shapeDestination.PositioningMode = shapeSource.PositioningMode; destination.Shapes.Add(shapeDestination); }
static WorksheetCell GetSameCellInOtherWorksheet(WorksheetCell sourceCell, Worksheet destinationWorksheet) { return destinationWorksheet.Rows[sourceCell.RowIndex].Cells[sourceCell.ColumnIndex]; }