zoukankan      html  css  js  c++  java
  • 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();
    
                }
    
              
            }
  • 相关阅读:
    线程高级应用-心得2-同步锁讲解及面试题案例分析
    线程高级应用-心得1-传统线程和定时器讲解及案例分析
    Map拷贝 关于对象深拷贝 浅拷贝的问题
    HashMap对象的深层克隆
    java Collections.sort()实现List排序自定义方法
    java中观察者模式Observable和Observer
    mysql字符串函数(转载)
    CSS的三种样式表和优先级
    Android之微信支付
    Android之扫描二维码和根据输入信息生成名片二维码
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/12083707.html
Copyright © 2011-2022 走看看