Beispiel #1
0
        public Import(IswItem topItem, List <SwParagraph> paragraphs, List <SwStyle> styles, List <SwStyle> description, string hostName, ThreadedWindowWrapper wrap)
        {
            LogToDescription("Importing from Office started at " + Convert.ToString(DateTime.Now));
            var             currentItem = topItem;
            List <WordItem> wordItems   = CreateWordItems(paragraphs, description);

            double progress = 0;
            double step     = (double)100 / (double)wordItems.Count;

            wrap.SetProgress(Convert.ToInt32(progress).ToString()); progress += step;

            int             handledItems        = 0;
            WdOutlineLevel  currentOutlineLevel = WdOutlineLevel.wdOutlineLevelBodyText;
            WdOutlineLevel  lastOutlineLevel    = 0;
            Stack <IswItem> parentItems         = new Stack <IswItem>();

            parentItems.Push(topItem);
            foreach (WordItem wordItem in wordItems)
            {
                if (wordItem.MainParagraph == null)
                {
                    topItem.Description = SWDescription.MakeDescription(SWUtility.RtfToRvfz(ConcatenateParagraphsRtf(wordItem.DescriptionParagraphs)));
                    continue;
                }
                currentOutlineLevel = wordItem.MainParagraph.OutlineLevel;

                if (currentOutlineLevel > lastOutlineLevel) // Sublevel -> Add to the stack
                {
                    currentItem = WriteItem(parentItems.Peek(), wordItem);
                    parentItems.Push(currentItem);
                }

                else // Higher level -> Remove items from the stack
                {
                    for (WdOutlineLevel i = currentOutlineLevel; (i <= lastOutlineLevel && parentItems.Count > 1); i++)
                    {
                        parentItems.Pop();
                    }
                    currentItem = WriteItem(parentItems.Peek(), wordItem);
                    parentItems.Push(currentItem);
                }

                lastOutlineLevel = currentOutlineLevel;

                wrap.SetProgress(Convert.ToInt32(progress).ToString()); progress += step;
                wrap.SetStatus(string.Format("Imported {0} paragraphs of {1}", ++handledItems, wordItems.Count));
            }
            LogToDescription("Script terminated gracefully at " + Convert.ToString(DateTime.Now));
            WriteLogToTopItem(topItem);
        }
        // 复制保存WORD.ParagraphFormat同名参数值
        public void clone(Word.ParagraphFormat srcParaFormat)
        {
            this.Alignment = srcParaFormat.Alignment;                         // 复制保存WORD.ParagraphFormat同名参数值

            this.AutoAdjustRightIndent = srcParaFormat.AutoAdjustRightIndent; // 复制保存WORD.ParagraphFormat同名参数值
            this.BaseLineAlignment     = srcParaFormat.BaseLineAlignment;     // 复制保存WORD.ParagraphFormat同名参数值

            //this.Borders.clone(srcParaFormat.Borders);// 复制保存WORD.ParagraphFormat同名参数值

            this.CharacterUnitFirstLineIndent = srcParaFormat.CharacterUnitFirstLineIndent;       // 复制保存WORD.ParagraphFormat同名参数值
            this.CharacterUnitLeftIndent      = srcParaFormat.CharacterUnitLeftIndent;            // 复制保存WORD.ParagraphFormat同名参数值
            this.CharacterUnitRightIndent     = srcParaFormat.CharacterUnitRightIndent;           // 复制保存WORD.ParagraphFormat同名参数值
            this.DisableLineHeightGrid        = srcParaFormat.DisableLineHeightGrid;              // 复制保存WORD.ParagraphFormat同名参数值
            this.FarEastLineBreakControl      = srcParaFormat.FarEastLineBreakControl;            // 复制保存WORD.ParagraphFormat同名参数值
            this.FirstLineIndent = srcParaFormat.FirstLineIndent;                                 // 复制保存WORD.ParagraphFormat同名参数值
            this.HalfWidthPunctuationOnTopOfLine = srcParaFormat.HalfWidthPunctuationOnTopOfLine; // 复制保存WORD.ParagraphFormat同名参数值
            this.HangingPunctuation = srcParaFormat.HangingPunctuation;                           // 复制保存WORD.ParagraphFormat同名参数值
            this.Hyphenation        = srcParaFormat.Hyphenation;                                  // 复制保存WORD.ParagraphFormat同名参数值
            this.KeepTogether       = srcParaFormat.KeepTogether;                                 // 复制保存WORD.ParagraphFormat同名参数值
            this.KeepWithNext       = srcParaFormat.KeepWithNext;                                 // 复制保存WORD.ParagraphFormat同名参数值
            this.LeftIndent         = srcParaFormat.LeftIndent;                                   // 复制保存WORD.ParagraphFormat同名参数值
            this.LineSpacing        = srcParaFormat.LineSpacing;                                  // 复制保存WORD.ParagraphFormat同名参数值
            this.LineSpacingRule    = srcParaFormat.LineSpacingRule;                              // 复制保存WORD.ParagraphFormat同名参数值
            this.LineUnitAfter      = srcParaFormat.LineUnitAfter;                                // 复制保存WORD.ParagraphFormat同名参数值
            this.LineUnitBefore     = srcParaFormat.LineUnitBefore;                               // 复制保存WORD.ParagraphFormat同名参数值
            this.MirrorIndents      = srcParaFormat.MirrorIndents;                                // 复制保存WORD.ParagraphFormat同名参数值
            this.OutlineLevel       = srcParaFormat.OutlineLevel;                                 // 复制保存WORD.ParagraphFormat同名参数值
            this.NoLineNumber       = srcParaFormat.NoLineNumber;                                 // 复制保存WORD.ParagraphFormat同名参数值
            this.PageBreakBefore    = srcParaFormat.PageBreakBefore;                              // 复制保存WORD.ParagraphFormat同名参数值
            this.ReadingOrder       = srcParaFormat.ReadingOrder;                                 // 复制保存WORD.ParagraphFormat同名参数值
            this.RightIndent        = srcParaFormat.RightIndent;                                  // 复制保存WORD.ParagraphFormat同名参数值

            // this.Shading = srcParaFormat.Shading;
            //this.Shading.clone(srcParaFormat.Shading);

            this.SpaceAfter      = srcParaFormat.SpaceAfter;      // 复制保存WORD.ParagraphFormat同名参数值
            this.SpaceAfterAuto  = srcParaFormat.SpaceAfterAuto;  // 复制保存WORD.ParagraphFormat同名参数值
            this.SpaceBefore     = srcParaFormat.SpaceBefore;     // 复制保存WORD.ParagraphFormat同名参数值
            this.SpaceBeforeAuto = srcParaFormat.SpaceBeforeAuto; // 复制保存WORD.ParagraphFormat同名参数值

            // this.TabStops = srcParaFormat.TabStops;

            this.TextboxTightWrap = srcParaFormat.TextboxTightWrap; // 复制保存WORD.ParagraphFormat同名参数值
            this.WidowControl     = srcParaFormat.WidowControl;     // 复制保存WORD.ParagraphFormat同名参数值
            this.WordWrap         = srcParaFormat.WordWrap;         // 复制保存WORD.ParagraphFormat同名参数值

            return;
        }
Beispiel #3
0
        private List <String> _search2()
        {
            Document   this_doc = Globals.ThisAddIn.Application.ActiveDocument;
            Paragraphs pars     = this_doc.Paragraphs;

            List <String>  draft_list = new List <String>();
            WdOutlineLevel level      = WdOutlineLevel.wdOutlineLevel1;



            //if (type == 1)
            //{
            //    reg = reLevel1;
            //    level = WdOutlineLevel.wdOutlineLevel1;
            //}
            //else
            //{
            //    reg = reLevel2;
            //    level = WdOutlineLevel.wdOutlineLevel2;
            //}

            foreach (Paragraph par in pars)
            {
                String line   = par.Range.Text.Trim();
                Match  match1 = reLevel1.Match(line);
                Match  match2 = reLevel2.Match(line);
                if (match1.Success)
                {
                    String b = match1.Groups[0].ToString();
                    draft_list.Add(line);
                }
                else if (match2.Success)
                {
                    String b = match2.Groups[0].ToString();
                    draft_list.Add(line);
                }

                //if (par.OutlineLevel == level)
                //{
                //    draft_list.Add(line);
                //}
            }
            return(draft_list);
        }
Beispiel #4
0
        private List <String> _search()
        {
            Document   this_doc = Globals.ThisAddIn.Application.ActiveDocument;
            Paragraphs pars     = this_doc.Paragraphs;

            List <String>  draft_list = new List <String>();
            Regex          reg        = null;
            WdOutlineLevel level      = WdOutlineLevel.wdOutlineLevel1;

            if (type == 1)
            {
                reg   = reLevel1;
                level = WdOutlineLevel.wdOutlineLevel1;
            }
            else
            {
                reg   = reLevel2;
                level = WdOutlineLevel.wdOutlineLevel2;
            }

            foreach (Paragraph par in pars)
            {
                String line  = par.Range.Text.Trim();
                Match  match = reg.Match(line);
                if (match.Success)
                {
                    String b = match.Groups[0].ToString();
                    draft_list.Add(line);
                }

                if (par.OutlineLevel == level)
                {
                    draft_list.Add(line);
                }
            }
            return(draft_list);
        }
        public int decodeFromString(Hashtable hashFeatures)
        {
            if (hashFeatures == null || hashFeatures.Count == 0)
            {
                return(1);
            }

            String strVal = "";
            int    nVal = 0, nDefaultVal = 0;
            float  fVal = 0.0f;

            strVal = (String)hashFeatures["ParaFmt_AddSpaceBetweenFarEastAndAlpha"];
            if (int.TryParse(strVal, out nVal))
            {
                AddSpaceBetweenFarEastAndAlpha = nVal;
            }
            else
            {
                AddSpaceBetweenFarEastAndAlpha = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_AddSpaceBetweenFarEastAndDigit"];
            if (int.TryParse(strVal, out nVal))
            {
                AddSpaceBetweenFarEastAndDigit = nVal;
            }
            else
            {
                AddSpaceBetweenFarEastAndDigit = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_Alignment"];
            if (int.TryParse(strVal, out nVal))
            {
                Alignment = (WdParagraphAlignment)nVal;
            }
            else
            {
                Alignment = WdParagraphAlignment.wdAlignParagraphDistribute;
            }

            strVal = (String)hashFeatures["ParaFmt_AutoAdjustRightIndent"];
            if (int.TryParse(strVal, out nVal))
            {
                AutoAdjustRightIndent = nVal;
            }
            else
            {
                AutoAdjustRightIndent = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_BaseLineAlignment"];
            if (int.TryParse(strVal, out nVal))
            {
                BaseLineAlignment = (WdBaselineAlignment)nVal;
            }
            else
            {
                BaseLineAlignment = WdBaselineAlignment.wdBaselineAlignAuto;
            }

            strVal = (String)hashFeatures["ParaFmt_CharacterUnitFirstLineIndent"];
            if (float.TryParse(strVal, out fVal))
            {
                CharacterUnitFirstLineIndent = fVal;
            }
            else
            {
                CharacterUnitFirstLineIndent = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_CharacterUnitLeftIndent"];
            if (float.TryParse(strVal, out fVal))
            {
                CharacterUnitLeftIndent = fVal;
            }
            else
            {
                CharacterUnitLeftIndent = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_CharacterUnitRightIndent"];
            if (float.TryParse(strVal, out fVal))
            {
                CharacterUnitRightIndent = fVal;
            }
            else
            {
                CharacterUnitRightIndent = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_DisableLineHeightGrid"];
            if (int.TryParse(strVal, out nVal))
            {
                DisableLineHeightGrid = nVal;
            }
            else
            {
                DisableLineHeightGrid = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_FarEastLineBreakControl"];
            if (int.TryParse(strVal, out nVal))
            {
                FarEastLineBreakControl = nVal;
            }
            else
            {
                FarEastLineBreakControl = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_FirstLineIndent"];
            if (float.TryParse(strVal, out fVal))
            {
                FirstLineIndent = fVal;
            }
            else
            {
                FirstLineIndent = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_HalfWidthPunctuationOnTopOfLine"];
            if (int.TryParse(strVal, out nVal))
            {
                HalfWidthPunctuationOnTopOfLine = nVal;
            }
            else
            {
                HalfWidthPunctuationOnTopOfLine = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_HangingPunctuation"];
            if (int.TryParse(strVal, out nVal))
            {
                HangingPunctuation = nVal;
            }
            else
            {
                HangingPunctuation = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_Hyphenation"];
            if (int.TryParse(strVal, out nVal))
            {
                Hyphenation = nVal;
            }
            else
            {
                Hyphenation = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_KeepTogether"];
            if (int.TryParse(strVal, out nVal))
            {
                KeepTogether = nVal;
            }
            else
            {
                KeepTogether = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_KeepWithNext"];
            if (int.TryParse(strVal, out nVal))
            {
                KeepWithNext = nVal;
            }
            else
            {
                KeepWithNext = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_LeftIndent"];
            if (float.TryParse(strVal, out fVal))
            {
                LeftIndent = fVal;
            }
            else
            {
                LeftIndent = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_LineSpacing"];
            if (float.TryParse(strVal, out fVal))
            {
                LineSpacing = fVal;
            }
            else
            {
                LineSpacing = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_LineSpacingRule"];
            if (int.TryParse(strVal, out nVal))
            {
                LineSpacingRule = (WdLineSpacing)nVal;
            }
            else
            {
                LineSpacingRule = WdLineSpacing.wdLineSpaceSingle;
            }

            strVal = (String)hashFeatures["ParaFmt_LineUnitAfter"];
            if (float.TryParse(strVal, out fVal))
            {
                LineUnitAfter = fVal;
            }
            else
            {
                LineUnitAfter = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_LineUnitBefore"];
            if (float.TryParse(strVal, out fVal))
            {
                LineUnitBefore = fVal;
            }
            else
            {
                LineUnitBefore = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_MirrorIndents"];
            if (int.TryParse(strVal, out nVal))
            {
                MirrorIndents = nVal;
            }
            else
            {
                MirrorIndents = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_NoLineNumber"];
            if (int.TryParse(strVal, out nVal))
            {
                NoLineNumber = nVal;
            }
            else
            {
                NoLineNumber = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_OutlineLevel"];
            if (int.TryParse(strVal, out nVal))
            {
                OutlineLevel = (WdOutlineLevel)nVal;
            }
            else
            {
                OutlineLevel = WdOutlineLevel.wdOutlineLevelBodyText;
            }

            strVal = (String)hashFeatures["ParaFmt_PageBreakBefore"];
            if (int.TryParse(strVal, out nVal))
            {
                PageBreakBefore = nVal;
            }
            else
            {
                PageBreakBefore = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_ReadingOrder"];
            if (int.TryParse(strVal, out nVal))
            {
                ReadingOrder = (WdReadingOrder)nVal;
            }
            else
            {
                ReadingOrder = WdReadingOrder.wdReadingOrderLtr;
            }

            strVal = (String)hashFeatures["ParaFmt_RightIndent"];
            if (float.TryParse(strVal, out fVal))
            {
                RightIndent = fVal;
            }
            else
            {
                RightIndent = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_SpaceAfter"];
            if (float.TryParse(strVal, out fVal))
            {
                SpaceAfter = fVal;
            }
            else
            {
                SpaceAfter = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_SpaceAfterAuto"];
            if (int.TryParse(strVal, out nVal))
            {
                SpaceAfterAuto = nVal;
            }
            else
            {
                SpaceAfterAuto = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_SpaceBefore"];
            if (float.TryParse(strVal, out fVal))
            {
                SpaceBefore = fVal;
            }
            else
            {
                SpaceBefore = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_SpaceBeforeAuto"];
            if (int.TryParse(strVal, out nVal))
            {
                SpaceBeforeAuto = nVal;
            }
            else
            {
                SpaceBeforeAuto = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_TextboxTightWrap"];
            if (int.TryParse(strVal, out nVal))
            {
                TextboxTightWrap = (WdTextboxTightWrap)nVal;
            }
            else
            {
                TextboxTightWrap = WdTextboxTightWrap.wdTightNone;
            }

            strVal = (String)hashFeatures["ParaFmt_WidowControl"];
            if (int.TryParse(strVal, out nVal))
            {
                WidowControl = nVal;
            }
            else
            {
                WidowControl = nDefaultVal;
            }

            strVal = (String)hashFeatures["ParaFmt_WordWrap"];
            if (int.TryParse(strVal, out nVal))
            {
                WordWrap = nVal;
            }
            else
            {
                WordWrap = nDefaultVal;
            }

            return(0);
        }