コード例 #1
0
        public void Dispose()
        {
            if (commandButton != null)
            {
                IsDisposed = true;

                if (CurrentCommand != null)
                {
                    commandButton.Click -= CurrentCommand;
                }

                ExcelInterop.Worksheet worksheet = OwnerRange.Worksheet;

                ExcelInterop.OLEObject obj = worksheet.OLEObjects(Name);
                obj.Delete();

                ExcelApplication.ReleaseComObject(obj);
                ExcelApplication.ReleaseComObject(commandButton);
                ExcelApplication.ReleaseComObject(OwnerRange);
                ExcelApplication.ReleaseComObject(worksheet);

                obj           = null;
                commandButton = null;
                OwnerRange    = null;
                worksheet     = null;
            }
        }
コード例 #2
0
        public ExcelButton(ExcelInterop.Range range, ExcelButtonDefinition definition)
        {
            OwnerRange        = range;
            OwnerRange.Value2 = null;
            ExcelInterop.Worksheet  worksheet  = null;
            ExcelInterop.OLEObjects oleObjects = null;
            ExcelInterop.OLEObject  obj        = null;

            try
            {
                worksheet = OwnerRange.Worksheet;
                Name      = $"ExcelBtn{Interlocked.Increment(ref cpt)}";

                oleObjects = worksheet.OLEObjects();
                obj        = oleObjects.Add("Forms.CommandButton.1",
                                            Type.Missing,
                                            false,
                                            false,
                                            Type.Missing,
                                            Type.Missing,
                                            Type.Missing,
                                            OwnerRange.Left + definition.X,
                                            OwnerRange.Top + definition.Y,
                                            definition.W == 0 ? OwnerRange.Width : definition.W,
                                            definition.H == 0 ? OwnerRange.Height : definition.H);

                obj.Name = Name;
                object s = worksheet.GetType().InvokeMember(Name, BindingFlags.Default | BindingFlags.GetProperty, null, worksheet, null);
                commandButton           = s as ExcelForms.CommandButton;
                commandButton.FontName  = "Arial";
                commandButton.Font.Size = 8;
                commandButton.Caption   = definition.Label;
                //if (excelTemplateDefinition.W == 0 && excelTemplateDefinition.H == 0)
                //    commandButton.AutoSize = true;
                obj.Placement = ExcelInterop.XlPlacement.xlMove;
            }
            finally
            {
                if (obj != null)
                {
                    ExcelApplication.ReleaseComObject(obj);
                }
                if (oleObjects != null)
                {
                    ExcelApplication.ReleaseComObject(oleObjects);
                }
                if (worksheet != null)
                {
                    ExcelApplication.ReleaseComObject(worksheet);
                }
                obj        = null;
                oleObjects = null;
                worksheet  = null;
            }
        }
コード例 #3
0
        public void Dispose()
        {
            if (commandButton != null)
            {
                IsDisposed = true;

                View.ViewSheet.OLEObjects(Name).Delete();
                commandButton = null;
                OwnerRange    = null;
            }
        }
コード例 #4
0
        public ExcelSortAndFilterButton(ExcelTemplateView templateView)
        {
            this.View = templateView;
            ExcelInterop.Worksheet worksheet = null;
            ExcelInterop.Shapes    shapes    = null;
            ExcelInterop.Shape     shape     = null;
            try
            {
                worksheet  = View.ViewSheet;
                OwnerRange = View.FirstOutputCell;
                Name       = $"ExcelBtn{Interlocked.Increment(ref cpt)}";
                shapes     = worksheet.Shapes;

                shape = (ExcelInterop.Shape)shapes.AddOLEObject("Forms.CommandButton.1",
                                                                Type.Missing,
                                                                false,
                                                                false,
                                                                Type.Missing,
                                                                Type.Missing,
                                                                Type.Missing,
                                                                OwnerRange.Left,
                                                                OwnerRange.Top,
                                                                20,
                                                                20);

                shape.Name = Name;
                object s = worksheet.GetType().InvokeMember(Name, BindingFlags.GetProperty, null, worksheet, null);
                commandButton = s as ExcelForms.CommandButton;


                commandButton.FontName  = "Arial";
                commandButton.Font.Size = 8;
                commandButton.Caption   = "S/F";
                commandButton.ForeColor = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);

                commandButton.Click += () =>
                {
                    using (ExcelMainWindow excelWindow = new ExcelMainWindow(ETKExcel.ExcelApplication.Application.Hwnd))
                    {
                        //@@SortAndFilterManagement.DisplaySortAndFilterWindow(excelWindow, View);
                    }
                };
            }
            finally
            {
                if (shape != null)
                {
                    ExcelApplication.ReleaseComObject(shape);
                }
                if (shapes != null)
                {
                    ExcelApplication.ReleaseComObject(shapes);
                }
                if (worksheet != null)
                {
                    ExcelApplication.ReleaseComObject(worksheet);
                }

                shape     = null;
                shapes    = null;
                worksheet = null;
            }
        }