Ask a questionAsk a question
 

AnswerUnable to Resize Embedded Ole Object

  • Friday, November 06, 2009 2:26 AMSamuel Clevsh Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    I generate an Excel file programmatically, save it to a temporary file, copy that file to another temporary file(otherwise I get some kind of cryptic message when I try to quit excel), and then finally import the file into PowerPoint. The first element in the workbook is a chart, which is then automatically displayed. The following does the trick.

    shape = slide.Shapes.AddOLEObject(left, top, width, height, String.Empty, filename, Office.MsoTriState.msoFalse, string.Empty, 0, string.Empty, Office.MsoTriState.msoFalse);
    
    For some values of left, top, width and height and filename(=xls file). This works fine, except for one thing - the resulting chart is streched. I would very much want to resize the OLE container to same values of width and height. It's possible to do this if I activate the OLE object manually and drag it about with a mouse.

    I've spent about a day trying to find a solution to this problem, but so far I've nothing to show for it. Thank you in advance!

Answers

  • Friday, November 06, 2009 7:45 AMCindy MeisterMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Samuel

    As far as I know, there is absolutely no way to change the size of an embedded OLE object programmatically. The width and height parameters in the method you're using refer soley to the graphical object and not to the OLE object being embedded. That's why it's appearing "stretched". In my experience, the only way you can control the size (as well as the number of rows and columns) is to make sure the original file corresponds to the result you require.

    Since this topic isn't really VSTO-related (VSTO does nothing in relation to OLE embedding or Shapes - that all comes from the Office object models, even if you would be using VSTO as an add-in), there's not much more this forum can contribute. You might try asking in the specialized PowerPoint newsgroup how they deal with this problem when embedding Excel sheets into slide shows. You'll find a link in the fourm's Please Read First message.
    Cindy Meister, VSTO/Word MVP

All Replies

  • Friday, November 06, 2009 7:45 AMCindy MeisterMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Samuel

    As far as I know, there is absolutely no way to change the size of an embedded OLE object programmatically. The width and height parameters in the method you're using refer soley to the graphical object and not to the OLE object being embedded. That's why it's appearing "stretched". In my experience, the only way you can control the size (as well as the number of rows and columns) is to make sure the original file corresponds to the result you require.

    Since this topic isn't really VSTO-related (VSTO does nothing in relation to OLE embedding or Shapes - that all comes from the Office object models, even if you would be using VSTO as an add-in), there's not much more this forum can contribute. You might try asking in the specialized PowerPoint newsgroup how they deal with this problem when embedding Excel sheets into slide shows. You'll find a link in the fourm's Please Read First message.
    Cindy Meister, VSTO/Word MVP
  • Wednesday, November 11, 2009 3:26 AMSamuel Clevsh Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thank you for taking time to answer my question. Since I'm creating the Excel file charts that I want to stretch myself, ensuring that the "original file corresponds to the results I requie" should be a solvable problem for me. Taking your advice, I did the following - I made my charts and changed the paper type of the excel workbook. It actually works fine, but it's not an ideal solution as there is no precise way to set height and width - there are only so many types of paper.

    If I may impose slightly futher, I would appreciate it a lot if you could comment on the following new topic that I started, which describes my particular problem.

    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/3e61cecb-5b18-44e3-bff2-3f0c5ff828b5