@@ -305,6 +305,41 @@ public void SetStyle(IExcelBatch batch, string chartName, int styleId)
305305 } ) ;
306306 }
307307
308+ /// <inheritdoc />
309+ public void SetPlacement ( IExcelBatch batch , string chartName , int placement )
310+ {
311+ batch . Execute ( ( ctx , ct ) =>
312+ {
313+ // Find chart by name
314+ var findResult = FindChart ( ctx . Book , chartName ) ;
315+ if ( findResult . Chart == null )
316+ {
317+ throw new InvalidOperationException ( $ "Chart '{ chartName } ' not found in workbook.") ;
318+ }
319+
320+ try
321+ {
322+ // Validate placement value (xlMoveAndSize=1, xlMove=2, xlFreeFloating=3)
323+ if ( placement < 1 || placement > 3 )
324+ {
325+ throw new ArgumentException (
326+ $ "Placement must be 1 (move and size with cells), 2 (move only), or 3 (free floating). Provided: { placement } ",
327+ nameof ( placement ) ) ;
328+ }
329+
330+ // Set placement on the shape (ChartObject)
331+ findResult . Shape . Placement = placement ;
332+
333+ return 0 ; // Void operation completed
334+ }
335+ finally
336+ {
337+ if ( findResult . Shape != null ) ComUtilities . Release ( ref findResult . Shape ! ) ;
338+ if ( findResult . Chart != null ) ComUtilities . Release ( ref findResult . Chart ! ) ;
339+ }
340+ } ) ;
341+ }
342+
308343 // === DATA LABELS ===
309344
310345 /// <inheritdoc />
@@ -1129,4 +1164,49 @@ public void SetTrendline(
11291164 }
11301165 } ) ;
11311166 }
1167+
1168+ /// <inheritdoc />
1169+ public void FitToRange ( IExcelBatch batch , string chartName , string sheetName , string rangeAddress )
1170+ {
1171+ batch . Execute ( ( ctx , ct ) =>
1172+ {
1173+ // Find chart by name
1174+ var findResult = FindChart ( ctx . Book , chartName ) ;
1175+ if ( findResult . Chart == null )
1176+ {
1177+ throw new InvalidOperationException ( $ "Chart '{ chartName } ' not found in workbook.") ;
1178+ }
1179+
1180+ dynamic ? worksheet = null ;
1181+ dynamic ? range = null ;
1182+
1183+ try
1184+ {
1185+ // Get the target range
1186+ worksheet = ctx . Book . Worksheets . Item ( sheetName ) ;
1187+ range = worksheet . Range [ rangeAddress ] ;
1188+
1189+ // Get range geometry
1190+ double left = Convert . ToDouble ( range . Left ) ;
1191+ double top = Convert . ToDouble ( range . Top ) ;
1192+ double width = Convert . ToDouble ( range . Width ) ;
1193+ double height = Convert . ToDouble ( range . Height ) ;
1194+
1195+ // Apply to chart shape
1196+ findResult . Shape . Left = left ;
1197+ findResult . Shape . Top = top ;
1198+ findResult . Shape . Width = width ;
1199+ findResult . Shape . Height = height ;
1200+
1201+ return 0 ; // Void operation completed
1202+ }
1203+ finally
1204+ {
1205+ if ( range != null ) ComUtilities . Release ( ref range ! ) ;
1206+ if ( worksheet != null ) ComUtilities . Release ( ref worksheet ! ) ;
1207+ if ( findResult . Shape != null ) ComUtilities . Release ( ref findResult . Shape ! ) ;
1208+ if ( findResult . Chart != null ) ComUtilities . Release ( ref findResult . Chart ! ) ;
1209+ }
1210+ } ) ;
1211+ }
11321212}
0 commit comments