Esempio n. 1
0
 public static void CustomFooterExists(bool hasCustomFooter)
 {
     try
     {
         Office.DocumentProperties prps = (Office.DocumentProperties)ExcelApplication.ActiveWorkbook.CustomDocumentProperties;
         // Add a new property.
         Office.DocumentProperty prp = prps.Add("HasCustomFooter", false, Office.MsoDocProperties.msoPropertyTypeBoolean, hasCustomFooter);
     } catch (Exception ex)
     {
         //PLLog.Error(ex, Globals.PROJECT_NAME)
         MessageBox.Show("CustomFooterExists() Unable to add HasCustomFooter property" + ex.Message);
     }
 }
Esempio n. 2
0
 public static bool HasCustomTableOfContents()
 {
     try
     {
         Office.DocumentProperties prps = (Office.DocumentProperties)ExcelApplication.ActiveWorkbook.CustomDocumentProperties;
         Office.DocumentProperty   prp  = prps["HasCustomTableOfContents"];
         // If the property exists we don't really care about the value
         return(true);
     }
     catch (Exception)
     {
         // Exception is thrown if property does not exist
         return(false);
     }
 }
Esempio n. 3
0
        private static Office.DocumentProperty Add(Excel.Workbook workbook, string propertyName, Office.MsoDocProperties propertyType, object value)
        {
            if (null == workbook)
            {
                throw new ArgumentNullException("workbook");
            }

            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            Office.DocumentProperties properties = workbook.CustomDocumentProperties;
            Office.DocumentProperty   property   = properties.Add(propertyName, false, propertyType, value);

            return(property);
        }
Esempio n. 4
0
        public static bool HasCustomFooter()
        {
            Office.DocumentProperty   prp  = default(Office.DocumentProperty);
            Office.DocumentProperties prps = default(Office.DocumentProperties);

            try
            {
                prps = (Office.DocumentProperties)ExcelApplication.ActiveWorkbook.CustomDocumentProperties;
                prp  = prps["HasCustomFooter"];
                // If the property exists we don't really care about the value
                return(true);
            }
            catch (Exception)
            {
                // Exception is thrown if property does not exist
                return(false);
            }
        }
Esempio n. 5
0
        public static string GetBuiltInPropertyValue(Workbook workBook, string propName)
        {
            string returnValue = "";

            //// This procedure returns the value of the built-in document
            //// property specified in the propName argument for the Office
            //// document object specified in the workBook argument.

            //DocumentProperty prpDocProp = default(DocumentProperty);
            //object varValue = null;

            //const long ERR_BADPROPERTY = 5;
            //const long ERR_BADDOCOBJ = 438;
            //const long ERR_BADCONTEXT = -2147467259;

            Office.DocumentProperties documentProperties = (Office.DocumentProperties)workBook.BuiltinDocumentProperties;

            if (documentProperties != null)
            {
                try
                {
                    Office.DocumentProperty property = documentProperties[propName];
                    returnValue = property.Value.ToString();
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    //Common.WriteToDebugWindow(string.Format("GetBuiltInPropertyValue({0}) COMException ErrorCode:({1})", propName, ex.ErrorCode));
                    returnValue = "Property Not Available Yet";
                }
                catch (NullReferenceException)
                {
                    //Common.WriteToDebugWindow(string.Format("GetBuiltInPropertyValue({0}) NullReferenceException", propName));
                    returnValue = "Property Not Set";
                }
                catch (Exception)
                {
                    //Common.WriteToDebugWindow(string.Format("GetBuiltInPropertyValue({0}) Exception >{1})<", propName, ex));
                }
            }

            return(returnValue);
        }
Esempio n. 6
0
        public static void Delete(Excel.Workbook workbook, string propertyName)
        {
            if (null == workbook)
            {
                throw new ArgumentNullException("workbook");
            }

            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            Office.DocumentProperty property = GetProperty(workbook, propertyName);

            if (null == property)
            {
                return;
            }

            property.Delete();
        }
Esempio n. 7
0
        public static void Set(Excel.Workbook workbook, string propertyName, string value)
        {
            if (null == workbook)
            {
                throw new ArgumentNullException("workbook");
            }

            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            Office.DocumentProperty property = GetProperty(workbook, propertyName);

            if (null == property)
            {
                property = Add(workbook, propertyName, Office.MsoDocProperties.msoPropertyTypeString, value);
            }

            property.Value = value;
        }