OLE Excel Object Size is Changed after Double Click on it in MS Word | Insert OLE (Excel) into Document using .NET

@RadAway

Please manually create the expected Excel document using MS Excel that you want to insert into MS Word document. Please insert this document into Word document using MS Word and check the MS Word’s behavior. You will notice the same behavior.

If you notice different behavior, please share following resources here for testing.

  • Your expected Excel document that you want to insert into Word document. Please create this document using MS Excel.
  • Please attach the output Excel document that is generated by Aspose.Cells and shows undesired behavior and .
  • Please share Aspose.Cells code example to generate Excel document.

We will then investigate the issue and provide you more information on it. If Aspose.Cells does not generate the expected Excel output, we will log this issue for Aspose.Cells.

PS: To attach these resources, please zip and upload them.

You’ve completely ignored what I wrote in my post. Are you not understanding the point I am making or is what I stated somehow incorrect?

@RadAway

We have investigated this issue further and noticed that the OLE Shape width does not set correctly. The Shape.Width should be equal to size set by SetOleSize method.

The Shape.Width does not change the width of OLE as MS Word does. We have logged this detail in our issue tracking system and you will be informed once there is any update available on it.

@RadAway

Further to my previous post, you can set the OLE width using following code snippet. The Shape width should be the size of OLE set by SetOleSize.

Bitmap bitmap = sr.ToImage(0);
shape.Width = bitmap.Width;

Hope this helps you.

Ok that makes sense. So you are acknowledging that shape.Width not taking effect is a bug and will be fixed at some point?

@RadAway

This code will solve your problem. However, as shared in my previous post, the Shape.Width sets the shape size but not the internal OLE size.

It is more related to missing feature in Aspose.Words. We will check the possibility of implementation of this feature and inform you via this forum thread.

Well it doesn’t actually solve my problem because I need to resize the image to get it to fit properly into the document, but I am glad to hear that you will be looking into it. Here is updated code:

static void TestAspose()
{
    var book = new Aspose.Cells.Workbook(@"C:\Projects\WordTest\sample.xlsx");

    var sheet = book.Worksheets[0];

    book.Worksheets.SetOleSize(0, sheet.Cells.MaxDataRow, 0, sheet.Cells.MaxDataColumn);

    sheet.PageSetup.LeftMargin = 0;
    sheet.PageSetup.RightMargin = 0;
    sheet.PageSetup.TopMargin = 0;
    sheet.PageSetup.BottomMargin = 0;

    var options = new Aspose.Cells.Rendering.ImageOrPrintOptions
    {
        OnePagePerSheet = true,
        ImageType = Aspose.Cells.Drawing.ImageType.Emf
    };

    var sr = new Aspose.Cells.Rendering.SheetRender(sheet, options);

    var imgStream = new MemoryStream();
    sr.ToImage(0, imgStream);
    imgStream.Position = 0;

    using var image = Aspose.Imaging.Image.Load(imgStream);
    image.ResizeWidthProportionally(600);
    image.Save();
    imgStream.Position = 0;

    var document = new Aspose.Words.Document();
    var builder = new Aspose.Words.DocumentBuilder(document);
    using var xlsStream = new MemoryStream();

    book.Save(xlsStream, SaveFormat.Xlsx);
    xlsStream.Position = 0;
    var shape = builder.InsertOleObject(xlsStream, "Excel.Sheet.12", false, imgStream);

    var of = shape.OleFormat;
    of.AutoUpdate = false;

    shape.AspectRatioLocked = true;
    shape.Width = image.Width;

    document.Save(@"C:\Projects\WordTest\sample.docx");
}

@RadAway

We will inform you via this forum thread once there is any news available on WORDSNET-22615.

Are there any updates on this? Is it still being looked at?

@RadAway

Unfortunately, there is no update available on your issue. We will be sure to inform you via this forum thread once this issue is resolved. We apologize for your inconvenience.

Is WORDSNET-22615 still in the work queue? It’s been over a year and a half since the issue was acknowledged.

@RadAway We have completed analysis of the issue, but it is not yet scheduled for development. Please accept our apologies for your inconvenience.
I have asked the team whether we can schedule the issue for development or it will be postponed. We will keep you updated and let you know once there are news.

Any updates on when we can expect a resolution for WORDSNET-22615?

@lancomdevteam Unfortunately, there are no news regarding the issue yet.

Any updates available?

@lancomdevteam Unfortunately, there are still no news regarding the issue. Please accept our apologies for your inconvenience.