Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
Copy WorkSheetShape
posted

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?

Parents
No Data
Reply
  • 125
    Offline posted

    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];
            }

Children
No Data