0

I'm looking for direction on how to add an excel sheet into the pagelayout of an mxd; much like the function that is available through the arcmap interface.

I'm using C# arcobjects (10.5) and am loaing the MXD in to memory. At that time I'm adding the excel to the pagelayout and then exporting to PDF.

I have tired the below, but when I cast 'rawSrc' variable it is null. I'm not sure what the correct IElement type is:

 IPageLayout pageLayout = myMXD.PageLayout;
 IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;

            RectangleElement ExcelSrc = new RectangleElement();

            double posX = 0.8008;
            double posY = 6.9567;
            double Legwidth = 4.8;
            System.Double w = 11.0301;
            System.Double h = 9.0949;

            System.Double aspectRatio = w / h;
            var envelope = new EnvelopeClass();
            envelope.PutCoords(posX, posY, (posX * Legwidth), (posY * Legwidth / aspectRatio));
            ExcelSrc.Geometry = envelope;

            string xcelPath = System.IO.Path.Combine("string to my directory",  "Data.xlsx");

            var rawSrc = new XLWorkbook(xcelPath).Worksheet("Table");

            IVariantStream blobStream = new VariantStreamIOClass();
            blobStream = rawSrc as IVariantStream;

            ExcelSrc = blobStream.Read() as RectangleElement;

            graphicsContainer.AddElement(((IElement)ExcelSrc), 0);

            ((IActiveView)myMXD.PageLayout).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            myMXD.Save();

            Marshal.FinalReleaseComObject(blobStream);

Thanks for the help.

Omnia9
  • 1,563
  • 4
  • 14
  • 39

1 Answers1

0

Write real sheet name into the Excel. If sheet name "sheet1" you should write;

var rawSrc = new XLWorkbook(xcelPath).Worksheet("sheet1");

Murat Can OĞUZHAN
  • 735
  • 11
  • 19