Ejemplo n.º 1
0
        private Excel.Shape[] Sort(Excel.ShapeRange shapeRange, Func <Excel.Shape, Excel.Shape, float> testFunc)
        {
            var sorted = new Excel.Shape[shapeRange.Count];

            for (int i = 0; i < sorted.Length; i++)
            {
                sorted[i] = shapeRange.Item(i + 1);
            }

            // FIXME: GroupByで一発でソートする
            bool swapped = true;

            while (swapped)
            {
                swapped = false;
                for (int i = 0, length = sorted.Length; i < length - 1; i++)
                {
                    if (testFunc(sorted[i], sorted[i + 1]) > 0)
                    {
                        var tmp = sorted[i + 1];
                        sorted[i + 1] = sorted[i];
                        sorted[i]     = tmp;
                        swapped       = true;
                    }
                }
            }

            return(sorted);
        }
        /// <summary>
        /// Get Selected Shape
        /// </summary>
        /// <returns>Return Selected Shape</returns>
        private MyShape GetShapeSelected()
        {
            Excel.Shape selectedShape   = null;
            MyShape     myselectedShape = null;

            Excel.ShapeRange selectedShapeRange = null;
            try
            {
                selectedShapeRange = this.Application.Selection.ShapeRange;
            }
            catch
            {
                if (selecteTypeNameNow != selectedTypeNameLastTime)
                {
                    customTaskPanel.AddMessage("No shape selected");
                }
            }
            if (selectedShapeRange != null)
            {
                selectedShape = selectedShapeRange.Item(1) as Excel.Shape;
                if (selectedShape != null)
                {
                    myselectedShape = new MyShape(selectedShape);
                    return(myselectedShape);
                }
            }

            return(myselectedShape);
        }