locked
How to add indent to paragraph in Word processing application in C# RRS feed

  • Question

  • Hi,

    I try to create a word document in C# with code like,

                // Start a new Word application
                Word.Application oWord = new Word.Application();
    
                //Creating a new  Word document
                object oMissing = System.Reflection.Missing.Value;
                Word.Document oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    
                for (int i = 0; i < qSetList.Count; i++)
                {
                    // Add caption for each question set
                    Word.Paragraph questionSetCaption = oDoc.Paragraphs.Add(ref oMissing);
                    questionSetCaption.Range.Font.Name = "Calibri";
                    questionSetCaption.Range.Font.Size = 13;
                    questionSetCaption.Range.Font.Bold = 1;
                    questionSetCaption.Range.ParagraphFormat.SpaceAfter = 0.0F;
                    questionSetCaption.Range.Text = qSetList[i].Caption.ExportStringToWord();
                    questionSetCaption.Range.InsertParagraphAfter();
    
    

    My question is how to indent the paragraph. I try questionSetCaption.Range.ParagraphFormat.IndentCharWidth(), but it is not working. Thanks.


    York

    Wednesday, March 21, 2012 5:50 AM

Answers

  • ParagraphFormat.IndentFirstLineCharWidth  is still not working. But I figure it out by simply adding more space on each text. Thanks any way.


    York

    • Marked as answer by york Z Thursday, March 22, 2012 11:45 PM
    Thursday, March 22, 2012 11:45 PM

All replies

  • Hi york Z,

      You can try using ParagraphFormat.IndentFirstLineCharWidth Method ,it indents the first line of one or more paragraphs by a specified number of characters,and its related MSDN article is as follows:

    http://msdn.microsoft.com/en-us/library/ff834550.aspx

    Sincerely,

    Jason Wang



    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, March 22, 2012 5:22 AM
    Moderator
  • ParagraphFormat.IndentFirstLineCharWidth  is still not working. But I figure it out by simply adding more space on each text. Thanks any way.


    York

    • Marked as answer by york Z Thursday, March 22, 2012 11:45 PM
    Thursday, March 22, 2012 11:45 PM