locked
How to use coordinate to insert text? RRS feed

  • Question

  • Hi everyone, I want to insert some texts to word in exact place of the page,I use C# . Any way to measure the coordinate and insert? Thanks.
    Wednesday, May 6, 2015 2:37 AM

Answers

  • if you are content with the more simple sentence, rather than lines:

    ActiveDocument.Sentences(1).Characters(5).Select
    Selection.Collapse
    Selection.InsertBefore "added "


    Five paragraphs and 50 spaces in VBA

    Selection.Text = String(5, vbCrLf) 
    Selection.Collapse wdCollapseEnd
    Selection.Text = String(50, " ")

    However, for a particular position, I would prefer a textbox:

    Set sh = doc.Shapes.AddTextbox(1, 10, 344, 575, 80)
    sh.Name = "Course1"

    With some properties:

    sh.Fill.Visible = False
    sh.Line.Visible = False
    sh.TextFrame.MarginLeft = 0#
    sh.TextFrame.MarginRight = 0#
    sh.TextFrame.MarginTop = 0#
    sh.TextFrame.MarginBottom = 0#


    • Edited by jujubeee Wednesday, May 6, 2015 2:41 AM Fix spell
    • Marked as answer by L.Hl Tuesday, May 19, 2015 12:00 AM
    Wednesday, May 6, 2015 2:41 AM

All replies

  • if you are content with the more simple sentence, rather than lines:

    ActiveDocument.Sentences(1).Characters(5).Select
    Selection.Collapse
    Selection.InsertBefore "added "


    Five paragraphs and 50 spaces in VBA

    Selection.Text = String(5, vbCrLf) 
    Selection.Collapse wdCollapseEnd
    Selection.Text = String(50, " ")

    However, for a particular position, I would prefer a textbox:

    Set sh = doc.Shapes.AddTextbox(1, 10, 344, 575, 80)
    sh.Name = "Course1"

    With some properties:

    sh.Fill.Visible = False
    sh.Line.Visible = False
    sh.TextFrame.MarginLeft = 0#
    sh.TextFrame.MarginRight = 0#
    sh.TextFrame.MarginTop = 0#
    sh.TextFrame.MarginBottom = 0#


    • Edited by jujubeee Wednesday, May 6, 2015 2:41 AM Fix spell
    • Marked as answer by L.Hl Tuesday, May 19, 2015 12:00 AM
    Wednesday, May 6, 2015 2:41 AM
  • Hi everyone, I want to insert some texts to word in exact place of the page,I use C# . Any way to measure the coordinate and insert? Thanks.

    Hi 

    You can append a text box and then append text in it,the set the distance to the margin in vertical and horizon.

    recommend u a useful professonal Doc library,download and add reference to your project then refer the following code:

    Document doc = new Document();
                Section sec = doc.AddSection();
                Paragraph par = sec.AddParagraph();
                Spire.Doc.Fields.TextBox textBox = par.AppendTextBox(50,50);
                Paragraph par1 = textBox.Body.AddParagraph();
                par1.AppendText("Hello, world");
                textBox.Format.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
                textBox.Format.VerticalOrigin = VerticalOrigin.Margin;
                textBox.Format.VerticalPosition = 200;
                textBox.Format.HorizontalOrigin = HorizontalOrigin.Margin;
                textBox.Format.HorizontalPosition = 100;
                textBox.Format.LineColor = Color.White;
                doc.SaveToFile("result.docx", FileFormat.Docx);

    Wednesday, May 6, 2015 2:49 AM