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