title: Insert chart as image into Word document from Excel
body: <p>I have a Word Add-In where I want the user to enter a path to an Excel file (that resides somewhere on a network drive), read all the charts from the Excel file, display a small summary of all the charts and then let the user select one and insert it into the document as an image.</p>
  
  <p>Similar to this example here, except I don't want the Excel files to be hosted on OneDrive (just a local directory) and I am doing it in pure JS/HTML, no ASP.NET: <a href="https://github.com/OfficeDev/PowerPoint-Add-in-Microsoft-Graph-ASPNET-InsertChart" rel="nofollow noreferrer">https://github.com/OfficeDev/PowerPoint-Add-in-Microsoft-Graph-ASPNET-InsertChart</a></p>
  
  <p>I am struggling with the first part, accessing the Excel file from Word. How do I do that? As per this post <a href="https://stackoverflow.com/questions/40100876/load-excel-file-in-ms-word-add-in-with-office-js">Load Excel file in MS Word Add-in with Office.js</a> from Oct 2016 it might be added in the future. Any news on that or is the only way to go still via OneDrive?</p>
  
  <p>Once I can open the Excel and access its content in Javascript I think it is straight forward, e.g.:</p>
  
  <p>Get all the charts</p>
  
  <pre><code>var charts = ctx.workbook.worksheets.getActiveWorksheet().charts.load("name");
  </code></pre>
  
  <p>Convert them to images</p>
  
  <pre><code>chartObject.getImage(height, width, fittingMode);
  </code></pre>
  
  <p>When the user selects one I just insert it into the document at the selection.</p>