word内有文字穿插着图片地址,如<img height="16" width="15" alt="" src="image/authorship.gif" />怎么操作可以把所有图片地址转换成对应的图片??等待高手...是否需要用到Range.InlineShapes.AddPicture,最好有源码,分不够还可以加

解决方案 »

  1.   

    你可以使用正则表达式提取出<img height="16" width="15" alt="" src="image/authorship.gif" />,保存为字符串,如str1,同样的方法,从str1中提取出src="...",注意相对路径到绝对路径的转换,如果这些图片都在word文档的目录或子目录下当然很好办,否则你就要另想办法了。然后再从word中选中str1,直接调用Range.InlineShapes.AddPicture应该就可以了,另外,同样的思路还可以应用height width 和alt的。
    源码就免了吧,我在网吧,不方便!
      

  2.   

    打开word获取内容。通过正则获取图片
    System.Text.RegularExpressions.Regex  reg=new  System.Text.RegularExpressions.Regex(@"<img[^>].*?src=""(? <src>[^""].*)""[^>].*?>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);  
    System.Text.RegularExpressions.MatchCollection mc = reg.Matches(str); 
                foreach(Match m in mc)
                { 
                     string s=m.Groups["src"].ToString();
                } 

    Word.Document wd = objWinWordControl.document;
    Word.Application wa = wd.Application;
    string fileName="D:\\a.jpg";
    object LinkToFile=false;
    object SaveWithDocument=true;
    object Range=Missing.Value;
    object Left=1;
    object Top=1;
    object Width=100;
    object Height=100;
    object Anchor=wd.Application.Selection.Range;                
    wd.Application.ActiveDocument.Shapes.AddPicture(fileName,ref LinkToFile,ref SaveWithDocument,ref Left,ref Top,ref Width,ref Height,ref Anchor);
                    
      

  3.   

    上面两位能做个列子,打包给我吗,本人太菜了 光有思路还是不会写代码[email protected]