c# VSTO 将word 里面的图表保存成图片

   private void button1_Click(object sender, RibbonControlEventArgs e)
        {

            Document doc = Globals.ThisAddIn.Application.ActiveDocument;
            Paragraphs pp= doc.Content.Paragraphs;
            Form1 form = new Form1();
            form.Show();
            Tables  tablelist=  doc.Tables; 
            Table table = tablelist[1];           
            Columns cc= table.Columns;
            Rows rr = table.Rows;
            Shapes shapelist=  doc.Shapes;
            Application m_app = Globals.ThisAddIn.Application;
            Bookmarks booklist = doc.Bookmarks;
            Range rangelist = doc.Range();
            int nCount = m_app.ActiveDocument.Styles.Count;

            for (int j = 1; j <= nCount; j++)
            {
                Microsoft.Office.Interop.Word.Style stl = m_app.ActiveDocument.Styles[j];

            }
            Paragraphs ppplist = doc.Paragraphs;
            List<Node> mu1 = new List<Node>();
            List<string> mu2 = new List<string>();
            List<string> valuelist = new List<string>();
            // Sections sectiongs=  doc.Sections;
            //foreach(Section s in sectiongs)
            //{

            //   Debug.WriteLine( s.Range);
            //}
            foreach (Paragraph item in doc.Paragraphs)
            {

                Microsoft.Office.Interop.Word.Style style_Word = (Microsoft.Office.Interop.Word.Style)item.get_Style();
                Debug.WriteLine("style_Word:" + style_Word.NameLocal);
                Tables tablearray = item.Range.Tables;
                if(tablearray.Count>0)
                {
                    Table onetable = tablearray[1];
                    Debug.WriteLine("tabletitle:" + onetable.Title);
                    //Debug.WriteLine("tabletitle:" + onetable.Range.Copy());
                    var bits = (byte[])onetable.Range.EnhMetaFileBits;
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(bits);
                    var ret = Image.FromStream(ms);
                    img = ret;
                    form.picturebox.Image = img;
                    //foreach (Row a in onetable.Rows)
                    //{
                    //    Debug.WriteLine("rowcell:" + a.Cells[0].Range.Text);
                    //}
                    //break;
                }               
                Debug.WriteLine("tableCount:" + tablearray.Count);
                var lll = item.Range.ShapeRange;
                Debug.WriteLine("ShapeRange:" + lll.Count);
                Debug.WriteLine("ppp:"+ item.Range.Text);

                string str=string.Empty;
                if(!string.IsNullOrEmpty(item.Range.Text))
                {
                    valuelist.Add(item.Range.Text);
                }
                if (style_Word.NameLocal == "目录 1")
                {
                    mu1.Add(new Node() { value = item.Range.Text });
                }

                //Form1 form = new Form1(mu1, img);
                //form.Show();

            }

        }

声明:该文章系转载,转载该文章的目的在于更广泛的传递信息,并不代表本网站赞同其观点,文章内容仅供参考。

本站是一个个人学习和交流平台,网站上部分文章为网站管理员和网友从相关媒体转载而来,并不用于任何商业目的,内容为作者个人观点, 并不代表本网站赞同其观点和对其真实性负责。

我们已经尽可能的对作者和来源进行了通告,但是可能由于能力有限或疏忽,导致作者和来源有误,亦可能您并不期望您的作品在我们的网站上发布。我们为这些问题向您致歉,如果您在我站上发现此类问题,请及时联系我们,我们将根据您的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。