Click here to Skip to main content
14,969,978 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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);

                //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.

Updated 2-May-17 4:18am

1 solution

As far as I know you need to set the Paragraph linespacing before getting the result or change it.

Selection.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle;
abdul subhan mohammed 2-May-17 10:24am
No, i'm not setting up the value, but, i'm comparing the value with the given value.
Wessel Beulink 2-May-17 10:43am
How do you know than that the given amount is in points? The documentation didn't describe the LineSpacing is in points only when rule is Single Or Multiple.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900