word插入excel图表(office组件)

internal void InsertExcelChart()
        {
            Word.InlineShape ilsChartObject;
            Word.Selection sel;


            object oClassType = "Excel.Chart.8";
            object oFileName = string.Empty;
            object oLinkToFile = System.Type.Missing;
            object oDisplayAsIcon = false;
            object oIconFileName = System.Type.Missing;
            object oIconIndex = System.Type.Missing;
            object oIconLabel = System.Type.Missing;
            object oRange = System.Type.Missing;


            try
            {
                sel = this.ActiveWindow.Selection;
                if (sel != null)
                {
                    ilsChartObject = sel.InlineShapes.AddOLEObject(ref oClassType, ref oFileName, ref oLinkToFile,
                                            ref oDisplayAsIcon, ref oIconFileName, ref oIconIndex, ref oIconLabel, ref oRange);
                    if (ilsChartObject != null)
                    {
                        //TODO: do something with your chart object now ...
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Insert Chart Error", 
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }












internal void InsertExcelChart()
        {
            Word.InlineShape ilsChartObject;
            Word.Selection sel;


            object oClassType = "Excel.Chart.8";
            object oFileName = string.Empty;
            object oLinkToFile = System.Type.Missing;
            object oDisplayAsIcon = false;
            object oIconFileName = System.Type.Missing;
            object oIconIndex = System.Type.Missing;
            object oIconLabel = System.Type.Missing;
            object oRange = System.Type.Missing;


            try
            {
                sel = this.ActiveWindow.Selection;
                if (sel != null)
                {
                    ilsChartObject = sel.InlineShapes.AddOLEObject(ref oClassType, ref oFileName, ref oLinkToFile,
                                            ref oDisplayAsIcon, ref oIconFileName, ref oIconIndex, ref oIconLabel, ref oRange);
                    if (ilsChartObject != null)
                    {
                        //TODO: do something with your chart object now ...
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Insert Chart Error", 
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

 

posted @ 2022-07-26 10:26  devgis  阅读(265)  评论(0编辑  收藏  举报