目前有个C#项目,其中有个功能要实现html转为word格式,我是用程序直接将html文件扩展名直接改为.doc就可以完成转换了,可是有一个问题,如果html页面中包含图片,转为word格式无法将图片复制到文档中,还是需要通过图片路径显示图片,请问,能不能用程序将图片复制到文档中啊

解决方案 »

  1.   


    //插入图片
                      string FileName = Picture;//图片所在路径
                      object LinkToFile = false;
                      object SaveWithDocument = true;
                      object Anchor = WordDoc.Application.Selection.Range;
                      WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
              WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;//图片宽度
              WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;//图片高度
                        //将图片设置为四周环绕型
                        Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
                        s.WrapFormat.Type = Word.WdWrapType.wdWrapSquare; 
      

  2.   


    Application.Selection.InsertFile(htmlPath, ref missing, ref falseObj, ref missing, ref missing);
      

  3.   

    Word.ApplicationClass wordApp = new Word.ApplicationClass();
    object visible = false;
    Word.Document doc = Application.Documents.Add(ref missing, ref missing, ref missing, ref visible);wordApp.Selection.InsertFile(htmlPath, ref missing, ref falseObj, ref missing, ref missing);
      

  4.   

    我做过word转html的  反过来应该不会出问题吧
      

  5.   


    sl2161,wowoj2ee,wowoj2ee
    这样直接插入图片,位置怎么控制,转换成word之后要和原先的html页面格式一模一样