Create some text under program control

[Top]  [Chapter]  [Previous]  [Next]


This demo creates a paragraph style "header" and applies to to every other paragraph. It also creates a table.





We first initialize the reference to our working interfaces Memo and TextCursor. 


  Dim Memo As IWPMemo

  Dim TextCursor As IWPTextCursor

  Set Memo = WPDLLInt1.Memo

  Set TextCursor = Memo.TextCursor



Now we make sure the mail merge markers, they are usually displayed as << and >> are hidden.


  WPDLLInt1.SpecialTextAttr(wpInsertpoints).Hidden = True

  WPDLLInt1.SpecialTextAttr(wpInsertpoints).CodeTextColor = 0

  WPDLLInt1.SpecialTextAttr(wpAutomaticText).BackgroundColor = &HE0E0E0 ' gray



And we clear the text.


  Memo.Clear false, false



Now create a text style called 'header'   


  Memo.SelectStyle "header"

  Memo.CurrStyleAttr.SetFontface "Times New Roman"

  Memo.CurrStyleAttr.SetFontSize 18



And create the header and initialize using HTML code. 


  TextCursor.InputHeader 0, "", "<html><center>Testreport <pagenr/> of <pagecount/>"



Clear writing attributes - otherwise the style is not used!




Create the text


  Memo.CurrPar.StyleName = "header"

  TextCursor.InputText "This is a header text"

  TextCursor.InputParagraph 0, ""

  TextCursor.InputText "Test"

  TextCursor.InputParagraph 0, ""

  TextCursor.InputText "Test"

  TextCursor.InputParagraph 0, "header"

  TextCursor.InputText "This is a header text"


Start with the table creation - here we use "InputTable"


  TextCursor.InputTable 5000, "AA" ' 50%

  TextCursor.InputRowStart 1

  TextCursor.InputCell "A", "header"

  TextCursor.InputParagraph 0, "header"

  TextCursor.InputText "Line 2"

  TextCursor.InputCell "B", "header"


Insert an image in a cell


  TextCursor.InputImage App.Path + "\..\demo.jpg", 0

  TextCursor.InputCell "C", "header"



Now create text after the table


  TextCursor.InputParagraph 0, ""

  TextCursor.InputText "more text"

  TextCursor.InputParagraph 0, ""

  TextCursor.InputText "name: "


And insert a merge field, initialized with a default name


  TextCursor.InputField "NAME", "Julian Ziersch", False


Format the text



[createsometextunderprogram.htm]    Copyright © 2007 by WPCubed GmbH