Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
When i insert a row in excel, charts and other shapes does not move with their cells.
Lets say i have a chart at A5:D10, then i insert a row below 2nd row, so now chart should be at A6:D11, but chart stays their and hides the 5th row.

I design a template containing chart and shape, then at runtime i am supplying data for chart and changing few properties of shapes. Now my sheet contains some data in first 5 rows and i insert row after 2nd row then everything should go one row down, but this is not happening.

At design time i have checked that charts property to move and size with cells is set to true. Yet this is not happening at runtime programmatically. Although at design time inserting rows have no issues.

Following is code used to insert row :
C#
range.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromRightOrBelow);


Please help me to solve my problem
Thnx.
Posted

1 solution

The charts are not part of spreadsheet. They are displayed in separate 'windows' and overlay the sheet. You need to get the instance of the chart and update its position relative to top left corner. In other words you need to shift position of the chart down by the value based on the hight of the inserted row.
 
Share this answer
 
Comments
j4m4l 20-Apr-12 23:25pm    
There is a property for charts and shapes i.e. 'move and size with cell', if i set this property at rutime like this :
chartObject.Placement = Excel.XlPlacement.xlMoveAndSize;
than it should work, but its not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900