在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
参考资料: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using Microsoft.Office.Interop.Word; using System.Windows.Forms; using System.Drawing; namespace ConsoleApplication1 { class STAANDMTA { static void Main() { Thread t = new Thread(new ThreadStart(CopyImages)); t.ApartmentState = ApartmentState.STA; t.Start(); } private static void CopyImages() { Microsoft.Office.Interop.Word.Application app = null; Microsoft.Office.Interop.Word.Document doc = null; object missing = System.Reflection.Missing.Value; app = new Microsoft.Office.Interop.Word.Application(); try { object fileName = @"E:\A.doc"; doc = app.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); int count = doc.InlineShapes.Count; for (int i = 1; i <= count; i++) { doc.InlineShapes[i].Range.Copy();//复制到粘贴板 if (System.Windows.Forms.Clipboard.GetDataObject() != null) { IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent(DataFormats.Bitmap)) { Image image = (Image)data.GetData(DataFormats.Bitmap, true); image.Save("E:\\" + i.ToString() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); } else { //lst_Items.Items.Add(doc.Name + ";无正确图片数据"); } } else { //lst_Items.Items.Add(doc.Name + ";粘贴板为空"); } } } catch (Exception ex) { //lst_Items.Items.Add(doc.Name + "发生错误;" + ex.Message); } finally { if (doc != null) doc.Close(ref missing, ref missing, ref missing); if (app != null) app.Quit(ref missing, ref missing, ref missing); } } } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论