当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.Office.Interop.Excel.CustomDocumentProperties方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Excel.CustomDocumentProperties方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Excel.CustomDocumentProperties方法的具体用法?C# Microsoft.Office.Interop.Excel.CustomDocumentProperties怎么用?C# Microsoft.Office.Interop.Excel.CustomDocumentProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Excel的用法示例。


在下文中一共展示了Microsoft.Office.Interop.Excel.CustomDocumentProperties方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WorkbookBeforeSaveHandler

        /// <summary>
        /// Before the workbook is saved, finalize the elapsed time, write the ElapsedTime CustomDocumentProperty
        /// </summary>
        /// <param name="Wb"></param>
        /// <param name="Cancel"></param>
        public void WorkbookBeforeSaveHandler(Excel.Workbook Wb)
        {
            log.Info("WorkbookBeforeSaveHandler - Start");

            // Checks that the Workbook is being timed
            if (!timers.ContainsKey(Wb.FullName)) { return; }

            // Save the current Workbook FullName as previous name CustomDocumentProperty
            // We will check this value after the save to update the timers Dictionary
            if (CustomDocumentPropertiesContain(Wb, PREVFULLNAME))
            {
                // Delete existing CustomDocumentProperty if it exists
                Wb.CustomDocumentProperties(PREVFULLNAME).Delete();
            }
            // Add a new CustomDocumentProperty saving the current FullName of the workbook
            Wb.CustomDocumentProperties.Add(
                Name: PREVFULLNAME, LinkToContent: false,
                Type: Office.MsoDocProperties.msoPropertyTypeString, Value: Wb.FullName);

            double elapsedSeconds;

            // Finalize the elasped time
            // First treat as a SheetChange and make sure the timer is up to date
            WorkbookChangeHandler(Wb);
            elapsedSeconds = timers[Wb.FullName].SaveSession();

            // Write the elapsed time to a the CustomDocumentProperty
            Wb.CustomDocumentProperties(ELAPSEDTIME).Value = elapsedSeconds;
            log.Info("WorkbookBeforeSaveHandler - Finish");
        }
开发者ID:jepayne1138,项目名称:excel-active-editing-timer,代码行数:35,代码来源:ThisAddIn.cs

示例2: Application_WorkbookOpenOrNew

        /// <summary>
        /// Initializes the Workbook timers upon opening or creating a new workbook
        /// </summary>
        /// <param name="Wb"></param>
        private void Application_WorkbookOpenOrNew(Excel.Workbook Wb)
        {
            try
            {
                log.Info(String.Format("Application_WorkbookOpenOrNew: <{0}>", Wb.Name));

                // Check if the workbook name is blacklisted (or in XLSTART)
                if (blacklist.Contains(Wb.Name.ToLower()) || Wb.Path == Application.StartupPath) { return; }

                double elapsedMinutes;

                // Try to get the stored elapsed time for this Workbook, or initialize it to zero if it doesn't exist
                if (CustomDocumentPropertiesContain(Wb, ELAPSEDTIME))
                {
                    elapsedMinutes = Wb.CustomDocumentProperties(ELAPSEDTIME).Value;
                }
                else
                {
                    // The CustomDocumentProperty does not exist, so created it and initialize to zero
                    elapsedMinutes = 0;
                    Wb.CustomDocumentProperties.Add(
                        Name: ELAPSEDTIME, LinkToContent: false,
                        Type: Office.MsoDocProperties.msoPropertyTypeNumber, Value: elapsedMinutes);
                }

                // Create a new WorkbookTimers instance for the opened Workbook
                if (!timers.ContainsKey(Wb.FullName))
                {
                    timers.Add(Wb.FullName, new WorkbookTimers(elapsedMinutes));
                }
                else
                {
                    // The timer for this Workbook already existed.  This should never happen, but if so, just overwrite previous timer.
                    timers.Remove(Wb.FullName);
                    timers.Add(Wb.FullName, new WorkbookTimers(elapsedMinutes));
                }

                log.Info("Application_WorkbookOpenOrNew - Finish");
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
开发者ID:jepayne1138,项目名称:excel-active-editing-timer,代码行数:48,代码来源:ThisAddIn.cs

示例3: WorkbookAfterSaveHandler

        public void WorkbookAfterSaveHandler(Excel.Workbook Wb, bool success)
        {
            log.Info("WorkbookAfterSaveHandler - Start");

            if (!CustomDocumentPropertiesContain(Wb, PREVFULLNAME)) { return; }

            string prevFullName;

            prevFullName = Wb.CustomDocumentProperties(PREVFULLNAME).Value;

            // Check if any timer was counting for the file with the previous name
            // If so, change the Dictionary key to be the new Workbook's FullName
            if (timers.ContainsKey(prevFullName))
            {
                WorkbookTimers tempWorkbookTimers = timers[prevFullName];
                timers.Remove(prevFullName);
                timers.Add(Wb.FullName, tempWorkbookTimers);
            }

            // Delete the PrevFullName CustomDocumentProperty
            Wb.CustomDocumentProperties(PREVFULLNAME).Delete();

            log.Info("WorkbookAfterSaveHandler - Finish");
        }
开发者ID:jepayne1138,项目名称:excel-active-editing-timer,代码行数:24,代码来源:ThisAddIn.cs


注:本文中的Microsoft.Office.Interop.Excel.CustomDocumentProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。