Beispiel #1
0
 public void ScaleWidth(float Factor, MsoTriState RelativeToOriginalSize, MsoScaleFrom fScale = MsoScaleFrom.msoScaleFromTopLeft)
 {
     throw new NotImplementedException();
 }
Beispiel #2
0
        /// <summary>
        /// InsertPicture
        /// </summary>
        /// <param name="fileName"></param>

        public static void InsertPicture(
            string fileName,
            float dx,
            float dy,
            float width,
            float height,
            float scale = -1)
        {
            if (LogCalls)
            {
                DebugLog.Message("ExcelOp InsertPicture " + fileName);
            }

            float left = (float)((double)XlApp.ActiveCell.Left) + dx;
            float top  = (float)((double)XlApp.ActiveCell.Top) + dy;

            float origWidth = width;

            if (width <= 0)
            {
                width = (float)((double)XlApp.ActiveCell.Width);
            }

            float origHeight = height;

            if (height <= 0)
            {
                height = (float)((double)XlApp.ActiveCell.Height);
            }

            bool scaleShapeSize = false;

            if (scale > 0)
            {
                left   *= scale;
                top    *= scale;
                width  *= scale;
                height *= scale;

                float rowHeight = height;

                if (scale > 1 && AdjustHighDpiRowHeight)                 // fudge to adjust row height better for relatively tall images
                {
                    if (height < width)
                    {
                        float fFactor = ((width - height) / width);                         // varies 1 for no height to 0 for height == width
                        float scale2  = 1 + ((scale - 1) * fFactor);
                        rowHeight = origHeight * scale2;
                    }

                    else
                    {
                        rowHeight = origHeight;
                    }
                }

                RowHeight(rowHeight);                 // be sure row is at least this height

                //scaleShapeSize = true; // don't turn on shape scaling, doesn't seem to help
            }

            else
            {
                scale = 1.0f;
            }

            MsoTriState linkToFile     = MsoTriState.msoFalse;
            MsoTriState saveToDocument = MsoTriState.msoTrue;

            XlShape = XlSheet.Shapes.AddPicture(fileName, linkToFile, saveToDocument, left, top, width, height);

            if (scaleShapeSize)             // adjust scaling of the shape just created
            {
                MsoTriState  scaleRelativeToOriginalSize = MsoTriState.msoTrue;
                MsoScaleFrom scaleFrom = MsoScaleFrom.msoScaleFromTopLeft;

                XlShape.LockAspectRatio = MsoTriState.msoTrue;
                XlShape.ScaleWidth(scale, scaleRelativeToOriginalSize, scaleFrom);
                //XlShape.ScaleHeight(scale, scaleRelativeToOriginalSize, scaleFrom);
            }

            ReleaseObject(XlShape);
        }
Beispiel #3
0
 public void ScaleWidth(float Factor, MsoTriState RelativeToOriginalSize, MsoScaleFrom fScale = MsoScaleFrom.msoScaleFromTopLeft)
 {
     throw new NotImplementedException();
 }
        /// <summary>按指定的比例调整形状的宽度。对于图片和 OLE 对象,可以指定是相对于原有尺寸还是相对于当前尺寸来调整该形状。对于不是图片和 OLE 对象的形状,总是相对于其当前大小来调整宽度。
        /// </summary>
        /// <param name="Factor">指定形状调整后的宽度与当前或原始宽度的比例。例如,若要将一个矩形放大百分之五十,请将此参数设为 1.5。</param>
        /// <param name="RelativeToOriginalSize">如果为 False,则相对于形状的原有尺寸来调整宽度。仅当指定的形状是图片或 OLE 对象时,才能将此参数指定为 True。</param>
        /// <param name="Scale">MsoScaleFrom 的常量之一,它指定调整形状大小时,该形状哪一部分的位置将保持不变。</param>
        public void ScaleWidth(float Factor, MsoTriState RelativeToOriginalSize, MsoScaleFrom? Scale = null)
        {
            _objaParameters = new object[3] {
                Factor,
                RelativeToOriginalSize,
                Scale == null ? System.Type.Missing : Scale
            };

            _objShapeRange.GetType().InvokeMember("ScaleWidth", BindingFlags.InvokeMethod, null, _objShapeRange, _objaParameters);
        }