We help IT Professionals succeed at work.
Get Started

Microsoft Office Word document

Jedidia
Jedidia asked
on
153 Views
Last Modified: 2015-07-17
Need a little help here.

I am generating a word document and having a little trouble understanding the separation of paragraphs.

This code generates a word document (screen shot attached) and I am having issues formatting the paragraphs to the left.  the top paragraph and the bitmap I import should be centered.  the paragraph below (in the red box) should be shifted to the left.

                object oMissing = System.Reflection.Missing.Value;
                object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

                //Start Word and create a new document.

                // Get the Word application object.
                Word._Application oWord = new Word.Application();

                //Set animation status for word application
                oWord.ShowAnimation = false;

                //Make Word visible (optional)
                oWord.Visible = true;

                // Create the Word document.
                object missing = Type.Missing;
                Word._Document word_doc = oWord.Documents.Add(ref missing, ref missing, ref missing, ref missing);

                // Set the Range to the first paragraph. 
                Word.Range rng = word_doc.Paragraphs[1].Range;

                //Set Text and Alignment properties
                rng.Font.Size = 12;
                rng.Font.Name = "Arial";
                rng.Underline = WdUnderline.wdUnderlineSingle;
                rng.Font.Bold = 1;
                rng.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                rng.ParagraphFormat.SpaceAfter = 0;
                rng.ParagraphFormat.SpaceBefore = 0;
                rng.ParagraphFormat.LineSpacing = 12;
                rng.Text = txtStationName.Text + " TEST EQUIPMENT" + Environment.NewLine + "TEST TEST TEST";
                
                rng.InsertParagraphAfter();

               //Insert a paragraph as a spacer
                Word.Paragraph oPara2;
                object oRng1 = word_doc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                oPara2 = word_doc.Content.Paragraphs.Add(ref oRng1);
                oPara2.Range.Text = " ";
                oPara2.Format.SpaceAfter = 6;
                //oPara2.Format.Borders.Enable;// = true;// = 1;
                oPara2.Range.InsertParagraphAfter();
                
                Word.Paragraph concept = word_doc.Paragraphs.Add();

                // Add BitMap to WORD Document
                Bitmap croppedBitmap = new Bitmap(pictureBox1.Image);
                croppedBitmap = croppedBitmap.Clone(new System.Drawing.Rectangle(0, 0, picBoxSize_X, picBoxSize_Y), System.Drawing.Imaging.PixelFormat.DontCare);

                Clipboard.SetImage(croppedBitmap);      
                concept.Range.InsertParagraphAfter();
                concept.Range.Select();
                oWord.Selection.Paste();


                //Insert a paragraph at the end of the document.
                Word.Paragraph oPara3;
                object oRng = word_doc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                oPara3 = word_doc.Content.Paragraphs.Add(ref oRng);
                oPara3.Format.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                oPara3.Range.Text = "Notes: – TEST Equipment TEST TEST TEST ";
                oPara3.Format.SpaceAfter = 6;
                oPara3.Range.InsertParagraphAfter();

Open in new window


Pointers anyone...

Thanks
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE