码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2019-12-23 14:52:37      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:als   div   sof   word   button   column   lin   保存   col   

   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();

            }

          
        }

 

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

标签:als   div   sof   word   button   column   lin   保存   col   

原文地址:https://www.cnblogs.com/gisbeginner/p/12083707.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!