Issue with sizing embedded Excel objects

Home Forums Open-Xml-Sdk Issue with sizing embedded Excel objects

This topic contains 1 reply, has 2 voices, and was last updated by  Eric White 8 years, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3860

    Thierry
    Participant

    Hi Eric,

    I do have a issue with embedding Excel Worksheet objects into Word documents concerning the size of this objects. The size of the embedded object is calculated via the generated emf-picture of object.
    The embedded Excel objects are .xlsx-files (also open xml-files).

    I found a related topic but the issue which is currently unresolved at:
    https://social.msdn.microsoft.com/Forums/en-US/9635fca8-a726-4ab3-9068-ffc6ceb00a14/openxml-embed-excel-ole-object-in-word-document?forum=os_binaryfile

    Embedding Visio Drawings as object are going correctly. So I think it has to do with embedding Excel into Word.

    Hereby code snippet for embedding an object:

    Dim embeddedObject As EmbeddedObject = New EmbeddedObject() With {.DxaOriginal = widthInTwips.ToString(), .DyaOriginal = heightInTwips.ToString()}

    Dim shapetypeId As String = DateTime.Now.Ticks.ToString() ‘”_x0000_t75″
    Dim shapetype1 As V.Shapetype = New V.Shapetype() With {.Id = shapetypeId, .CoordinateSize = “21600,21600”, .Filled = False, .Stroked = False, .OptionalNumber = 75, .PreferRelative = True, .EdgePath = “m@4@5L@4@11@9@11@9@5xe”}
    Dim stroke1 As V.Stroke = New V.Stroke() With {.JoinStyle = V.StrokeJoinStyleValues.Miter}

    Dim formulas1 As V.Formulas = New V.Formulas()
    Dim formula1 As V.Formula = New V.Formula() With {.Equation = “If lineDrawn pixelLineWidth 0”}
    Dim formula2 As V.Formula = New V.Formula() With {.Equation = “sum @0 1 0”}
    Dim formula3 As V.Formula = New V.Formula() With {.Equation = “sum 0 0 @1”}
    Dim formula4 As V.Formula = New V.Formula() With {.Equation = “prod @2 1 2”}
    Dim formula5 As V.Formula = New V.Formula() With {.Equation = “prod @3 21600 pixelWidth”}
    Dim formula6 As V.Formula = New V.Formula() With {.Equation = “prod @3 21600 pixelHeight”}
    Dim formula7 As V.Formula = New V.Formula() With {.Equation = “sum @0 0 1”}
    Dim formula8 As V.Formula = New V.Formula() With {.Equation = “prod @6 1 2”}
    Dim formula9 As V.Formula = New V.Formula() With {.Equation = “prod @7 21600 pixelWidth”}
    Dim formula10 As V.Formula = New V.Formula() With {.Equation = “sum @8 21600 0”}
    Dim formula11 As V.Formula = New V.Formula() With {.Equation = “prod @7 21600 pixelHeight”}
    Dim formula12 As V.Formula = New V.Formula() With {.Equation = “sum @10 21600 0″}

    formulas1.Append(formula1)
    formulas1.Append(formula2)
    formulas1.Append(formula3)
    formulas1.Append(formula4)
    formulas1.Append(formula5)
    formulas1.Append(formula6)
    formulas1.Append(formula7)
    formulas1.Append(formula8)
    formulas1.Append(formula9)
    formulas1.Append(formula10)
    formulas1.Append(formula11)
    formulas1.Append(formula12)

    Dim path1 As V.Path = New V.Path() With {.AllowGradientShape = True, .ConnectionPointType = Ovml.ConnectValues.Rectangle, .AllowExtrusion = False}
    Dim lock1 As Ovml.Lock = New Ovml.Lock() With {.Extension = V.ExtensionHandlingBehaviorValues.Edit, .AspectRatio = True}

    shapetype1.Append(stroke1)
    shapetype1.Append(formulas1)
    shapetype1.Append(path1)
    shapetype1.Append(lock1)

    Dim id As String = DateTime.Now.Ticks.ToString() ‘”_x0000_i1025”
    Dim sWidth As String = String.Format(“{0:0.##}”, Convert.TwipsToPoints(widthInTwips))
    Dim sHeight As String = String.Format(“{0:0.##}”, Convert.TwipsToPoints(heightInTwips))
    Dim sStyle As String = “width:” + sWidth + “pt;height:” + sHeight + “pt”

    Dim shape1 As V.Shape = New V.Shape() With {.Id = id, .Style = sStyle, .Type = shapetypeId} ‘, .Ole = False
    Dim imageData1 As V.ImageData = New V.ImageData() With {.Title = “”, .RelationshipId = imagePartEMFid}

    shape1.Append(imageData1)

    Dim oleObject1 As Ovml.OleObject = New Ovml.OleObject() With {.Type = Ovml.OleValues.Embed, .ProgId = progID, .ShapeId = id, .DrawAspect = Ovml.OleDrawAspectValues.Content, .ObjectId = DateTime.Now.Ticks.ToString(), .Id = embeddedPartOLEid}

    embeddedObject.Append(shapetype1)
    embeddedObject.Append(shape1)
    embeddedObject.Append(oleObject1)

    Dim paragraphForEmbeddedObject As Wordprocessing.Paragraph = New Wordprocessing.Paragraph()

    ‘Dim run1 As Run = New Run(picture)
    Dim runEmbeddedObject As Run = New Run(embeddedObject)

    ‘paragraphForEmbeddedObject.Append(run1)
    paragraphForEmbeddedObject.Append(runEmbeddedObject)

    Return paragraphForEmbeddedObject

    As a workaround/hack I can size the embedded Excel-objects via the Word objectmodel as postprocessing (if Word is present), but prever to prevent this workaround.

    Kind regards,
    Thierry

    #3875

    Eric White
    Keymaster

    Hi Thierry,

    Unfortunately, I have no experience in this area.

    I presume there is some issue associated with extents or metrics, but it would take some research to figure this out.

    After running your workaround/hack sizing the embedded Excel objects via the Word object model, you should get a pretty good idea of what your markup should be by looking at the markup after Word does its thing, do you not?

    Best, Eric

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.