none
Copy table from Excel to Word RRS feed

  • Question

  • Is it possible to copy content from Excel to Word using OpenXML 2.5?

    Case: Excel file has Charts and regions of data. All of them are using defined names to identify.

    Now I need to copy some of them into Word document which contains exactly same name as defined name in excel (could be part of text or merging field, not sure yet).The problem is, sometimes it should be copied as MetafileImage, sometimes EnhancedMetafileImage, sometimes Text, or html or rtf.

     

    Right now I'm using Interop, which is really slow.

    Thursday, June 26, 2014 10:02 AM

Answers

  • Hi DevKode

    It is definitely possible (although I've never done it) to copy the components that make up a chart from an Excel file into a Word file, using the SDK. The Open XML file format supports these "parts" the same way in Excel, Word and PowerPoint. Essentially, each component is an XML file, so all you need to do is copy the components into the Word document's Zip package, create the reference in the target (document.xml, probably) and the relationship between the Reference and the component part(s).

    Any other format, however, is not something Open XML (with or without the SDK) "does". When you use Copy/Paste in the Office applications the Clipboard and internal converters are responsible for making the various file types available for pasting into the target application. Since the applications aren't involved when you work directly with an Open XML file, the converters aren't available. This means you'd need to write your own converter or license a third-party converter (and I'm not sure whether generating the image files is even possible, just from the Open XML data).


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, June 26, 2014 6:36 PM
    Moderator

All replies

  • Hello,

       One simple way that saving excel to image and add image to Word document.

    -----------------------------------------
     if the reply help you mark it as your answer.
     Free No OLE C# Word PDF, ExcelPowerPoint Component(Create, Modify, Convert & Print) 
    Thursday, June 26, 2014 10:24 AM
  • But can you convert region to image and export it using open xml sdk?

    The problem is, financial guys take 3 charts, make them a region (with defined name) and I have to copy this region into doc file (there may be multiple regions, some of them are table + chart and that kind of mixing)

    Thursday, June 26, 2014 1:05 PM
  • Hi DevKode

    It is definitely possible (although I've never done it) to copy the components that make up a chart from an Excel file into a Word file, using the SDK. The Open XML file format supports these "parts" the same way in Excel, Word and PowerPoint. Essentially, each component is an XML file, so all you need to do is copy the components into the Word document's Zip package, create the reference in the target (document.xml, probably) and the relationship between the Reference and the component part(s).

    Any other format, however, is not something Open XML (with or without the SDK) "does". When you use Copy/Paste in the Office applications the Clipboard and internal converters are responsible for making the various file types available for pasting into the target application. Since the applications aren't involved when you work directly with an Open XML file, the converters aren't available. This means you'd need to write your own converter or license a third-party converter (and I'm not sure whether generating the image files is even possible, just from the Open XML data).


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, June 26, 2014 6:36 PM
    Moderator