charts and shapes does not move when row inserted in excel in c# programmatically


February 2019


1.7k time


When I insert a row in Excel charts and other shapes does not move with their cells.
Let's say I have a chart at A5:D:10, then i insert a row below 2nd row, so now chart should be at A6:D:11, but the chart stays there and hides the 5th row.

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

At design time I have checked if the chart's 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.

Please help me to solve my problem

3 answers


I had the same problem and managed to fix it by unlocking the chart(s).


я решил его с обходным путем, упаковывает кто - то будет искать -
график и формы все еще не двигается, но теперь я задаю TopLeftCellсвойство диаграммы и формы во время выполнения и заставляя их двигаться, хотя теперь у меня есть накладные расходы по поддержанию его местоположения.


I had this problem, and setting any of the graph's properties made no difference. I traced my problem, it was due to having multiple sheets in my workbook. I was inserting cells in a number of sheets but only ever having the first sheet active.

If I added currentsheet.Activate(); before I inserted cells the graph moved as you'd had expected it to.