コード例 #1
0
        private void Set(string key, MsoDocProperties type, object value)
        {
            if (value == null)
            {
                this.Remove(key);
                return;
            }

            var property = this.Get(key);

            if (property != null)
            {
                property.Value = value;
                return;
            }

            this.Properties.Add(key, false, type, value, null);
        }
コード例 #2
0
        private void ChooseAttribute(object sender, SelectionChangedEventArgs e)
        {
            if (itemList.SelectedItem != null)
            {
                btnSave.IsEnabled = true;
                string selectedItem = itemList.SelectedItem.ToString();
                string category     = itemType.SelectedItem.ToString();
                object retval;
                if (category == "Document Property")
                {
                    try
                    {
                        DocumentProperties properties = (DocumentProperties)Globals.ThisAddIn.Application.ActiveDocument.BuiltInDocumentProperties;
                        retval = properties[selectedItem];
                    }
                    catch (ArgumentException)
                    {
                        DocumentProperties properties = (DocumentProperties)Globals.ThisAddIn.Application.ActiveDocument.CustomDocumentProperties;
                        retval = properties[selectedItem];
                    }
                    MsoDocProperties valueType = ((DocumentProperty)retval).Type;
                    txtContents.Visibility = Visibility.Hidden;
                    dtpDateTime.Visibility = Visibility.Hidden;
                    chkValue.Visibility    = Visibility.Hidden;
                    dblValue.Visibility    = Visibility.Hidden;
                    intValue.Visibility    = Visibility.Hidden;
                    try
                    {
                        object test = ((DocumentProperty)retval).Value;
                    }
                    catch (System.Runtime.InteropServices.COMException)
                    {
                        valueType = 0;
                    }
                    switch (valueType)
                    {
                    case MsoDocProperties.msoPropertyTypeString:
                        txtContents.Visibility = Visibility.Visible;
                        txtContents.Text       = (string)((DocumentProperty)retval).Value;
                        break;

                    case MsoDocProperties.msoPropertyTypeDate:
                        dtpDateTime.Visibility = Visibility.Visible;
                        dtpDateTime.Value      = (DateTime)((DocumentProperty)retval).Value;
                        break;

                    case MsoDocProperties.msoPropertyTypeBoolean:
                        chkValue.Visibility = Visibility.Visible;
                        chkValue.IsChecked  = (bool)((DocumentProperty)retval).Value;
                        break;

                    case MsoDocProperties.msoPropertyTypeFloat:
                        dblValue.Visibility = Visibility.Visible;
                        dblValue.Value      = (float)((DocumentProperty)retval).Value;
                        break;

                    case MsoDocProperties.msoPropertyTypeNumber:
                        intValue.Visibility = Visibility.Visible;
                        intValue.Value      = (int)((DocumentProperty)retval).Value;
                        break;

                    case 0:
                        txtContents.Visibility = Visibility.Visible;
                        txtContents.Text       = "";
                        break;
                    }
                }
                else if (category == "Document Variable")
                {
                    retval           = Globals.ThisAddIn.Application.ActiveDocument.Variables[selectedItem].Value;
                    txtContents.Text = (string)retval;
                }
                else if (category == "Bookmark")
                {
                }
            }
            else
            {
                btnSave.IsEnabled = false;
            }
        }