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

2021-01-22 05:15

阅读:592

标签: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 )
            {
                Microsoft.Office.Interop.Word.Style stl = m_app.ActiveDocument.Styles[j];
               
            }
            Paragraphs ppplist = doc.Paragraphs;
            List mu1 = new List();
            Liststring> mu2 = new Liststring>();
            Liststring> valuelist = new Liststring>();
            // 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


评论


亲,登录后才可以留言!