-1

I want to create a document and auto fill it using C# program, however, I have to fill the white space in the end of each paragraphe for Eg: let's say this is my paragraphe >

John Albert is a famous singer, he used to sing Rap songs even when he was a 4 years old boy.

I want it to look like that :

John Albert is a famous singer, he used to sing Rap songs even when he was a 4 years old boy. .......................................................

so the blank spaces will be filled by a character I choose for now I can generate texts and add them to the documents using the XML tags, any help?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
  • It's not clear to me what you mean by "for now I can generate texts and add them to the documents using the XML tags". Do you mean you're working with the Open XML file format? – Cindy Meister Feb 19 '16 at 16:13
  • The only reliable thing you can do is to format the paragraphs with a right-aligned tab stop at the right margin that has a "dot leader". You can see this in Word: Home tab / dialog launcher in the Paragraphs group / Tabs button in the dialog box. Enter the tab position; Choose "Right" alignment; Choose one of the "leader" options. At the end of the paragraph, press Tab and you should see the line fill to the end with the leader you selected. Once you understand how it works and what you want, define this tab stop in the STYLE you use for the paragraphs. Have your code append "\t" to the text. – Cindy Meister Feb 19 '16 at 16:15
  • I will see if I can do it – Feelbad Soussi Wolfgun DZ Feb 19 '16 at 18:42

1 Answers1

0

Here is some VBA code to add dots at the end of each paragraph to fill up the last line of the paragraph. You see this a lot in legal documents. It even works if paragraphs have different margin positions:

Sub AddDotLeaderTabToParagraphs()

    Dim par As Word.Paragraph
    Dim rng As Range

    Dim tabposition As Integer
    Dim marginposition As Integer

    For i = 1 To ActiveDocument.Paragraphs.Count

        Set par = ActiveDocument.Paragraphs(i)

        With par.Range.PageSetup
             marginposition = .PageWidth - .LeftMargin - .RightMargin - .Gutter
        End With

        tabposition = marginposition - par.RightIndent

        par.Range.ParagraphFormat.TabStops.Add Position:=tabposition, Alignment:=wdAlignTabRight, Leader:=wdTabLeaderDots

        With par.Range
           .Collapse wdCollapseEnd

           If i < ActiveDocument.Paragraphs.Count Then
             .Move wdCharacter, -1
           End If

           .InsertAfter vbTab
        End With
     Next
End Sub
Maarten van Stam
  • 1,901
  • 1
  • 11
  • 16