How to add text vertically into a Word margin with C# (using namespace: Microsoft.Office.Interop.Word)

I need to add text vertically in a word document outside the margins.  How can I do this with Microsoft.Office.Interop.Word and C#?
Leonard Swarczinski Software Developer Postal Center International

Hi Leonard,
According to your description, do you want to add text vertically into Page Header/Footer? I wrote a sample  for you.
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AddTextToWord
class Program
static void Main(string[] args)
CreateNewDocument();
Console.ReadLine();
private static void CreateNewDocument()
Object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application oWord;
Microsoft.Office.Interop.Word.Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
String HeaderText = "Hello everyone!";
WdParagraphAlignment wdAlign = WdParagraphAlignment.wdAlignParagraphCenter;
AddHeader1(oWord, HeaderText, wdAlign);
private static void AddHeader1(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign)
Object oMissing = System.Reflection.Missing.Value;
WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
Microsoft.Office.Interop.Word.Shape textBox = WordApp.ActiveDocument.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationVertical, 150, 10, 40, 40);
textBox.TextFrame.TextRange.Text = HeaderText;
WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;
If I misunderstood or anything wrong, please let me know and you can get more information from below articles.
Office development in Visual Studio
http://msdn.microsoft.com/en-us/office/hh133430.aspx
Abhout: AddTextbox Method
http://msdn.microsoft.com/en-us/library/office/aa171543(v=office.11).aspx
How to: Programmatically Insert Text into Word Documents
http://msdn.microsoft.com/en-us/library/vstudio/6b9478cs.aspx

Similar Messages

  • Microsoft.Office.Interop.Word error on Windows Server 2008 R2

    Hi,
    I have Microsoft Office 2003 installed on Windows Server 2008 R2. I get a "There is insufficient memory. Save the document now." error while adding a document to the Microsoft.Office.Interop.Word.Document class as in the code below. I can see the Memory
    consumption shoots up as soon as the following lines of code is executed. Surprisingly, this same piece of code works fine on Windows Server 2008.
    Object missing = System.Reflection.Missing.Value;
    Object oFalse = false;
    Microsoft.Office.Interop.Word.Application oWord = new Application();
    Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
    oWordDoc = oWord.Documents.Add(ref missing, ref missing, ref missing, ref missing); //The code fails here
    oWordDoc.Close(ref oFalse, ref missing, ref missing);
    oWord.Quit(ref missing, ref missing, ref missing);
    Can someone help on this?
    Thanks,
    Tarun

    Hi,
    I suggest discussing this issue in Word or IIS forum.
    Word forum:
    http://social.technet.microsoft.com/Forums/en-us/word/threads
    IIS forum:
    http://forums.iis.net/
    Tim Quan

  • How to convert text file into xml file format with and check that with DTD

    I have an text file with | seperator . I have to convert this to an xml file and check with DTD present with me..
    plz help me out

    can i get some code that how to compare the xml with dtd or just give the DTD name with an XML

  • How to draw text vertically, or in an angle

    please help me how to draw text vertically, or in an angle

    I robbed the framework from Dr Las or 74phillip (don't remember which) ...
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class AngleText extends JPanel {
      private int      degrees = 16;
      private JSpinner degreesSpinner;
      public AngleText () {
        setBackground ( Color.WHITE );
      }  // AngleText constructor
      protected void paintComponent ( Graphics _g ) {
        super.paintComponent ( _g );
        Graphics2D g = (Graphics2D)_g;
        g.setRenderingHint ( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
        AffineTransform at = AffineTransform.getRotateInstance ( Math.toRadians ( degrees ) );
        Font f =  g.getFont();
        g.setFont ( f.deriveFont ( at ) );
        g.drawString ( "Rotating Text!", getWidth()/2, getHeight()/2 );
        g.setRenderingHint ( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
      }  // paintComponent
      public JPanel getUIPanel () {
        SpinnerModel degreesModel = new SpinnerNumberModel (
                                      degrees  // initial
                                     ,0        // min
                                     ,360      // max
                                     ,2        // step
        degreesSpinner = new JSpinner ( degreesModel );
        degreesSpinner.addChangeListener ( new DegreesTracker() );
        JPanel panel = new JPanel();
        panel.add ( degreesSpinner );
        return panel;
      }  // getUIPanel
      //  DegreesTracker
      private class DegreesTracker implements ChangeListener {
        public void stateChanged ( ChangeEvent e ) {
          Integer i = (Integer)((JSpinner)e.getSource()).getValue();
          degrees   = i.intValue ();
          repaint();
      }  // DegreesTracker
      //  main
      public static void main ( String[] args ) {
        JFrame f = new JFrame ( "AngleText" );
        f.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
        AngleText app = new AngleText();
        f.getContentPane().add ( app );
        f.getContentPane().add ( app.getUIPanel(), BorderLayout.SOUTH );
        f.setSize ( 200, 200 );
        f.setVisible ( true );
      }  // main
    }  // AngleText

  • How to add PDF files into a slides? (Flash 8)

    I am new to flash and I am using Macromedia Flash 8. My task is simple enough: I need create a Presentation with Screens from PDF files: I have 10-12 PDF files which I want convert into flash presentation.
    I have read this tutorial:
    http://w3.id.tue.nl/fileadmin/id/objects/E-Atelier/Phidgets/Software/Flash/fl8_tutorials.p df
    Chapter 11: Basic Tasks: Create a Presentation with Screens.
    I'm having trouble how to add PDF files into a slides: I want insert a whole pdf file as separate slide, without splitting pdf file into separate elements: pictures, text, etc. I tried import pdf file into Flash, wheen import there is shown prompt how program should process this pdf file(add in stage, library, as keyframes, etc) , not clear which option is correct for my task. What I got is pdf file splitted into multiple images, text, - which is not what I want. I want keep PDF files without changes, preserve original design and formatting, just convert this pdf into flash, so presentation will consist of PDFs organized in correct order, then add navigation buttons and some effects. How to solve this task?

    Just to avoid potential confusion... PDF is an Adobe format, but Flash 8 is/was not.  Flash 8 came out before Adobe bought Macromedia.  Even today, I don't believe anything has been done to accomodate direct integration of PDF content in Flash.

  • How to add a report into the SAP-SCRIPT .using PERFORM ......ENDPERFORM

    My question is that How to add a report into the SAP-SCRIPT .
    by using PERFORM ......ENDPERFORM
    I don't know how to used it .

    Hi Sandeep,
    Please check this link
    http://help.sap.com/saphelp_40b/helpdata/en/d1/803279454211d189710000e8322d00/content.htm
    http://www.allinterview.com/showanswers/37425.html
    Calling ABAP Subroutines: PERFORM
    You can use the PERFORM command to call an ABAP subroutine (form) from any program, subject to the normal ABAP runtime authorization checking. You can use such calls to subroutines for carrying out calculations, for obtaining data from the database that is needed at display or print time, for formatting data, and so on.
    PERFORM commands, like all control commands, are executed when a document is formatted for display or printing. Communication between a subroutine that you call and the document is by way of symbols whose values are set in the subroutine.
    Syntax in a form window:
    /: PERFORM <form> IN PROGRAM <prog>
    /: USING &INVAR1&
    /: USING &INVAR2&
    /: CHANGING &OUTVAR1&
    /: CHANGING &OUTVAR2&
    /: ENDPERFORM
    INVAR1 and INVAR2 are variable symbols and may be of any of the four SAPscript symbol types.
    OUTVAR1 and OUTVAR2 are local text symbols and must therefore be character strings.
    The ABAP subroutine called via the command line stated above must be defined in the ABAP report prog as follows:
    FORM <form> TABLES IN_TAB STRUCTURE ITCSY
    OUT_TAB STRUCTURE ITCSY.
    ENDFORM.
    The values of the SAPscript symbols passed with /: USING... are now stored in the internal table IN_TAB . Note that the system passes the values as character string to the subroutine, since the field Feld VALUE in structure ITCSY has the domain TDSYMVALUE (CHAR 80). See the example below on how to access the variables.
    The internal table OUT_TAB contains names and values of the CHANGING parameters in the PERFORM statement. These parameters are local text symbols, that is, character fields. See the example below on how to return the variables within the subroutine.
    From within a SAPscript form, a subroutine GET_BARCODE in the ABAP program QCJPERFO is called. Then the simple barcode contained there (u2018First pageu2019, u2018Next pageu2019, u2018Last pageu2019) is printed as local variable symbol.
    Definition in the SAPscript form:
    /: PERFORM GET_BARCODE IN PROGRAM QCJPERFO
    /: USING &PAGE&
    /: USING &NEXTPAGE&
    /: CHANGING &BARCODE&
    /: ENDPERFORM
    / &BARCODE&
    Coding of the calling ABAP program:
    REPORT QCJPERFO.
    FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY
    OUT_PAR STRUCTURE ITCSY.
    DATA: PAGNUM LIKE SY-TABIX, "page number
    NEXTPAGE LIKE SY-TABIX. "number of next page
    READ TABLE IN_PAR WITH KEY u2018PAGEu2019.
    CHECK SY-SUBRC = 0.
    PAGNUM = IN_PAR-VALUE.
    READ TABLE IN_PAR WITH KEY u2018NEXTPAGEu2019.
    CHECK SY-SUBRC = 0.
    NEXTPAGE = IN_PAR-VALUE.
    READ TABLE IN_PAR WITH KEY u2018BARCODEu2019.
    CHECK SY-SUBRC = 0.
    IF PAGNUM = 1.
    OUT_PAR-VALUE = u2018|u2019. "First page
    ELSE.
    OUT_PAR-VALUE = u2018||u2019. "Next page
    ENDIF.
    IF NEXTPAGE = 0.
    OUT_PAR-VALUE+2 = u2018Lu2019. "Flag: last page
    ENDIF.
    MODIFY OUT_PAR INDEX SY-TABIX.
    ENDFORM.
    Best regards,
    raam

  • How to print text vertically in smart forms

    hi,
    Can any one tell how to print text vertically in smartforms
    ADVANCE THANKS
    GUHAPRIYAN

    HI,
    Chk out  this thread.Maybe it proves helpful.
    Re: vertical writing in smartforms
    Regards,
    Gayathri

  • How to add a project into master project by Powershell

    How to add a master project and sub-projects powershell
    I use project server 2013, I want inserting multiple sub-project plans into a project master

    Hello,
    You can't do this directly in PowerShell using the PSI etc. as the PSI can't create master projects / insert subprojects. You could however do this in VBA if required or automate Project using PowerShell COM object.
    Paul
    Paul Mather | Twitter |
    http://pwmather.wordpress.com | CPS

  • How to display TEXT vertically in SMART FORM

    Hai,
    I need to display the column name of a table vertically (readable from bottom to top) in smart form.
    Could any one please tell me how to do this?
    Thanks & Best Regards,
    Maniyam Bhaskar.

    Hi,
    Go through these threads for the discussions happened on similar issue... hope it helps you..
    how to print text vertically in smart forms
    vertical and horizontal printing in same page with smartforms or sapscript
    Good luck
    Narin

  • How to add an item into the Newsstand

    How to add an item into the Newsstand.  Please do NOT reply using  "tech-language." Use standard- normal everyday English. Thanks,
    Don Otlin
    Franklin Square, NY

    Open Newsstand. Tap on the "Store" button in the upper right. Any newspaper or magazine you download from the store will appear in Newsstand.

  • How to add text to Imovie

    Hi there,
    As a new user of an Macbook, and iMovie, I cannot figure out how to add texts to my movies. I do understand that I can add titles, but that doesn't allow me to change positions nor allows me to edit the font in the extent that I want to.
    Naturally I browsed the web, and the only conclusion I can draw is that it is not possible (yet) to add plain texts to your movie. Is this correct?
    If this is the case, do you use some other programs to circumvent this limitation in iMovie?
    Thanks for your help!

    in imovie 10, look at the bottom left hand corner there should be:
    Content and Backgrounds
    Titles
    Tranistions
    This is also known as the content libary
    Click on titles and they should appear, it works for me.

  • How to add text to photos?

    Please advise how I add text to pictures.

    sk86
    You can't using iphoto. You'll need an external editor. Seasgore is free, Photoshop Elements is relatively inexpensive, Photoshop is very expensive. Graphic Converter may be on your machine already. Search on http://www.macupdate.com
    Regards
    TD

  • How to add text to gif

    Hello, i'm a beginner in photoshop.
    I want to add text to my gif in animation frame, but somehow the text look transparent even though i already use black color for the text.
    Could someone give me tutorial to how to add text to the gif and then make some kind of a subtitle?
    Thanks..

    So, if i want to make the text appear in layer 1-10 only, i only have to put the text layer above layer 10 right?
    Do you mean 'Frame 1 - 10'? If you want the text to appear in Frames 1 - 10, you have to add the text to all frames from 1 - 10 above your image layer.
    But what if then i want to make a new text for layer 11-20? Wouldn't the text appear in layer 1-10 as well? How to separate the text then?
    If you want new text for Frame 11-20, you have to create a text layer in Frames 11 - 20 and change the text that you want to show in 11-20 frames.

  • Asset related question - How to add a record into table ANLC?

    Hello experts,
    Could anyone tell me how to add a record into table ANLC?
    Thanks very much!
    Christina.

    how you want add?
    you want add direct in table???.
    Normally if yo post any transaction this table will update.
    ex;acquisition;
    chandra

  • How to add a system into Solution Manager directory.

    Hi!
    Can anybody tell me how to add a system into Solution Manager directory before generating license key for ECC installation .
    Also,
    How to connect the XI in same box with SolMan and ECC in defferent server to SolMan 3.2 .
    I am going to install SolMan and than XI in and box and after that ECC in a seperate box.
    AM I right?
    regards,
    Pratip Bhattacharyya

    Hi Bratip Bhattacharyya,
    SolMan 3.2 needs SLD only for automatic data gathering of the sap landscape; you can choose between SLD and LIS in transaction SMSY_SETUP (which simply uses the TMS-domain controllers for information gathering).
    XI needs SLD, but XI needs also a netweaver04 (s) system (Abap WAS 6.40). SolMan 3.2 isn't a netweaver04 system (Abap WAS 6.20). So you have to install XI as an own central instance (Abap + Java) on the same windows server, if you like. In this case you have to install for XI an own SLD. Different SLDs can create bridges between themselves. Please look at the SLD configuration guide (quicklink /netweaver -> installation guides).
    But don't ask me how to install two sap systems on one server on windows (on Linux it's easy I have done so); basically it will have an own SID and own "service" numbers (which means own tcp port numbers).
    If you can't dedicate to XI an own server, it's only a question of hardware sizing. For the different combinations of netweaver components you should study the master guide for netweawer.
    Bye
    Message was edited by: Riccardo Escher

Maybe you are looking for