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


C# ContentControl.Delete方法代码示例

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


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

示例1: ToDocx

        /// <summary>
        /// Convert html to docx
        /// </summary>
        /// <param name="control"></param>
        /// <param name="html"></param>
        public void ToDocx(ContentControl control, string html)
        {
            int actionCount = 0;

            string ra = Convert.ToChar(0x000D).ToString() + Convert.ToChar(0x0007).ToString(); // \r\a
            string folderName = Path.GetTempPath() + Guid.NewGuid().ToString(); // temp folder
            string fileName = folderName + "\\temp.docx"; // temp file
            string controlID = control.ID;

            Range range = control.Range;

            Globals.ThisAddIn.Application.ScreenUpdating = false; // false to update screen

            Microsoft.Office.Interop.Word.Document doc = null;

            try
            {
                // get wi id and field name
                string wiID = Globals.ThisAddIn.Application.ActiveDocument.Variables[control.ID + "_wiid"].Value;
                string wiField = Globals.ThisAddIn.Application.ActiveDocument.Variables[control.ID + "_wifield"].Value;

                CreateTempDocument(html, folderName, fileName);

                // get range to insert
                doc = Globals.ThisAddIn.Application.Documents.Open(fileName, Visible: false, ReadOnly: true);
                Range insert = doc.Content;
                PrepareRange(ref range, ref insert);

                // delete old control

                Globals.ThisAddIn.Application.ActiveDocument.Range(range.Start - 1, range.End + 1).Select();
                if (wiField != "System.Title") Globals.ThisAddIn.Application.Selection.ClearFormatting(); actionCount++;

                control.Delete(true); actionCount++;

                // insert range
                if (wiField != "System.Title") { range.FormattedText = insert.FormattedText; actionCount++; }
                else { range.Text = insert.Text; actionCount++; }

                range.LanguageID = WdLanguageID.wdNoProofing;

                foreach (InlineShape image in range.InlineShapes)
                    image.LinkFormat.SavePictureWithDocument = true;

                range.Select();
                ExtendSelection();

                Globals.ThisAddIn.Application.ActiveDocument.Range(range.End, range.End + 1).Delete(); actionCount++;

                // add new control
                int id = 0;

                if (Int32.TryParse(wiID, out id))
                    Globals.ThisAddIn.AddWIControl(id, wiField, range);
            }
            catch (Exception e)
            {
                if (actionCount > 0)
                    Globals.ThisAddIn.Application.ActiveDocument.Undo(actionCount);

                throw new Exception(e.Message);
            }
            finally
            {
                Globals.ThisAddIn.Application.Selection.Collapse();
                Globals.ThisAddIn.Application.ScreenUpdating = true;

                try
                {
                    ((_Document)doc).Close(SaveChanges: false);

                    if (Directory.Exists(folderName))
                        Directory.Delete(folderName, true);
                }
                catch { }
            }

            DeleteVariables(controlID);
        }
开发者ID:SoftServeInc,项目名称:SALMA,代码行数:84,代码来源:HtmlToDocx.cs


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