简体   繁体   English

C# Arcobjects:将 Excel 对象插入到页面布局中

[英]C# Arcobjects: Insert Excel object into the pagelayout

I'm looking for direction on how to add an excel sheet into the pagelayout of an mxd;我正在寻找有关如何将 Excel 工作表添加到 mxd 的页面布局的方向; much like the function that is available through the arcmap interface.很像通过 arcmap 界面提供的功能。

I'm using C# arcobjects (10.5) and am loaing the MXD in to memory.我正在使用 C# arcobjects (10.5) 并将 MXD 加载到内存中。 At that time I'm adding the excel to the pagelayout and then exporting to PDF.那时我正在将 excel 添加到页面布局中,然后导出为 PDF。

I have tired the below, but when I cast 'rawSrc' variable it is null .我已经厌倦了下面的内容,但是当我转换 'rawSrc' 变量时,它是null I'm not sure what the correct IElement type is:我不确定正确的IElement类型是什么:

 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.谢谢您的帮助。

Write real sheet name into the Excel.将真实的工作表名称写入 Excel。 If sheet name "sheet1" you should write;如果工作表名称“sheet1”你应该写;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM