none
Paste excel chart in word with C#: pasteandformat(wdChartLinked) The command is not available RRS feed

  • Question

  • I´m trying to insert an excel chart in word, but I can only do it as a bitmap, not as an excel chart (embedded or linked).

    This is what I´m trying to do:

    Chart chart = xls.Charts[chartSheetName];
    chart.ChartArea.Copy();
    doc.Application.Selection.PasteAndFormat(Word.WdRecoveryType.wdChartLinked);

    And it fails in pasteandformat with "This command is not available.". I recorded a macro in excel and word, and these are the commands... In excel selects the chartarea and copy, and in word pasteandformat(wdChartLinked)...

    If I paste as Bitmap, it works:

    Chart chart = xls.Charts[chartSheetName];
    chart.ChartArea.Copy();
    doc.Application.Selection.PasteAndFormat(DOC.WdRecoveryType.wdChartPicture);

    I also tried with addoleobject method, but it gives an error about not being able to link file

    doc.Content.InlineShapes.AddOLEObject(filename, LinkToFile: true, DisplayAsIcon: false);

    filename is the path of the xls file (the path is OK, it´s the same I use to SaveAs the excel file in the code) and added to the end "!chart_sheet_name"

    I.E. filename= C:/file.xls!MyChartSheetName

    Friday, March 1, 2013 1:44 AM

Answers

  • you can record this manipulate(insert ->Object->From File Command) in a macro to get basic syntax, and then you can translate VBA codes to C# 
    Monday, March 4, 2013 6:31 AM

All replies

  • you can record this manipulate(insert ->Object->From File Command) in a macro to get basic syntax, and then you can translate VBA codes to C# 
    Monday, March 4, 2013 6:31 AM
  • Hi Alberto GD,

    I temporarily marked the reply as answer. You can unmark it if it provides no help.

    Please feel free to let us know if you need any help.

    Have a nice day.


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 14, 2013 7:19 AM
    Moderator