locked
How to format the oleobject in word document? RRS feed

  • Question

  • Hi,
    My requirement is merge some excel document to a word document,so i use the flowing code:
    object classType = "Excle.Sheet.12";
                            object falseValue = false;
                            object missing = System.Type.Missing;
                            object fileName;
    
    InlineShape inlineShape = wordApplication.Selection.InlineShapes.AddOLEObject(ref classType,
                                ref fileName, falseValue, falseValue, missing, missing, missing, missing);
                            
    that worked fine, but I want to align the inserted excel sheet center in the word document, how to code it?
    Wednesday, May 6, 2009 3:47 AM

Answers

  • Hi,
    Could you please provide a snippet of your code and point out to exactly where it is failing using the ConvertToShape() method?

    The code works fine when executed using VS 2008, Office 2007.

     

    Wednesday, May 27, 2009 1:13 AM
    Moderator

All replies

  • Hi,

    Thank you for contacting Microsoft Innovate on Office Forum!
    We have started our research on this request and will get back to you ASAP.

    Could you please confirm if you are using office 2007?

    Thanks,
    Dhanashri.

    Thursday, May 7, 2009 1:07 AM
    Moderator
  • thank you!

    office2007
    vs2005
    Thursday, May 7, 2009 1:41 AM
  • Hi,

    Let me start by explaining two kinds of "shapes" in Word:

    (1)    Inlineshape
      The shape is a part of the Text Layer. You do not have formatting options for such shapes.

    (2)    Shape
    The shape is a part of the Drawing Layer. You have a lot of formatting options like: wrap, location, height, width, etc.

    So , in this case you have created an InlineShape and needs to be converted to a Shape:

                Shape temp = inlineShape.ConvertToShape();

                temp.Top = 200;

                temp.Left = 100;

                temp.WrapFormat.Type = WdWrapType .wdWrapTight;

    You may want to try the different options given by Shape.

    Another way of doing this is to use the XML API to manipulate the XML files that are created by Word 2007 document directly. You get a lot of flexibility by doing this, although initially it may take a lot of time to understand programming the XML way.

    Regards,

    Avinash, MSFT

     

    Disclaimer:

    By using the following materials or sample code you agree to be bound by the license terms below and the Microsoft Partner Program Agreement the terms of which are incorporated herein by this reference. These license terms are an agreement between Microsoft Corporation (or, if applicable based on where you are located, one of its affiliates) and you. Any materials (other than the sample code) we provide to you are for your internal use only. Any sample code is provided for the purpose of illustration only and is not intended to be used in a production environment. We grant you a nonexclusive, royalty-free right to use and modify the sample code and to reproduce and distribute the object code from the sample code, provided that you agree: (i) to not user Microsoft’s name, logo, or trademarks to market your software product in which the sample code is embedded; (ii) to include a valid copyright notice on your software product in which the sample code is embedded; (iii) to provide on behalf of and for the benefit of your subcontractors a disclaimer of warranties, exclusion of liability for indirect and consequential damages and a reasonable limitation of liability; and (iv) to indemnify, hold harmless, and defend Microsoft, its affiliates and suppliers from and against any third party claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the sample code.

    Thursday, May 21, 2009 8:14 PM
    Moderator
  • I had tried the inlineShape.ConvertToShape() method ,but when the inlineshape is an excel document, it doesn't work.
    Friday, May 22, 2009 3:05 AM
  • Hi,
    Could you please provide a snippet of your code and point out to exactly where it is failing using the ConvertToShape() method?

    The code works fine when executed using VS 2008, Office 2007.

     

    Wednesday, May 27, 2009 1:13 AM
    Moderator