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


C# Microsoft.Office.Interop.Word.Range方法代码示例

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


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

示例1: Create

        public ResultType_enum Create(Document document, Word.Application application, out Word._Document doc, out string message)
        {
            try
            {
                isWork = true;
                message = "";

                Object trueObj = true;
                Object falseObj = false;
                Object begin = Type.Missing;
                Object end = Type.Missing;
                doc = null;

                // Если вылетим не этом этапе, приложение останется открытым
                try
                {
                    doc = application.Documents.Add(ref missingObj, ref missingObj, ref missingObj, ref missingObj);
                    // Стиль
                    object patternstyle = Word.WdStyleType.wdStyleTypeParagraph;
                    Word.Style wordstyle = doc.Styles.Add("myStyle", ref patternstyle);
                    wordstyle.Font.Size = 9;
                    wordstyle.Font.Name = "Times New Roman";
                    Word.Range wordrange = doc.Range(ref begin, ref end);
                    object oWordStyle = wordstyle;
                    wordrange.set_Style(ref oWordStyle);

                    // Вставляем параграфы
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);

                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);

                    doc.Paragraphs[1].Range.Text = "Приложение № 1";
                    doc.Paragraphs[1].Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    doc.Paragraphs[1].Range.ParagraphFormat.LeftIndent = 300;
                    doc.Paragraphs[1].Range.ParagraphFormat.LineSpacing = 11;
                    //doc.Paragraphs[1].Range.ParagraphFormat.LineUnitBefore = 0;
                    doc.Paragraphs[1].SpaceAfter = 0;
                    doc.Paragraphs[1].SpaceBefore = 0;
                    doc.Paragraphs[2].LineUnitAfter = 0;
                    doc.Paragraphs[2].LineUnitBefore = 0;
                    doc.Paragraphs[3].LineUnitAfter = 0;
                    doc.Paragraphs[3].LineUnitBefore = 0;
                    doc.Paragraphs[4].LineUnitAfter = 0;
                    doc.Paragraphs[4].LineUnitBefore = 0;
                    //doc.Paragraphs[1].LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle;

                    doc.Paragraphs[2].Range.Text = "к Техническому заданию";
                    doc.Paragraphs[2].Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    doc.Paragraphs[2].Range.ParagraphFormat.LeftIndent = 300;

                    doc.Paragraphs[4].Range.Text = "ТРЕБОВАНИЯ К ТОВАРАМ, ИСПОЛЬЗУЕМЫМ ПРИ ВЫПОЛНЕНИИ РАБОТ";
                    doc.Paragraphs[4].Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;

                    //Добавляем таблицу (но перед этим узнаем сколько продуктов)
                    string productsMessage = "";

                    Object defaultTableBehavior =
                     Word.WdDefaultTableBehavior.wdWord9TableBehavior;
                    Object autoFitBehavior =
                     Word.WdAutoFitBehavior.wdAutoFitWindow;
                    Word.Table wordtable = doc.Tables.Add(doc.Paragraphs[5].Range, 3 + document.Products.Count, 6,
                      ref defaultTableBehavior, ref autoFitBehavior);

                    // Объединение ячеек
                    object begCell = wordtable.Cell(1, 1).Range.Start;
                    object endCell = wordtable.Cell(2, 1).Range.End;
                    Word.Range wordcellrange = doc.Range(ref begCell, ref endCell);
                    wordcellrange.Select();
                    application.Selection.Cells.Merge();

                    begCell = wordtable.Cell(1, 2).Range.Start;
                    endCell = wordtable.Cell(1, 3).Range.End;
                    wordcellrange = doc.Range(ref begCell, ref endCell);
                    wordcellrange.Select();
                    application.Selection.Cells.Merge();

                    begCell = wordtable.Cell(1, 3).Range.Start;
                    endCell = wordtable.Cell(1, 4).Range.End;
                    wordcellrange = doc.Range(ref begCell, ref endCell);
                    wordcellrange.Select();
                    application.Selection.Cells.Merge();

                    begCell = wordtable.Cell(1, 4).Range.Start;
                    endCell = wordtable.Cell(2, 6).Range.End;
                    wordcellrange = doc.Range(ref begCell, ref endCell);
                    wordcellrange.Select();
                    application.Selection.Cells.Merge();

                    // Окраска строки с номерами
                    begCell = wordtable.Cell(3, 1).Range.Start;
                    endCell = wordtable.Cell(3, 6).Range.End;
                    wordcellrange = doc.Range(ref begCell, ref endCell);
//.........这里部分代码省略.........
开发者ID:BrickProd,项目名称:PublicOrders,代码行数:101,代码来源:FreedomProcessor.cs

示例2: answerSpot

 /// <summary>
 /// 在指定范围内匹配,如果范围的start、end都为0,专门为答案识别
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="progressBarSpot"></param>
 /// <param name="matchArray"></param>
 /// <param name="start">指定范围的起始</param>
 /// <param name="end">指定范围的结束</param>
 /// <param name="prelength">前缀长度</param>
 /// <returns></returns>
 public List<SubjectInfo> answerSpot(Word.Document doc, ref ProgressBar progressBarSpot, string[] matchArray, int start, int end)
 {
     List<SubjectInfo> list = new List<SubjectInfo>();
     object start1 = start;
     object end1 = end;
     int count = 0;//总共有多少段落
     count = doc.Range(ref start1, ref end1).Paragraphs.Count;//正对选定的部分统计数据行数
     for (int i = 0; i < count; i++)
     {
         string text = "";
         text = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Text;
         if (text.ToString().Length > 1)//通过字段长度过滤来提高性能;
         {
             try
             {
                 doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Copy();
                 text = ClipboardHelper.getClipboardText();
             }
             catch
             {
                 text = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Text;
             }
             if (MatchContent.match(matchArray, text))
             {
                 SubjectInfo si = new SubjectInfo();
                 si.paragraphsNum = i;
                 si.paragraphsStart = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Start;
                 si.paragraphsEnd = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.End;
                 if (checkThisContentIsInTable(si.paragraphsStart, doc))//判断是否在表格范围
                 {
                     list.Add(si);
                 }
             }
         }
     }
     //排序题目信息(SubjectInfo)列表
     list.Sort(CompareSubJectInfo);
     return list;
 }
开发者ID:Kristd,项目名称:backup,代码行数:49,代码来源:MartianSpot.cs

示例3: Paste

        /// <summary>
        /// itemの内容をtargetにペーストする
        /// </summary>
        /// <param name="target"></param>
        /// <param name="item"></param>
        static public void Paste(this Word.Document document, Word.Document item)
        {
            try
            {
                // コピー
                item.Range(item.Content.Start, item.Content.End).Copy();

                // ペースト
                var rng = document.Range(document.Content.End - 1, document.Content.End - 1);
                rng.Paste();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
开发者ID:yuyi1,项目名称:WordMerge,代码行数:21,代码来源:Program.cs

示例4: MakeDropDownElementsText

        public void MakeDropDownElementsText(Word.Document doc)
        {
            //Comparison doesn't work with drop down controls so get rid of them!

            //Now step through the doc
            object start = doc.Content.Start;
            object end = doc.Content.End;
            Word.Range r = doc.Range(ref start, ref end);

            // Step through and select the one passed
            foreach (Word.ContentControl cc in r.ContentControls)
            {
                string tag = cc.Tag;
                if (tag != null && tag != "" && cc.Tag.Contains('|'))
                {
                    string[] taga = cc.Tag.Split('|');
                    if (taga[0] == "Element")
                    {
                        if (cc.Type == Word.WdContentControlType.wdContentControlDropdownList || cc.Type == Word.WdContentControlType.wdContentControlComboBox)
                        {
                            cc.Type = Word.WdContentControlType.wdContentControlText;
                        }

                    }
                }
            }
        }
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon01,代码行数:27,代码来源:ThisAddIn.cs

示例5: GetFootnotes

        public string GetFootnotes(Word.Document doc,string ConceptId)
        {
            string rtn = "";
            if (isTemplate(doc))
            {

                foreach (Word.ContentControl c in doc.Range().ContentControls)
                {
                    if (c.Tag != null)
                    {
                        string tag = Convert.ToString(c.Tag);
                        if (tag.StartsWith("Concept|" + ConceptId))
                        {
                            if (c.Range.Footnotes.Count > 0)
                            {
                                for (int z = 1; z <= c.Range.Footnotes.Count; z++)
                                {
                                    string foot = c.Range.Footnotes[z].Range.Text;
                                    if(foot.StartsWith("\t")) foot = foot.Substring(1);
                                    rtn += foot + "\n";
                                }
                            }

                        }
                    }
                }
            }
            else if (isClause(doc))
            {
                for (int z = 1; z <= doc.Range().Footnotes.Count; z++)
                {
                    string foot = doc.Range().Footnotes[z].Range.Text;
                    if (foot.StartsWith("\t")) foot = foot.Substring(1);
                    rtn += foot + "\n";
                }
            }

            return rtn;
        }
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon01,代码行数:39,代码来源:ThisAddIn.cs

示例6: UpdateContractTemplatesConceptTag

        public void UpdateContractTemplatesConceptTag(Word.Document doc, string conceptid, string clauseid, string lastmodified)
        {
            if (doc == null) doc = Application.ActiveDocument;
            //Is it one of ours
            if (isTemplate(doc))
            {

                string templateid = GetDocId(doc);

                //Now step through the doc and update the concept TAG if it matches the one we just updated
                object start = doc.Content.Start;
                object end = doc.Content.End;
                Word.Range r = doc.Range(ref start, ref end);

                //Create an array of concept content controls in the doc - have to copy or we get into problems with the range including the new ones
                //that we created
                Word.ContentControl[] ccs = new Word.ContentControl[r.ContentControls.Count];
                int cnt = 0;
                foreach (Word.ContentControl cc in r.ContentControls)
                {
                    ccs[cnt++] = cc;
                }

                //Now step through all the Contact Controls and update the XML so we get the newest clauses
                foreach (Word.ContentControl cc in ccs)
                {
                    string tag = cc.Tag;
                    if (tag != null && tag != "" && cc.Tag.Contains('|'))
                    {
                        string[] taga = cc.Tag.Split('|');
                        if (taga[0] == "Concept" && Convert.ToString(taga[1]) == conceptid)
                        {
                            // update the tag
                            if (clauseid == "")
                            {
                                cc.Tag = "Concept|" + conceptid;
                            }
                            else
                            {
                                cc.Tag = "Concept|" + conceptid + "|" + clauseid + "|" + lastmodified;
                            }
                        }
                    }

                }
            }
        }
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon01,代码行数:47,代码来源:ThisAddIn.cs

示例7: UpdateContractTemplateContentControls

        // this is used in the Template Import - updates the ContentControl tags to match the new
        // ids that have been created - this one does both the Clauses and the Elements that are
        // being displayed in the current template clause selection
        public void UpdateContractTemplateContentControls(Word.Document doc, Dictionary<string, string> ConceptMapping,Dictionary<string, string> ClauseMapping, Dictionary<string, string> ElementMapping)
        {
            //Is it one of ours
            if (isTemplate(doc))
            {
                //Remove the handler - won't have any hanlders yet - loaded it as an exporttemplate
                // Microsoft.Office.Tools.Word.Document vstoDoc = Globals.Factory.GetVstoObject(doc);
                // vstoDoc.ContentControlOnExit -= new Word.DocumentEvents2_ContentControlOnExitEventHandler(vstoDoc_ContentControlOnExit);

                string contractid = GetDocId(doc);

                //Now step through the doc
                object start = doc.Content.Start;
                object end = doc.Content.End;
                Word.Range r = doc.Range(ref start, ref end);

                foreach (Word.ContentControl cc in r.ContentControls)
                {
                    string tag = cc.Tag;
                    if (tag != null && tag != "" && cc.Tag.Contains('|'))
                    {
                        string[] taga = cc.Tag.Split('|');

                        if (taga.Length > 1 && ((taga[0] == "Concept" && taga[1] != "")))
                        {
                            // Concept is the format Concept|ConceptId|SelectedClauseId|LastModified
                            // as we are importing this everything should be up to date - set the LastModified to "0000"
                            // to indicate it is up to date - need to do this cause I don't have the last modified date

                            string ConceptIdOld = taga[1].ToString();
                            string ClauseIdOld = "";
                            if (taga.Length > 2)
                            {
                                ClauseIdOld = taga[2].ToString();
                            }

                            // if we have the new clause id then set the tag so that we know its the one in the doc
                            // "0000" indicates it has been loaded so is up to date
                            if (ClauseMapping.ContainsKey(ClauseIdOld))
                            {
                                cc.Tag = "Concept|" + ConceptMapping[ConceptIdOld] + "|" + ClauseMapping[ClauseIdOld] + "|0000";
                            }
                            else
                            {
                                cc.Tag = "Concept|" + ConceptMapping[ConceptIdOld];
                            }

                        }
                        else if ((taga[0] == "Element" && taga[1] != ""))
                        {
                            // Element tag is the format Element|ElementId|ClauseId
                            string ElementIdOld = taga[1].ToString();
                            string ClauseIdOld = taga[2].ToString();

                            // if its not in the mapping leave it be
                            if (ElementMapping.ContainsKey(ElementIdOld))
                            {
                                if (ClauseMapping.ContainsKey(ClauseIdOld))
                                {
                                    cc.Tag = "Element|" + ElementMapping[ElementIdOld] + "|" + ClauseMapping[ClauseIdOld];
                                }
                                else
                                {
                                    cc.Tag = "Element|" + ElementMapping[ElementIdOld];
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon01,代码行数:74,代码来源:ThisAddIn.cs

示例8: UpdateClauseTemplateContentControls

        public void UpdateClauseTemplateContentControls(Word.Document doc, Dictionary<string, string> ConceptMapping, Dictionary<string, string> ClauseMapping, Dictionary<string, string> ElementMapping)
        {
            //Is it one of ours
            if (isClause(doc))
            {
                // Remove the handler - won't have any hanlders yet - loaded it as an exporttemplate
                // Microsoft.Office.Tools.Word.Document vstoDoc = Globals.Factory.GetVstoObject(doc);
                // vstoDoc.ContentControlOnExit -= new Word.DocumentEvents2_ContentControlOnExitEventHandler(vstoDoc_ContentControlOnExit);

                // Now step through the doc
                object start = doc.Content.Start;
                object end = doc.Content.End;
                Word.Range r = doc.Range(ref start, ref end);

                foreach (Word.ContentControl cc in r.ContentControls)
                {
                    string tag = cc.Tag;
                    if (tag != null && tag != "" && cc.Tag.Contains('|'))
                    {
                        string[] taga = cc.Tag.Split('|');

                        if ((taga[0] == "Element" && taga[1] != ""))
                        {
                            // Element tag is the format Element|ElementId|ClauseId

                            string ElementIdOld = taga[1].ToString();
                            string ClauseIdOld = taga[2].ToString();

                            // if its not in the mapping leave it be
                            if (ElementMapping.ContainsKey(ElementIdOld))
                            {
                                if (ClauseMapping.ContainsKey(ClauseIdOld))
                                {
                                    cc.Tag = "Element|" + ElementMapping[ElementIdOld] + "|" + ClauseMapping[ClauseIdOld];
                                }
                                else
                                {
                                    cc.Tag = "Element|" + ElementMapping[ElementIdOld];
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon01,代码行数:45,代码来源:ThisAddIn.cs

示例9: FindFirstAttachmentStyleByName

        static Wd.Range FindFirstAttachmentStyleByName(Wd.Document doc, Wd.Range range, Wd.Range result, string style)
        {
            if (doc.Styles.Exists(style))
            {
                Wd.Range search = range.Duplicate;
                if (result == null || !result.Find.Found)
                    search.End = doc.Range().End;
                else
                    search.End = result.Start;

                Wd.Range result_temp = search.Find(null, doc.Styles[style]);

                if (result_temp.Find.Found && (result == null || result.Start > result_temp.Start))
                    return result_temp;
            }
            return result;
        }
开发者ID:beachandbytes,项目名称:GorillaDocs,代码行数:17,代码来源:TableOfContentsHelper.cs

示例10: next_occur

        private void next_occur(Word._Document oDoc, string search_font, ref int start_pos, ref int end_pos)
        {
            Word.Range oRange;
            Word.Font oFont;
            int length, pos;
            object position;

            length = oDoc.Characters.Count;
            if (end_pos == (length-1))
                pos = 0;
            else
                pos = end_pos;

            // find the beginning of the next occurance of the search font

            while (true)
            {
                position = pos;
                oRange = oDoc.Range(ref position, ref position);
                oFont = oRange.Font;
                if (oFont.Name.Equals(search_font))
                   break;
                else
                    pos++;
                if (pos == length)
                    pos = 0;
            }

            start_pos = pos;

            // find the end of this occurance

            while (true)
            {
                position = pos;
                oRange = oDoc.Range(ref position, ref position);
                oFont = oRange.Font;
                if (!oFont.Name.Equals(search_font))
                    break;
                else
                    pos++;
                if (pos == length)
                {
                    pos--;
                    break;
                }
            }

            end_pos = pos;

            return;
        }
开发者ID:kamwoods,项目名称:FontAnalysis,代码行数:52,代码来源:DocSearchForm.cs

示例11: Create

        public ResultType_enum Create(Document document, Word.Application application, out Word._Document doc, out string message)
        {
            try
            {
                isWork = true;
                message = "";

                Object trueObj = true;
                Object falseObj = false;
                Object begin = Type.Missing;
                Object end = Type.Missing;
                doc = null;

                // если вылетим не этом этапе, приложение останется открытым
                try
                {
                    doc = application.Documents.Add(ref missingObj, ref missingObj, ref missingObj, ref missingObj);
                    // Общий Стиль
                    object patternstyle = Word.WdStyleType.wdStyleTypeParagraph;
                    Word.Style wordstyle = doc.Styles.Add("myStyle", ref patternstyle);
                    wordstyle.Font.Size = 9;
                    wordstyle.Font.Name = "Times New Roman";
                    Word.Range wordrange = doc.Range(ref begin, ref end);
                    object oWordStyle = wordstyle;
                    wordrange.set_Style(ref oWordStyle);

                    // Вставляем параграфы
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);

                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);

                    doc.Paragraphs[1].Range.Text = "«Утверждаю»";
                    doc.Paragraphs[1].Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    doc.Paragraphs[1].Range.ParagraphFormat.LeftIndent = 300;
                    doc.Paragraphs[1].Range.ParagraphFormat.LineSpacing = 11;
                    doc.Paragraphs[1].SpaceAfter = 0;
                    doc.Paragraphs[1].SpaceBefore = 0;
                    doc.Paragraphs[2].LineUnitAfter = 0;
                    doc.Paragraphs[2].LineUnitBefore = 0;
                    doc.Paragraphs[3].LineUnitAfter = 0;
                    doc.Paragraphs[3].LineUnitBefore = 0;
                    doc.Paragraphs[4].LineUnitAfter = 0;
                    doc.Paragraphs[4].LineUnitBefore = 0;

                    doc.Paragraphs[2].Range.Text = "Руководитель";
                    doc.Paragraphs[2].Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    doc.Paragraphs[2].Range.ParagraphFormat.LeftIndent = 300;

                    doc.Paragraphs[4].Range.Text = "Форма 2. Сведения о качестве, технических характеристиках товара, его безопасности, функциональных характеристиках (потребительских свойствах) товара, размере и иные сведения о товаре, представление которых предусмотрено документацией об аукционе в электронной форме";
                    doc.Paragraphs[4].Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;

                    // Подсчитываем количество строк у продуктов (потому что одно свойство продукта занимает одну строку)
                    int propertiesCount = 0;
                    foreach (Product product in document.Products)
                    {
                        var myTemplate = product.Templates.FirstOrDefault(m => m.Name.Trim().ToLower() == "форма 2");
                        IEnumerable<Property> productProperties = product.Properties.SelectMany(m => m.ParamValues.Where(p => myTemplate.Param.Contains(p.Param))).Select(f => f.Property).Distinct();

                        propertiesCount += productProperties.Count();
                    }

                    Object defaultTableBehavior =
                     Word.WdDefaultTableBehavior.wdWord9TableBehavior;
                    Object autoFitBehavior =
                     Word.WdAutoFitBehavior.wdAutoFitWindow;
                    Word.Table wordtable = doc.Tables.Add(doc.Paragraphs[5].Range, 3 + propertiesCount, 8,
                      ref defaultTableBehavior, ref autoFitBehavior);

                    // Объединение ячеек
                    object begCell = wordtable.Cell(1, 1).Range.Start;
                    object endCell = wordtable.Cell(2, 1).Range.End;
                    Word.Range wordcellrange = doc.Range(ref begCell, ref endCell);
                    wordcellrange.Select();
                    application.Selection.Cells.Merge();

                    begCell = wordtable.Cell(1, 2).Range.Start;
                    endCell = wordtable.Cell(2, 2).Range.End;
                    wordcellrange = doc.Range(ref begCell, ref endCell);
                    wordcellrange.Select();
                    application.Selection.Cells.Merge();

                    begCell = wordtable.Cell(1, 3).Range.Start;
                    endCell = wordtable.Cell(2, 3).Range.End;
                    wordcellrange = doc.Range(ref begCell, ref endCell);
                    wordcellrange.Select();
                    application.Selection.Cells.Merge();

                    begCell = wordtable.Cell(1, 4).Range.Start;
                    endCell = wordtable.Cell(1, 6).Range.End;
                    wordcellrange = doc.Range(ref begCell, ref endCell);
                    wordcellrange.Select();
                    application.Selection.Cells.Merge();
//.........这里部分代码省略.........
开发者ID:BrickProd,项目名称:PublicOrders,代码行数:101,代码来源:Form2Processor.cs

示例12: GetAmendmentDocumentInsertPosition

        private static Word.Range GetAmendmentDocumentInsertPosition(List<AmendClause> clauses, int orderNumber, Word.Document amend)
        {
            Word.Range insPosition = null;

            int insertAfter = 0;
            // Sor the list before doing this
            object wdth = Environment.NewLine.Length;
            for (int i = 0; i < clauses.Count; i++)
            {
                if (clauses[i].InitialPosition > orderNumber)
                {
                    insertAfter = clauses[i].InitialPosition;
                    Word.Range rng = amend.Range(clauses[i].Clause.Range.Start - 1, clauses[i].Clause.Range.End);
                    rng.InsertBefore(Environment.NewLine);
                    insPosition = clauses[i].Clause.Range.Previous(Word.WdUnits.wdCharacter, ref wdth);
                    return insPosition;
                }
            }
            return null;
        }
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon,代码行数:20,代码来源:CompareAmendment.xaml.cs

示例13: subjectSpot

 /// <summary>
 /// 在指定范围内匹配,如果范围的start、end都为0,则在整个文件匹配
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="progressBarSpot"></param>
 /// <param name="matchArray"></param>
 /// <param name="start">指定范围的起始</param>
 /// <param name="end">指定范围的结束</param>
 /// <param name="prelength">前缀长度</param>
 /// <returns></returns>
 public List<SubjectInfo> subjectSpot(Word.Document doc, ref ProgressBar progressBarSpot, string[] matchArray, int start, int end)
 {
     List<SubjectInfo> list = new List<SubjectInfo>();
     object start1 = start;
     object end1 = end;
     int count = 0;//总共有多少段落
     //int prelength = 0;//匹配题目前缀如(1、)的长度用于截断
     if (start == 0 && end == 0)
     {
         count = doc.Paragraphs.Count;//针对整个文件统计数据行数
     }
     else
     {
         count = doc.Range(ref start1, ref end1).Paragraphs.Count;//正对选定的部分统计数据行数
     }
     for (int i = 0; i < count; i++)
     {
         string text = "";
         if (start == 0 && end == 0)
         {
             text = doc.Paragraphs[i + 1].Range.Text;
         }
         else
         {
             text = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Text;
         }
         if (text.ToString().Length > 1)//通过字段长度过滤来提高性能;
         {
             if (start == 0 && end == 0)//取整个文本中对应行的数据
             {
                 try
                 {
                     doc.Paragraphs[i + 1].Range.Copy();
                     text = ClipboardHelper.getClipboardText();//取整个文本中对应行的数据
                 }
                 catch
                 {
                     text = doc.Paragraphs[i + 1].Range.Text;//取整个文本中对应行的数据
                 }
             }
             else//取整个文本中选择的文本中对应行的数据
             {
                 try
                 {
                     doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Copy();
                     text = ClipboardHelper.getClipboardText();
                 }
                 catch
                 {
                     text = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Text;
                 }
             }
             if (MatchContent.match(matchArray, text))
             {
                 SubjectInfo si = new SubjectInfo();
                 si.paragraphsNum = i;
                 if (start == 0 && end == 0)
                 {
                     si.paragraphsStart = doc.Paragraphs[i + 1].Range.Start;
                     si.paragraphsEnd = doc.Paragraphs[i + 1].Range.End;
                 }
                 else
                 {
                     si.paragraphsStart = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Start;
                     si.paragraphsEnd = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.End;
                 }
                 if (checkThisContentIsInTable(si.paragraphsStart, doc))//判断是否在表格范围
                 {
                     list.Add(si);
                 }
             }
         }
     }
     //排序题目信息(SubjectInfo)列表
     list.Sort(CompareSubJectInfo);
     return list;
 }
开发者ID:Kristd,项目名称:backup,代码行数:87,代码来源:MartianSpot.cs

示例14: Create

        public ResultType_enum Create(Document document, Word.Application application, out Word._Document doc, out string message)
        {
            try
            {
                isWork = true;
                message = "";

                Object trueObj = true;
                Object falseObj = false;
                Object begin = Type.Missing;
                Object end = Type.Missing;
                doc = null;

                // если вылетим не этом этапе, приложение останется открытым
                try
                {
                    doc = application.Documents.Add(ref missingObj, ref missingObj, ref missingObj, ref missingObj);
                    // Стиль
                    object patternstyle = Word.WdStyleType.wdStyleTypeParagraph;
                    Word.Style wordstyle = doc.Styles.Add("myStyle", ref patternstyle);
                    wordstyle.Font.Size = 9;
                    wordstyle.Font.Name = "Times New Roman";
                    Word.Range wordrange = doc.Range(ref begin, ref end);
                    object oWordStyle = wordstyle;
                    wordrange.set_Style(ref oWordStyle);

                    // Вставляем параграфы
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);

                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);
                    doc.Paragraphs.Add(ref missingObj);

                    doc.Paragraphs[1].Range.Text = "Приложение № 3";
                    doc.Paragraphs[1].Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    doc.Paragraphs[1].Range.ParagraphFormat.LeftIndent = 300;
                    doc.Paragraphs[1].Range.ParagraphFormat.LineSpacing = 11;
                    doc.Paragraphs[1].SpaceAfter = 0;
                    doc.Paragraphs[1].SpaceBefore = 0;
                    doc.Paragraphs[2].LineUnitAfter = 0;
                    doc.Paragraphs[2].LineUnitBefore = 0;
                    doc.Paragraphs[3].LineUnitAfter = 0;
                    doc.Paragraphs[3].LineUnitBefore = 0;
                    doc.Paragraphs[4].LineUnitAfter = 0;
                    doc.Paragraphs[4].LineUnitBefore = 0;

                    doc.Paragraphs[2].Range.Text = "к Техническому заданию";
                    doc.Paragraphs[2].Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    doc.Paragraphs[2].Range.ParagraphFormat.LeftIndent = 300;

                    doc.Paragraphs[4].Range.Text = "СВЕДЕНИЯ О КАЧЕСТВЕ, ТЕХНИЧЕСКИХ ХАРАКТЕРИСТИКАХ ТОВАРА, ЕГО БЕЗОПАСНОСТИ, ФУНКЦИОНАЛЬНЫХ ХАРАКТЕРИСТИКАХ (ПОТРЕБИТЕЛЬСКИХ СВОЙСТВАХ) ТОВАРА, РАЗМЕРЕ, УПАКОВКЕ, ОТГРУЗКЕ ТОВАРА И ИНЫЕ СВЕДЕНИЯ О ТОВАРЕ, ПРЕДСТАВЛЕНИЕ КОТОРЫХ ПРЕДУСМОТРЕНО ДОКУМЕНТАЦИЕЙ ОБ АУКЦИОНЕ В ЭЛЕКТРОННОЙ ФОРМЕ";
                    doc.Paragraphs[4].Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;

                    // Подсчитываем количество строк у продуктов (потому что одно свойство продукта занимает одну строку)
                    int propertiesCount = 0;
                    foreach (Product product in document.Products)
                    {
                        var myTemplate = product.Templates.FirstOrDefault(m => m.Name.Trim().ToLower() == "комитет");
                        IEnumerable<Property> productProperties = product.Properties.SelectMany(m => m.ParamValues.Where(p => myTemplate.Param.Contains(p.Param))).Select(f => f.Property).Distinct();

                        propertiesCount += productProperties.Count();
                    }

                    Object defaultTableBehavior =
                     Word.WdDefaultTableBehavior.wdWord9TableBehavior;
                    Object autoFitBehavior =
                     Word.WdAutoFitBehavior.wdAutoFitWindow;
                    Word.Table wordtable = doc.Tables.Add(doc.Paragraphs[5].Range, 1 + propertiesCount, 9,
                      ref defaultTableBehavior, ref autoFitBehavior);

                    // Заполнение заголовка
                    doc.Tables[1].Cell(1, 1).Range.Text = "№ п/п";
                    doc.Tables[1].Cell(1, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    doc.Tables[1].Cell(1, 2).Range.Text = "Наименование товара";
                    doc.Tables[1].Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    doc.Tables[1].Cell(1, 3).Range.Text = "Наименование показателя";
                    doc.Tables[1].Cell(1, 3).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    doc.Tables[1].Cell(1, 4).Range.Text = "Минимальные значения показателей";
                    doc.Tables[1].Cell(1, 4).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    doc.Tables[1].Cell(1, 5).Range.Text = "Максимальные значения показателей";
                    doc.Tables[1].Cell(1, 5).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    doc.Tables[1].Cell(1, 6).Range.Text = "Значения показателей, которые не могут изменяться";
                    doc.Tables[1].Cell(1, 6).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    doc.Tables[1].Cell(1, 7).Range.Text = "Конкретные показатели используемого товара, соответствующие значениям, установленным документацией, предлагаемые участником закупки";
                    doc.Tables[1].Cell(1, 7).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    doc.Tables[1].Cell(1, 8).Range.Text = "Единица измерения";
                    doc.Tables[1].Cell(1, 8).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    doc.Tables[1].Cell(1, 9).Range.Text = "Товарный знак";
                    doc.Tables[1].Cell(1, 9).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;

                    // Заполнение продуктами
                    int productIndexCompilator = 0;
                    int propertyIndexCompilator = 0;
                    for (int i = 0; i < propertiesCount; i++)
//.........这里部分代码省略.........
开发者ID:BrickProd,项目名称:PublicOrders,代码行数:101,代码来源:CommitteeProcessor.cs

示例15: UnlockContractConcept

        public void UnlockContractConcept(string conceptid,Word.Document doc)
        {
            //Is it one of ours
            if (isContract(doc))
            {
                //Remove the handler
                Microsoft.Office.Tools.Word.Document vstoDoc = Globals.Factory.GetVstoObject(doc);
                vstoDoc.ContentControlOnExit -= new Word.DocumentEvents2_ContentControlOnExitEventHandler(vstoDoc_ContentControlOnExit);

                string contractid = GetDocId(doc);

                //Now step through the doc
                object start = doc.Content.Start;
                object end = doc.Content.End;
                Word.Range r = doc.Range(ref start, ref end);

                Word.ContentControl[] ccs = new Word.ContentControl[r.ContentControls.Count];
                foreach (Word.ContentControl cc in r.ContentControls)
                {
                    string tag = cc.Tag;
                    if (tag != null && tag != "" && cc.Tag.Contains('|'))
                    {
                        string[] taga = cc.Tag.Split('|');
                        if (taga[0] == "Concept" && Convert.ToString(taga[1]) == conceptid)
                        {

                            // unlock the clause
                            cc.LockContents = false;
                            cc.LockContentControl = true;

                            // also have to unlock any other controls in the range
                            foreach (Word.ContentControl child in cc.Range.ContentControls)
                            {
                                if (child.ID != cc.ID)
                                {
                                    child.LockContents = false;
                                    child.LockContentControl = true;
                                }
                            }

                            // update the tag to set the modified to be unlocked so we know to load the clause
                            // from the database
                            cc.Tag = "Concept|" + taga[1].ToString() + "|" + taga[2].ToString() + "|" + "Unlocked";

                        }

                    }
                    //Add back in the handler
                    vstoDoc.ContentControlOnExit += new Word.DocumentEvents2_ContentControlOnExitEventHandler(vstoDoc_ContentControlOnExit);

                }
            }
        }
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon01,代码行数:53,代码来源:ThisAddIn.cs


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