@@ -788,7 +788,7 @@ internal int GetPixelLeft()
788788 {
789789 return ( int ) ( Math . Round ( From . X * _drawings . _screenWidth ) ) ;
790790 }
791- return 0 ;
791+ return Position == null ? 0 : Position . X / EMU_PER_PIXEL ;
792792 }
793793 if ( CellAnchor == eEditAs . Absolute )
794794 {
@@ -818,7 +818,7 @@ internal int GetPixelTop()
818818 {
819819 return ( int ) ( Math . Round ( From . Y * _drawings . _screenHeight ) ) ;
820820 }
821- return 0 ;
821+ return Position == null ? 0 : Position . Y / EMU_PER_PIXEL ;
822822 }
823823
824824 if ( CellAnchor == eEditAs . Absolute )
@@ -928,14 +928,7 @@ internal void SetPixelTop(double pixels)
928928 _doNotAdjust = true ;
929929 if ( CellAnchor == eEditAs . Absolute )
930930 {
931- if ( _collectionType == DrawingsCollectionType . Worksheet )
932- {
933- Position . Y = ( int ) ( pixels * EMU_PER_PIXEL ) ;
934- }
935- else
936- {
937- From . Y = ( double ) pixels / _drawings . _screenHeight ;
938- }
931+ Position . Y = ( int ) ( pixels * EMU_PER_PIXEL ) ;
939932 }
940933 else
941934 {
@@ -977,14 +970,7 @@ internal void SetPixelLeft(double pixels)
977970 _doNotAdjust = true ;
978971 if ( CellAnchor == eEditAs . Absolute )
979972 {
980- if ( _collectionType == DrawingsCollectionType . Worksheet )
981- {
982- Position . X = ( int ) ( pixels * EMU_PER_PIXEL ) ;
983- }
984- else
985- {
986- From . X = ( double ) pixels / _drawings . _screenWidth ;
987- }
973+ Position . X = ( int ) ( pixels * EMU_PER_PIXEL ) ;
988974 }
989975 else
990976 {
@@ -1143,7 +1129,7 @@ internal void GetToColumnFromPixels(double pixels, out int col, out int colOff,
11431129 double pixOff = pixels - ( PixelHelper . GetColumnWidth ( ws , fromColumn + 1 ) - fromColumnOff / EMU_PER_PIXEL ) ;
11441130 double offset = ( double ) fromColumnOff / EMU_PER_PIXEL + pixels ;
11451131 col = fromColumn + 2 ;
1146- while ( pixOff >= 0 )
1132+ while ( pixOff >= 0 && col < ExcelPackage . MaxColumns )
11471133 {
11481134 offset = pixOff ;
11491135 pixOff -= PixelHelper . GetColumnWidth ( ws , col ++ ) ;
@@ -1266,6 +1252,11 @@ private void AdjustFromToXY(double x, double y)
12661252 }
12671253 else
12681254 {
1255+ if ( EditAs != eEditAs . Absolute )
1256+ {
1257+ To . X = x + To . X - From . X ;
1258+ To . Y = y + To . Y - From . Y ;
1259+ }
12691260 From . X = x ;
12701261 From . Y = y ;
12711262 }
@@ -1532,8 +1523,18 @@ private void SetWidthChartShape(double PixelWidth)
15321523 }
15331524 if ( To != null )
15341525 {
1535- To . X = ( From . X + PixelWidth / _drawings . _screenWidth ) ;
1536- if ( To . X > 1 ) To . X = 1 ; else if ( To . X < 0 ) To . X = 0 ;
1526+ var widthFraction = PixelWidth / _drawings . _screenWidth ;
1527+ To . X = From . X + widthFraction ;
1528+ if ( To . X > 1 )
1529+ {
1530+ To . X = 1 ;
1531+ From . X = Math . Max ( 0 , 1 - widthFraction ) ;
1532+ }
1533+ else if ( To . X < 0 )
1534+ {
1535+ From . X = 0 ;
1536+ To . X = widthFraction ;
1537+ }
15371538 }
15381539 if ( Size != null )
15391540 {
@@ -1548,12 +1549,18 @@ private void SetHeightChartShape(double PixelHeight)
15481549 }
15491550 if ( To != null )
15501551 {
1551-
1552-
1553- if ( To . X > 1 ) To . X = 1 ; else if ( To . X < 0 ) To . X = 0 ;
1554-
1555- To . Y = ( From . Y + PixelHeight / _drawings . _screenHeight ) ;
1556- if ( To . Y > 1 ) To . Y = 1 ; else if ( To . Y < 0 ) To . Y = 0 ;
1552+ var heightFraction = PixelHeight / _drawings . _screenHeight ;
1553+ To . Y = From . Y + heightFraction ;
1554+ if ( To . Y > 1 )
1555+ {
1556+ To . Y = 1 ;
1557+ From . Y = Math . Max ( 0 , 1 - heightFraction ) ;
1558+ }
1559+ else if ( To . Y < 0 )
1560+ {
1561+ From . Y = 0 ;
1562+ To . Y = heightFraction ;
1563+ }
15571564 }
15581565 if ( Size != null )
15591566 {
0 commit comments