AnsweredAssumed Answered

ArcDesktop 10.5: Adding Excel object to mxd with arcobjects

Question asked by Mart0369 on Jan 3, 2018
Latest reply on Jan 18, 2018 by Mart0369

Background:

I'm using ArcdDesktop 10.5 with Arcobjects (C#) for development.

 

Problem:

I'm working on automated Chart creation for a client. They need a table of data to be added to the chart, and the excel sheet gives the most flexibility in styling.

 

I have created the excel with C#, and am trying to add this object to a MXD that is loaded in memory. I believe that I'm close but need some help to get it completed.

 

I'm able to load the excel sheet into memory but am not able to 'add' or 'update' the OLEFrame with the content.

I have tried adding a new OLEFrame with a given Envelope for placement and I've tried to find the OLEFrame from the IGraphicsContainer of the MXD and update the content. I keep getting the following error:

"Error HRESULT E_FAIL has been returned from a call to a COM component. at ESRI.ArcGIS.ArcMapUI.OleFrameClass.Load(IStream pstm)"

 

Here is the code that I'm using.

 

var outputFilePath = @"...";

IMemoryBlobStream MemStream = new MemoryBlobStreamClass();
IPageLayout pageLayout = TheMXD.PageLayout;
IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;
graphicsContainer.Reset();


IElement pElement = graphicsContainer.Next();

while (pElement != null)
{
IElementProperties ElementProps = pElement as IElementProperties;
if (ElementProps.Name.Contains("Excel"))
{
      MemStream.LoadFromFile(outputFilePath);
      IPersistStream oleSteam = pElement as IPersistStream;

      oleSteam.Load(MemStream);
      break;
}

pElement = graphicsContainer.Next();
}

((IActiveView)TheMXD.PageLayout).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

Outcomes