本文介绍了使用word interop C#评估单词中的段落行间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我们在winForm应用程序(C#)中自动化了MsOffice。我在哪里创建了一个评估段落行间距的方法。



在word文档中,会有段落,这个方法会找到行间距特定段落。



我已经从单词(手动)中将段落行间距设置为1.5。但是,当我调试代码时,我从该段落得到了linepacing的值是13.5,而不是1.5,这是出乎意料的。



我尝试过:



Dear All,

We are automating MsOffice in our winForm application(C#). Where I have create one method to "Evaluate the paragraph line spacing".

In the word document, there will be paragraphs and this method will find the line spacing from the specific paragraph.

I have set the paragraph line spacing to 1.5 from the word(Manually). But, When I debug the code, i was getting the value of linespacing from that Paragraph was "13.5", instead of 1.5, which was unexpected.

What I have tried:

<pre> public static bool FindLineSpacingInParagraph(IQuestion question, string filename, int paragraph, float lineSpacing)
        {
            WordInterop.Application wordApplication = GetOrCreateWordApplication(question.ObjectStore);

            try
            {
                //Avoid screen flickering or unwanted alerts while initializing
                wordApplication.ScreenUpdating = false;
                WordInterop.WdAlertLevel displayAlertLevel = wordApplication.DisplayAlerts;
                wordApplication.DisplayAlerts = WordInterop.WdAlertLevel.wdAlertsNone;

                WordInterop.Document wordDocument = wordApplication.Documents.Open(filename);


                if (paragraph >= wordDocument.Paragraphs.Count)
                    return false;

                WordInterop.Paragraph paragraphObject = wordDocument.Paragraphs[paragraph];
                if (paragraphObject == null)
                    return false;

                bool result = paragraphObject.LineSpacing == lineSpacing;//LineSpacing=13.5
                object save_changes = false;
                object missing = Type.Missing;
                wordDocument.Close(ref save_changes, ref missing, ref missing);
                return result;
            }
            catch (Exception)
            {
                Cleanup(question.ObjectStore, true);
            }
            return false;
        }







任何人都可以帮助我。



谢谢




Can anyone please help me.

Thanks

推荐答案

Selection.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle;


这篇关于使用word interop C#评估单词中的段落行间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:27