예제 #1
0
        protected ExcelControl(ExcelDrawings drawings, XmlNode drawingNode, string name, ExcelGroupShape parent = null) :
            base(drawings, drawingNode, "xdr:sp", "xdr:nvSpPr/xdr:cNvPr", parent)
        {
            var ws = drawings.Worksheet;

            //Drawing Xml
            XmlElement spElement = CreateShapeNode();

            spElement.InnerXml = ControlStartDrawingXml();
            CreateClientData();

            ControlPropertiesXml = new XmlDocument();
            ControlPropertiesXml.LoadXml(ControlStartControlPrXml());
            int id = ws.SheetId;

            ControlPropertiesUri  = GetNewUri(ws._package.ZipPackage, "/xl/ctrlProps/ctrlProp{0}.xml", ref id);
            ControlPropertiesPart = ws._package.ZipPackage.CreatePart(ControlPropertiesUri, ContentTypes.contentTypeControlProperties);
            var rel = ws.Part.CreateRelationship(ControlPropertiesUri, TargetMode.Internal, ExcelPackage.schemaRelationships + "/ctrlProp");

            //Vml
            _vml     = drawings.Worksheet.VmlDrawings.AddControl(this, name);
            _vmlProp = XmlHelperFactory.Create(_vml.NameSpaceManager, _vml.GetNode("x:ClientData"));

            //Control in worksheet xml
            XmlNode ctrlNode = ws.CreateControlContainerNode();

            ((XmlElement)ws.TopNode).SetAttribute("xmlns:xdr", ExcelPackage.schemaSheetDrawings);      //Make sure the namespace exists
            ((XmlElement)ws.TopNode).SetAttribute("xmlns:x14", ExcelPackage.schemaMainX14);            //Make sure the namespace exists
            ((XmlElement)ws.TopNode).SetAttribute("xmlns:mc", ExcelPackage.schemaMarkupCompatibility); //Make sure the namespace exists
            ctrlNode.InnerXml = GetControlStartWorksheetXml(rel.Id);
            _control          = new ControlInternal(NameSpaceManager, ctrlNode.FirstChild);
            _ctrlProp         = XmlHelperFactory.Create(NameSpaceManager, ControlPropertiesXml.DocumentElement);
        }
예제 #2
0
 internal ExcelControl(ExcelDrawings drawings, XmlNode drawingNode, ControlInternal control, ZipPackagePart ctrlPropPart, XmlDocument ctrlPropXml, ExcelGroupShape parent = null) :
     base(drawings, drawingNode, "xdr:sp", "xdr:nvSpPr/xdr:cNvPr", parent)
 {
     _control              = control;
     _vml                  = (ExcelVmlDrawingControl)drawings.Worksheet.VmlDrawings[LegacySpId];
     _vmlProp              = XmlHelperFactory.Create(_vml.NameSpaceManager, _vml.GetNode("x:ClientData"));
     ControlPropertiesXml  = ctrlPropXml;
     ControlPropertiesPart = ctrlPropPart;
     ControlPropertiesUri  = ctrlPropPart.Uri;
     _ctrlProp             = XmlHelperFactory.Create(NameSpaceManager, ctrlPropXml.DocumentElement);
 }
예제 #3
0
 internal ExcelControlWithText(ExcelDrawings drawings, XmlNode drawingNode, ControlInternal control, ZipPackagePart part, XmlDocument ctrlPropXml, ExcelGroupShape parent = null) :
     base(drawings, drawingNode, control, part, ctrlPropXml, parent)
 {
 }
예제 #4
0
 internal ExcelControlEditBox(ExcelDrawings drawings, XmlNode drawNode, ControlInternal control, ZipPackagePart part, XmlDocument controlPropertiesXml, ExcelGroupShape parent = null)
     : base(drawings, drawNode, control, part, controlPropertiesXml, parent)
 {
 }
예제 #5
0
        internal static ExcelDrawing GetControl(ExcelDrawings drawings, XmlElement drawNode, ControlInternal control, ExcelGroupShape parent)
        {
            var rel                  = drawings.Worksheet.Part.GetRelationship(control.RelationshipId);
            var controlUri           = UriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri);
            var part                 = drawings.Worksheet._package.ZipPackage.GetPart(controlUri);
            var controlPropertiesXml = new XmlDocument();

            XmlHelper.LoadXmlSafe(controlPropertiesXml, part.GetStream());
            var objectType  = controlPropertiesXml.DocumentElement.Attributes["objectType"]?.Value;
            var controlType = GetControlType(objectType);

            XmlNode node;

            if (parent == null)
            {
                node = drawNode.ParentNode;
            }
            else
            {
                node = drawNode;
            }

            switch (controlType)
            {
            case eControlType.Button:
                return(new ExcelControlButton(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.DropDown:
                return(new ExcelControlDropDown(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.GroupBox:
                return(new ExcelControlGroupBox(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.Label:
                return(new ExcelControlLabel(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.ListBox:
                return(new ExcelControlListBox(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.CheckBox:
                return(new ExcelControlCheckBox(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.RadioButton:
                return(new ExcelControlRadioButton(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.ScrollBar:
                return(new ExcelControlScrollBar(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.SpinButton:
                return(new ExcelControlSpinButton(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.EditBox:
                return(new ExcelControlEditBox(drawings, node, control, part, controlPropertiesXml, parent));

            case eControlType.Dialog:
                return(new ExcelControlDialog(drawings, node, control, part, controlPropertiesXml, parent));

            default:
                throw new NotSupportedException();
            }
            throw new NotImplementedException();
        }