none
c#, word addin, richtext style and .. charts RRS feed

  • Question

  • Hello,

    I have 3 questions about word addin in vs 2013.

    1).

    I programmary add some richtext to document:

    editableControl = vstoDocument.Controls.AddRichTextContentControl(currentRange, "new_control");

    editableControl.PlaceholderText = "text text text ..."

    How i can make style to editableControl.PlaceholderText? Like bold, colors, fonts???

    2).

    I have sample word document. How i can programmary add line text in empty space in all lines?

    Like this screen: 

    https://dl.dropboxusercontent.com/u/11254269/akt_notarialny_ADDS_Sp._Z_o.o._str.2%5B1%5D.pdf

    3)

    How i can programmary close word application (document) in office 2007.

    In office 2010 and 2013 i can use: 

    Word._Document document = this.Application.ActiveDocument;

    document.Close(Word.WdSaveOptions.wdDoNotSaveChanges);

    But in office 2007 only close active document, but not application (winword.exe process)

    Regards,

    Daro





    • Moved by Amanda Zhu Tuesday, September 30, 2014 7:31 AM
    • Edited by d4rq000z Tuesday, September 30, 2014 12:18 PM
    Monday, September 29, 2014 1:49 PM

Answers

  • Hi,

    >>How i can make style to editableControl.PlaceholderText? Like bold, colors, fonts???<<

    We can use RichTextContentControl.Range Property to access the formatting of the text in the control and other text properties. Here is a sample below to set the Bold, Italic and font color property for your reference.

    editableControl.PlaceholderText = "text text text ...";
    editableControl.Range.Font.Bold = -1;
    editableControl.Range.Font.Italic = -1;
    editableControl.Range.Font.ColorIndex = Word.WdColorIndex.wdBrightGreen;
    editableControl.Range.Text = "Hello";

    >>How i can programmary add line text in empty space in all lines? <<

    I think you want to add line text behind the end of every paragraph, if so, you can move the cursor to the end of the paragraph with Selection.EndKey method and use Selection.TypeText Method to insert the specified text.

    Word.Document document = app.ActiveDocument; //app means current Word application
    for (int i = 1; i <= document.Paragraphs.Count; i++)
    {
        Word.Range rng = document.Paragraphs[i].Range;
        rng.Select();
        app.Selection.EndKey(Word.WdUnits.wdLine);
        app.Selection.TypeText("-------"); 
    }

    >>How i can programmary close word application (document) in office 2007.<<

    In Word Object Model, to close the Word application, we have to use Application.Quit Method. Document.Close method is used to close the specified document.

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 1, 2014 5:54 AM
    Moderator

All replies

  • Hi Daro,

    For your issue, Word for Developers forum is a better forum. I moved this thread to that forum, you will get better support there.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, September 30, 2014 7:32 AM
  • Hi,

    >>How i can make style to editableControl.PlaceholderText? Like bold, colors, fonts???<<

    We can use RichTextContentControl.Range Property to access the formatting of the text in the control and other text properties. Here is a sample below to set the Bold, Italic and font color property for your reference.

    editableControl.PlaceholderText = "text text text ...";
    editableControl.Range.Font.Bold = -1;
    editableControl.Range.Font.Italic = -1;
    editableControl.Range.Font.ColorIndex = Word.WdColorIndex.wdBrightGreen;
    editableControl.Range.Text = "Hello";

    >>How i can programmary add line text in empty space in all lines? <<

    I think you want to add line text behind the end of every paragraph, if so, you can move the cursor to the end of the paragraph with Selection.EndKey method and use Selection.TypeText Method to insert the specified text.

    Word.Document document = app.ActiveDocument; //app means current Word application
    for (int i = 1; i <= document.Paragraphs.Count; i++)
    {
        Word.Range rng = document.Paragraphs[i].Range;
        rng.Select();
        app.Selection.EndKey(Word.WdUnits.wdLine);
        app.Selection.TypeText("-------"); 
    }

    >>How i can programmary close word application (document) in office 2007.<<

    In Word Object Model, to close the Word application, we have to use Application.Quit Method. Document.Close method is used to close the specified document.

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 1, 2014 5:54 AM
    Moderator
  • Thx for help,

    Word.Document document = app.ActiveDocument; //app means current Word application
    for (int i = 1; i <= document.Paragraphs.Count; i++)
    {
        Word.Range rng = document.Paragraphs[i].Range;
        rng.Select();
        app.Selection.EndKey(Word.WdUnits.wdLine);
        app.Selection.TypeText("-------"); 
    }

    Its too short line, and doesnt work if i have richtext in line.

    I would like add line like the screen. That it takes an entire line in a row

    And ... i have one more question

    How i can change richtext to text?


    • Edited by d4rq000z Wednesday, October 8, 2014 3:29 PM
    Wednesday, October 8, 2014 10:51 AM
  • >>I would like add line like the screen. That it takes an entire line in a row

    I fail to write  such a code, you need to do more research or write it by yourself.

    Thursday, October 9, 2014 2:00 AM